zesterer / chumsky

Write expressive, high-performance parsers with ease.
https://crates.io/crates/chumsky
MIT License
3.63k stars 155 forks source link

Failed to run JSON example code `cargo run --example json -- examples/sample.json`. #665

Closed coalooball closed 1 month ago

coalooball commented 2 months ago

I cloned the main branch of chumsky, and after running the command, the following error appeared:

   Compiling winnow v0.6.0
warning: unexpected `cfg` condition value: `stacker`
   --> src\recursive.rs:171:7
    |
171 | #[cfg(feature = "stacker")]
    |       ^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `feature` are: `_test_stable`, `default`, `docsrs`, `either`, `extension`, `label`, `lexical`, `lexical-numbers`, `memoization`, `nightly`, `pratt`, `regex`, `serde`, `spill-stack`, `spin`, `std`, `sync`, and `unstable`
    = help: consider adding `stacker` as a feature in `Cargo.toml`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
    = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition value: `stacker`
   --> src\recursive.rs:176:11
    |
176 | #[cfg(not(feature = "stacker"))]
    |           ^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `feature` are: `_test_stable`, `default`, `docsrs`, `either`, `extension`, `label`, `lexical`, `lexical-numbers`, `memoization`, `nightly`, `pratt`, `regex`, `serde`, `spill-stack`, `spin`, `std`, `sync`, and `unstable`
    = help: consider adding `stacker` as a feature in `Cargo.toml`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration

   Compiling pest_generator v2.7.2
   Compiling pest_derive v2.7.2
   Compiling ciborium v0.2.1
warning: `chumsky` (lib) generated 2 warnings
   Compiling tinytemplate v1.2.1
   Compiling criterion v0.4.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 19s
     Running `target\debug\examples\json.exe examples/sample.json`
Some(
    Object(
        {
            "activity": Str(
                "value",
            ),
            "noise": Bool(
                false,
            ),
            "invalid": Str(
                "\\uDFFF",
            ),
            "leaving": Object(
                {
                    "fed": Num(
                        -283765067.9149623,
                    ),
                    "cowboy": Num(
                        -355139449.0,
                    ),
                    "although": Num(
                        -794127593.3922591,
                    ),
                    "front": Str(
                        "college",
                    ),
                    "tail": Array(
                        [
                            Num(
                                -2063823378.8597813,
                            ),
                            Bool(
                                true,
                            ),
                            Bool(
                                false,
                            ),
                            Null,
                            Num(
                                -153646.6402,
                            ),
                            Str(
                                "board",
                            ),
                        ],
                    ),
                },
            ),
            "foo": Array(
                [],
            ),
            "office": Num(
                -342325541.1937506,
            ),
            "though": Bool(
                true,
            ),
            "acres": Str(
                "home",
            ),
        },
    ),
)
Error: found ! expected 'n', 't', 'f', '-', '0', '"', '[', or '{'
   ╭─[<unknown>:6:7]
   │
 6 │       !false,
   │       ┬
   │       ╰── found ! expected 'n', 't', 'f', '-', '0', '"', '[', or '{'
───╯
Error: found ] expected ','
    ╭─[<unknown>:10:6]
    │
 10 │     ]],
    │      ┬
    │      ╰── found ] expected ','
────╯
Error: found ! expected '.', 'e', 'E', or ','
    ╭─[<unknown>:12:25]
    │
 12 │     "cowboy": -355139449!,
    │                         ┬
    │                         ╰── found ! expected '.', 'e', 'E', or ','
────╯
Error: found - expected '0'
    ╭─[<unknown>:13:18]
    │
 13 │     "although": --794127593.3922591,
    │                  ┬
    │                  ╰── found - expected '0'
────╯
Error: found , expected '"'
    ╭─[<unknown>:14:24]
    │
 14 │     "front": "college",,
    │                        ┬
    │                        ╰── found , expected '"'
────╯
Error: found t expected 'r'
    ╭─[<unknown>:17:14]
    │
 17 │   "though": ttrue asasjk,
    │              ┬
    │              ╰── found t expected 'r'
────╯
Error: found a expected ','
    ╭─[<unknown>:17:19]
    │
 17 │   "though": ttrue asasjk,
    │                   ┬
    │                   ╰── found a expected ','
────╯
Error: invalid unicode character
    ╭─[<unknown>:18:17]
    │
 18 │   "invalid": "\uDFFF",
    │                 ──┬─
    │                   ╰─── invalid unicode character
────╯
Error: found ! expected 'n', 't', 'f', '-', '0', '"', '[', '{', or ']'
    ╭─[<unknown>:23:11]
    │
 23 │   "foo": [!],
    │           ┬
    │           ╰── found ! expected 'n', 't', 'f', '-', '0', '"', '[', '{', or ']'
────╯
Error: found } expected '"'
    ╭─[<unknown>:24:1]
    │
 24 │ }
    │ ┬
    │ ╰── found } expected '"'
────╯

