본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리

    std.toml.parse

    Parses TOML text into a TOMLValue.

    parse(text: string) -> Result<TOMLValue, string>
    수신자
    해당 없음
    최소 인자 수
    1
    최대 인자 수
    1

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 미정

    Import std.toml in language mode 5.21.

    The current compiler selects std/toml.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    수신자

    매개변수 제약

    parse accepts a complete TOML 1.0 document. An empty document or comments with whitespace produce an empty root table. Basic and literal strings, multiline strings, dotted and quoted keys, inline tables, arrays and arrays of tables retain their TOML meanings.

    Integers must fit the signed 64 bit range. TOML decimal, hexadecimal, octal and binary spellings and valid underscore separators are accepted. Floating values use IEEE binary64 rounding. The TOML inf and nan forms are valid TOML values. Finite overflow follows the TOML numeric error boundary and returns Err.

    Offset date times, local date times, local dates and local times remain distinct TOML kinds. Invalid calendar fields and time fields return Err. Strings that resemble dates remain strings.

    A key or table definition may not redefine an existing value under the TOML 1.0 rules. Names are compared after decoding. Malformed escapes, leading zeroes and misplaced underscore separators return Err without exposing a partial document.

    A failure returns a nonempty string identifying the cause, one based line and Unicode scalar column. CRLF is a single line break. The first offending scalar is the location and an incomplete input points immediately after its last scalar. Source comments and layout are not retained in TOMLValue.

    The text argument is evaluated once. Parsing consumes the complete document, performs no I/O and does not invoke JSON conversion. Syntax failures use Err rather than a runtime diagnostic.

    결과

    The declared result type is Result<TOMLValue, string>.

    효과

    실패

    Result and effects

    링크

    Parse a complete TOML 1.0 document and report invalid input with a cause and position.

    Related entries

    링크

    std.toml →

    Parse complete TOML 1.0 documents

    링크
    규칙topaz.stdlib.contract.toml-parse.rule

    Parse complete TOML 1.0 documents

    parse accepts a complete TOML 1.0 document. An empty document or comments with whitespace produce an empty root table. Basic and literal strings, multiline strings, dotted and quoted keys, inline tables, arrays and arrays of tables retain their TOML meanings.

    Integers must fit the signed 64 bit range. TOML decimal, hexadecimal, octal and binary spellings and valid underscore separators are accepted. Floating values use IEEE binary64 rounding. The TOML inf and nan forms are valid TOML values. Finite overflow follows the TOML numeric error boundary and returns Err.

    Offset date times, local date times, local dates and local times remain distinct TOML kinds. Invalid calendar fields and time fields return Err. Strings that resemble dates remain strings.

    A key or table definition may not redefine an existing value under the TOML 1.0 rules. Names are compared after decoding. Malformed escapes, leading zeroes and misplaced underscore separators return Err without exposing a partial document.

    A failure returns a nonempty string identifying the cause, one based line and Unicode scalar column. CRLF is a single line break. The first offending scalar is the location and an incomplete input points immediately after its last scalar. Source comments and layout are not retained in TOMLValue.

    The text argument is evaluated once. Parsing consumes the complete document, performs no I/O and does not invoke JSON conversion. Syntax failures use Err rather than a runtime diagnostic.

    이유

    Configuration files need a named format version and predictable rejection of invalid definitions. Preserving TOML kinds lets callers choose a separate and explicit conversion into JSON.

    Parse a table and write its deterministic form

    링크
    main.tpzParse a table and write its deterministic form플레이그라운드 열기 →
    1. import std.toml
    2. import std.test
    3. import std.io
    4. let value = test.assertOk(toml.parse("title = \"Topaz\"\ncount = 6\nactive = true\n[page]\nwidth = 210\n"))
    5. io.writeLine(test.assertOk(toml.stringify(value)))
    6. let empty = test.assertOk(toml.parse(" # comment\n"))
    7. test.assertEq(test.assertOk(toml.stringify(empty)), "")
    기대 출력종료 코드 0
    active = true
    count = 6
    title = "Topaz"
    
    [page]
    width = 210
    
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. active = true
    2. count = 6
    3. title = "Topaz"
    4. [page]
    5. width = 210

    Accept literal strings, multiline values, radix integers and dates

    링크
    main.tpzAccept literal strings, multiline values, radix integers and dates플레이그라운드 열기 →
    1. import std.toml
    2. import std.io
    3. for text in (["title = 'ink#paper'\n", "text = \"\"\"\nfirst\nsecond\"\"\"\n", "value = 0xff\n", "date = 1979-05-27T07:32:00Z\n", "value = inf\n", "value = nan\n"]) {
    4. match (toml.parse(text)) {
    5. case Ok(_) => io.writeLine("accepted")
    6. case Err(_) => io.writeLine("rejected")
    7. }
    8. }
    기대 출력종료 코드 0
    accepted
    accepted
    accepted
    accepted
    accepted
    accepted
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. accepted
    2. accepted
    3. accepted
    4. accepted
    5. accepted
    6. accepted

    Reject malformed numeric spellings and repeated definitions

    링크
    main.tpzReject malformed numeric spellings and repeated definitions플레이그라운드 열기 →
    1. import std.toml
    2. import std.io
    3. for text in (["n = 1__0\n", "n = 01\n", "[a]\nx = 1\n[a]\ny = 2\n", "x = 1\nx = 2\n"]) {
    4. match (toml.parse(text)) {
    5. case Ok(_) => io.writeLine("accepted")
    6. case Err(_) => io.writeLine("invalid")
    7. }
    8. }
    기대 출력종료 코드 0
    invalid
    invalid
    invalid
    invalid
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. invalid
    2. invalid
    3. invalid
    4. invalid

    Return line and scalar column in a TOML error

    링크
    main.tpzReturn line and scalar column in a TOML error플레이그라운드 열기 →
    1. import std.toml
    2. import std.test
    3. import std.io
    4. let error = test.assertErr(toml.parse("x = ?"))
    5. test.assertContains(error, "line 1")
    6. test.assertContains(error, "column 5")
    7. io.writeLine("located")
    기대 출력종료 코드 0
    located
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. located

    메뉴

    다운로드 →