chumsky icon indicating copy to clipboard operation
chumsky copied to clipboard

no method named `to_slice` found for opaque type `impl Parser<_, <_ as Character>::Collection, Error = _> + Copy + Clone` in the current scope

Open yonkeltron opened this issue 1 month ago • 1 comments

Hello,

When attempting to compile the following code, I get a very confusing error.

use chumsky::prelude::*;

#[derive(Clone, Debug, PartialEq)]
pub enum LiteralValue {
  Zint(isize),
  Float(f64),
  Chars(String),
  Identifier(String),
  MannaPos(String),
  MannaNeg(String),
}

pub fn literal_value_parser() -> impl Parser<char, LiteralValue, Error = Simple<char>> {
  let zint = text::int(10)
    .to_slice()
    .from_str()
    .unwrapped()
    .map(LiteralValue::Zint);

  let float = text::int(10)
    .then(just('.').then(text::digits(10)))
    .to_slice()
    .from_str()
    .unwrapped()
    .map(LiteralValue::Float);

  let string = just('"')
    .ignore_then(none_of('"').repeated())
    .then_ignore(just('"'))
    .to_slice()
    .map(LiteralValue::Chars);

  let manna_pos = just("+M").to_slice().map(LiteralValue::MannaPos);
  let manna_neg = just("-M").to_slice().map(LiteralValue::MannaNeg);

  zint.or(float).or(string).or(manna_neg).or(manna_pos)
}

The error I get is:

error[E0599]: no method named `to_slice` found for opaque type `impl Parser<_, <_ as Character>::Collection, Error = _> + Copy + Clone` in the current scope
  --> src/parser/spell.rs:18:6
   |
17 |     let zint = text::int(10)
   |  ______________-
18 | |     .to_slice()
   | |     -^^^^^^^^ method not found in `impl Parser<_, <_ as Character>::Collection, Error = _> + Copy + Clone`
   | |_____|
   |

error[E0599]: no method named `to_slice` found for struct `Then` in the current scope
  --> src/parser/spell.rs:25:6
   |
23 |     let float = text::int(10)
   |  _______________-
24 | |     .then(just('.').then(text::digits(10)))
25 | |     .to_slice()
   | |     -^^^^^^^^ method not found in `Then<impl Parser<char, ..., Error = ...> + Copy + Clone, ...>`
   | |_____|
   |
   |
   = note: the full type name has been written to '/Users/yonkeltron/.cargo/shared_target/debug/deps/splang-ebcbc78b3a0326cb.long-type-13662306929836172744.txt'
   = note: consider using `--verbose` to print the full type name to the console

error[E0599]: no method named `to_slice` found for struct `Map` in the current scope
  --> src/parser/spell.rs:33:6
   |
30 |     let string = just('"')
   |  ________________-
31 | |     .ignore_then(none_of('"').repeated())
32 | |     .then_ignore(just('"'))
33 | |     .to_slice()
   | |     -^^^^^^^^ method not found in `Map<Then<Map<Then<Just<char, char, _>, ...>, ..., ...>, ...>, ..., ...>`
   | |_____|
   |
   |
   = note: the full type name has been written to '/Users/yonkeltron/.cargo/shared_target/debug/deps/splang-ebcbc78b3a0326cb.long-type-9340547084340958696.txt'
   = note: consider using `--verbose` to print the full type name to the console

error[E0599]: no method named `to_slice` found for struct `Just` in the current scope
  --> src/parser/spell.rs:36:30
   |
36 |   let manna_pos = just("+M").to_slice().map(LiteralValue::MannaPos);
   |                              ^^^^^^^^ method not found in `Just<_, &str, _>`

error[E0599]: no method named `to_slice` found for struct `Just` in the current scope
  --> src/parser/spell.rs:37:30
   |
37 |   let manna_neg = just("-M").to_slice().map(LiteralValue::MannaNeg);
   |                              ^^^^^^^^ method not found in `Just<_, &str, _>`

Honestly, I'm not sure how to interpret the error considering that it's unclear if I am writing incorrect parsing logic, or just annotating type signatures incorrectly.

Here is some of my system info:

❯ rustc --version                                                                           at 06:37:05
rustc 1.78.0 (9b00956e5 2024-04-29)

ats/splang on  main [?] is 📦 v0.1.0 via 🦀 v1.78.0
❯ cargo --version                                                                                 at 06:41:57
cargo 1.78.0 (54d8815d0 2024-03-26)

ats/splang on  main [?] is 📦 v0.1.0 via 🦀 v1.78.0
❯ cat Cargo.toml | grep chumsky                                                                   at 06:42:00
chumsky = "0.9.3"

ats/splang on  main [?] is 📦 v0.1.0 via 🦀 v1.78.0
❯ uname -a                                                                                        at 06:42:13
Darwin Qafih.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:19:22 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8112 arm64

Please let me know if I can provide additional information.

Thanks, +Jonathan

yonkeltron avatar May 09 '24 10:05 yonkeltron