C:\tmp\chumsky>cargo run --example json -- examples/sample.json
warning: unexpected `cfg` condition value: `stacker`
   --> src\recursive.rs:171:7
    |
171 | #[cfg(feature = "stacker")]
    |       ^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `feature` are: `_test_stable`, `default`, `docsrs`, `either`, `extension`, `label`, `lexical`, `lexical-numbers`, `memoization`, `nightly`, `pratt`, `regex`, `serde`, `spill-stack`, `spin`, `std`, `sync`, and `unstable`
    = help: consider adding `stacker` as a feature in `Cargo.toml`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
    = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition value: `stacker`
   --> src\recursive.rs:176:11
    |
176 | #[cfg(not(feature = "stacker"))]
    |           ^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `feature` are: `_test_stable`, `default`, `docsrs`, `either`, `extension`, `label`, `lexical`, `lexical-numbers`, `memoization`, `nightly`, `pratt`, `regex`, `serde`, `spill-stack`, `spin`, `std`, `sync`, and `unstable`
    = help: consider adding `stacker` as a feature in `Cargo.toml`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration

warning: `chumsky` (lib) generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.29s
     Running `target\debug\examples\json.exe examples/sample.json`
Some(
    Object(
        {
            "acres": Str(
                "home",
            ),
            "foo": Array(
                [],
            ),
            "though": Bool(
                true,
            ),
            "activity": Str(
                "value",
            ),
            "noise": Bool(
                false,
            ),
            "office": Num(
                -342325541.1937506,
            ),
            "leaving": Object(
                {
                    "cowboy": Num(
                        -355139449.0,
                    ),
                    "fed": Num(
                        -283765067.9149623,
                    ),
                    "tail": Array(
                        [
                            Num(
                                -2063823378.8597813,
                            ),
                            Bool(
                                true,
                            ),
                            Bool(
                                false,
                            ),
                            Null,
                            Num(
                                -153646.6402,
                            ),
                            Str(
                                "board",
                            ),
                        ],
                    ),
                    "front": Str(
                        "college",
                    ),
                    "although": Num(
                        -794127593.3922591,
                    ),
                },
            ),
            "invalid": Str(
                "\\uDFFF",
            ),
        },
    ),
)
Error: found ! expected 'n', 't', 'f', '-', '0', '"', '[', or '{'
   ╭─[<unknown>:6:7]
   │
 6 │       !false,
   │       ┬
   │       ╰── found ! expected 'n', 't', 'f', '-', '0', '"', '[', or '{'
───╯
Error: found ] expected ','
    ╭─[<unknown>:10:6]
    │
 10 │     ]],
    │      ┬
    │      ╰── found ] expected ','
────╯
Error: found ! expected '.', 'e', 'E', or ','
    ╭─[<unknown>:12:25]
    │
 12 │     "cowboy": -355139449!,
    │                         ┬
    │                         ╰── found ! expected '.', 'e', 'E', or ','
────╯
Error: found - expected '0'
    ╭─[<unknown>:13:18]
    │
 13 │     "although": --794127593.3922591,
    │                  ┬
    │                  ╰── found - expected '0'
────╯
Error: found , expected '"'
    ╭─[<unknown>:14:24]
    │
 14 │     "front": "college",,
    │                        ┬
    │                        ╰── found , expected '"'
────╯
Error: found t expected 'r'
    ╭─[<unknown>:17:14]
    │
 17 │   "though": ttrue asasjk,
    │              ┬
    │              ╰── found t expected 'r'
────╯
Error: found a expected ','
    ╭─[<unknown>:17:19]
    │
 17 │   "though": ttrue asasjk,
    │                   ┬
    │                   ╰── found a expected ','
────╯
Error: invalid unicode character
    ╭─[<unknown>:18:17]
    │
 18 │   "invalid": "\uDFFF",
    │                 ──┬─
    │                   ╰─── invalid unicode character
────╯
Error: found ! expected 'n', 't', 'f', '-', '0', '"', '[', '{', or ']'
    ╭─[<unknown>:23:11]
    │
 23 │   "foo": [!],
    │           ┬
    │           ╰── found ! expected 'n', 't', 'f', '-', '0', '"', '[', '{', or ']'
────╯
Error: found } expected '"'
    ╭─[<unknown>:24:1]
    │
 24 │ }
    │ ┬
    │ ╰── found } expected '"'
────╯

My Rust env:

C:\tmp\chumsky>rustup toolchain list
stable-x86_64-pc-windows-msvc (default)
nightly-x86_64-pc-windows-msvc

C:\tmp\chumsky>rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.80.1 (3f5fd8dd4 2024-08-06)`

C:\tmp\chumsky>cargo --version
cargo 1.80.1 (376290515 2024-07-16)
zesterer commented 2 months ago

I believe the warnings should be fixed now.

The errors in the example are deliberate: they're showcasing chumsky's error recovery features. One can trivially remove the syntax errors if desired.