diff --git a/ilex/src/file/mod.rs b/ilex/src/file/mod.rs index a91e78c..cbed544 100644 --- a/ilex/src/file/mod.rs +++ b/ilex/src/file/mod.rs @@ -85,11 +85,11 @@ impl<'ctx> File<'ctx> { } /// Tokenizes the this file according to `spec` and generates a token stream. - pub fn lex<'spec>( + pub fn lex( self, - spec: &'spec Spec, + spec: &'ctx Spec, report: &Report, - ) -> Result, Fatal> { + ) -> Result, Fatal> { rt::lex(self, report, spec) } } diff --git a/ilex/src/fp.rs b/ilex/src/fp.rs index c8dfaa7..e29125b 100644 --- a/ilex/src/fp.rs +++ b/ilex/src/fp.rs @@ -613,7 +613,7 @@ impl Digital<'_> { && (exp.is_none() || exp.is_some_and(|exp| { exp.radix() == 10 - && (exp.has_prefix(ctx, "e") || exp.has_prefix(ctx, "E")) + && (exp.has_prefix("e") || exp.has_prefix("E")) && has_ordinary_sign(ctx, &exp) })) && (rule.separator.is_empty() diff --git a/ilex/src/report/builtin.rs b/ilex/src/report/builtin.rs index e96f221..dda034f 100644 --- a/ilex/src/report/builtin.rs +++ b/ilex/src/report/builtin.rs @@ -9,7 +9,6 @@ use byteyarn::yarn; use byteyarn::YarnBox; use crate::f; -use crate::file::Context; use crate::file::Spanned; use crate::plural; use crate::report::Diagnostic; @@ -43,10 +42,10 @@ impl Builtins<'_> { .report .error(f!( "unexpected {} in {}", - found.for_user_diagnostic(self.spec, &self.report.ctx), + found.for_user_diagnostic(self.spec), unexpected_in .into() - .for_user_diagnostic(self.spec, &self.report.ctx), + .for_user_diagnostic(self.spec), )) .at(at) .reported_at(Location::caller()); @@ -85,7 +84,7 @@ impl Builtins<'_> { plural(found.chars().count()), unexpected_in .into() - .for_user_diagnostic(self.spec, &self.report.ctx), + .for_user_diagnostic(self.spec), )) .at(at) .remark( @@ -109,14 +108,14 @@ impl Builtins<'_> { at: impl Spanned, ) -> Diagnostic { let expected = expected.into_iter().map(Into::into).collect::>(); - let alts = disjunction_to_string(self.spec, &self.report.ctx, &expected); + let alts = disjunction_to_string(self.spec, &expected); let found = found.into(); let diagnostic = self .report .error(f!( "expected {alts}, but found {}", - found.for_user_diagnostic(self.spec, &self.report.ctx) + found.for_user_diagnostic(self.spec) )) .saying(at, f!("expected {alts}")) .reported_at(Location::caller()); @@ -140,7 +139,7 @@ impl Builtins<'_> { .report .error(f!( "unexpected closing {}", - found.for_user_diagnostic(self.spec, &self.report.ctx) + found.for_user_diagnostic(self.spec) )) .saying(at, f!("expected to be opened by `{expected}`")) .reported_at(Location::caller()); @@ -165,7 +164,7 @@ impl Builtins<'_> { .report .error(f!( "expected closing `{expected}`, but found {}", - found.for_user_diagnostic(self.spec, &self.report.ctx) + found.for_user_diagnostic(self.spec) )) .saying(at, f!("expected `{expected}` here")) .remark(open, "previously opened here") @@ -189,7 +188,7 @@ impl Builtins<'_> { "unexpected non-ASCII characters in {}", expected .into() - .for_user_diagnostic(self.spec, &self.report.ctx) + .for_user_diagnostic(self.spec) )) .at(at) .reported_at(Location::caller()) @@ -263,7 +262,7 @@ impl Builtins<'_> { .report .error(f!( "{} out of span", - what.into().for_user_diagnostic(self.spec, &self.report.ctx) + what.into().for_user_diagnostic(self.spec) )) .at(at) .note(f!( @@ -313,12 +312,11 @@ fn non_printable_note(found: Expected, diagnostic: Diagnostic) -> Diagnostic { fn disjunction_to_string<'a>( spec: &'a Spec, - ctx: &'a Context, lexemes: &'a [Expected], ) -> YarnBox<'a, str> { let mut names = lexemes .iter() - .map(|tok| tok.for_user_diagnostic(spec, ctx)) + .map(|tok| tok.for_user_diagnostic(spec)) .collect::>(); names.sort(); names.dedup(); @@ -424,13 +422,12 @@ impl Expected<'_> { pub(crate) fn for_user_diagnostic<'a>( &'a self, spec: &'a Spec, - ctx: &Context, ) -> YarnBox<'a, str> { match self { Self::Literal(lit) => yarn!("`{lit}`"), Self::Name(name) => name.as_ref().to_box(), Self::Lexeme(lex) => lex.to_yarn(spec), - Self::Token(tok) => tok.to_yarn(ctx), + Self::Token(tok) => tok.to_yarn(), } } } diff --git a/ilex/src/rt/emit2.rs b/ilex/src/rt/emit2.rs index 2eabf99..02b2b6a 100644 --- a/ilex/src/rt/emit2.rs +++ b/ilex/src/rt/emit2.rs @@ -498,7 +498,7 @@ pub fn emit(lexer: &mut Lexer) { prefix, suffix, }; - let token = Cursor::fake_token(lexer.spec(), &tok); + let token = Cursor::fake_token(lexer.file(), lexer.spec(), &tok); // This happens later so we have access to the full spans of // the digit blocks. @@ -747,6 +747,7 @@ pub fn emit(lexer: &mut Lexer) { if match_.extra > 0 { let expected = if generated_token { Expected::Token(token::Cursor::fake_token( + lexer.file(), lexer.spec(), lexer.last_token(), )) @@ -778,6 +779,7 @@ pub fn emit(lexer: &mut Lexer) { let expected = if generated_token { Expected::Token(token::Cursor::fake_token( + lexer.file(), lexer.spec(), lexer.last_token(), )) diff --git a/ilex/src/rt/lexer.rs b/ilex/src/rt/lexer.rs index d54c718..379b342 100644 --- a/ilex/src/rt/lexer.rs +++ b/ilex/src/rt/lexer.rs @@ -24,9 +24,9 @@ use super::unicode::is_xid; /// The lexer state struct, that tracks everything going on during a lexing /// operation. -pub struct Lexer<'a, 'spec, 'ctx> { +pub struct Lexer<'a, 'ctx> { report: &'a Report, - spec: &'spec Spec, + spec: &'ctx Spec, file: File<'ctx>, cursor: usize, @@ -46,9 +46,9 @@ pub struct Closer { close: Yarn, } -impl<'a, 'spec, 'ctx> Lexer<'a, 'spec, 'ctx> { +impl<'a, 'ctx> Lexer<'a, 'ctx> { /// Creates a new lexer. - pub fn new(file: File<'ctx>, report: &'a Report, spec: &'spec Spec) -> Self { + pub fn new(file: File<'ctx>, report: &'a Report, spec: &'ctx Spec) -> Self { Lexer { eof: file.span(file.len()..file.len()).intern(file.context()), cache: Cache::new(&spec.dfa().engine), @@ -79,7 +79,7 @@ impl<'a, 'spec, 'ctx> Lexer<'a, 'spec, 'ctx> { } /// Returns the spec we're lexing against. - pub fn spec(&self) -> &'spec Spec { + pub fn spec(&self) -> &'ctx Spec { self.spec } @@ -265,7 +265,7 @@ impl<'a, 'spec, 'ctx> Lexer<'a, 'spec, 'ctx> { } } - pub fn finish(mut self) -> token::Stream<'spec> { + pub fn finish(mut self) -> token::Stream<'ctx> { self.add_token(rt::Token { kind: rt::Kind::Eof, span: self.eof, @@ -281,6 +281,6 @@ impl<'a, 'spec, 'ctx> Lexer<'a, 'spec, 'ctx> { .unclosed(open, &close.close, Lexeme::eof(), self.eof()); } - token::Stream { spec: self.spec, toks: self.tokens } + token::Stream { file: self.file, spec: self.spec, toks: self.tokens } } } diff --git a/ilex/src/rt/mod.rs b/ilex/src/rt/mod.rs index fc4b76a..631bd05 100644 --- a/ilex/src/rt/mod.rs +++ b/ilex/src/rt/mod.rs @@ -19,11 +19,11 @@ mod dfa; pub use dfa::compile; pub use dfa::Dfa; -pub fn lex<'spec>( - file: File, +pub fn lex<'ctx>( + file: File<'ctx>, report: &Report, - spec: &'spec Spec, -) -> Result, Fatal> { + spec: &'ctx Spec, +) -> Result, Fatal> { let mut lexer = lexer::Lexer::new(file, report, spec); let mut unexpected_start = None; diff --git a/ilex/src/token/mod.rs b/ilex/src/token/mod.rs index 368f696..eb7310b 100644 --- a/ilex/src/token/mod.rs +++ b/ilex/src/token/mod.rs @@ -50,6 +50,9 @@ pub trait Token<'lex>: /// The token this rule was parsed from. type Rule: rule::Rule; + /// The context that owns this token. + fn context(self) -> &'lex Context; + /// The spec that lexed this token. fn spec(self) -> &'lex Spec; @@ -105,6 +108,17 @@ impl<'lex> Token<'lex> for Any<'lex> { } } + fn context(self) -> &'lex Context { + match self { + Self::Eof(tok) => tok.context(), + Self::Bracket(tok) => tok.context(), + Self::Keyword(tok) => tok.context(), + Self::Ident(tok) => tok.context(), + Self::Digital(tok) => tok.context(), + Self::Quoted(tok) => tok.context(), + } + } + fn spec(self) -> &'lex Spec { match self { Self::Eof(tok) => tok.spec, @@ -223,12 +237,17 @@ impl Spanned for Any<'_> { #[derive(Copy, Clone)] pub struct Eof<'lex> { span: SpanId, + ctx: &'lex Context, spec: &'lex Spec, } impl<'lex> Token<'lex> for Eof<'lex> { type Rule = rule::Eof; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -276,6 +295,7 @@ impl Spanned for Eof<'_> { #[derive(Copy, Clone)] pub struct Keyword<'lex> { lexeme: Lexeme, + ctx: &'lex Context, spec: &'lex Spec, span: SpanId, _ph: PhantomData<&'lex rt::Token>, @@ -284,6 +304,10 @@ pub struct Keyword<'lex> { impl<'lex> Token<'lex> for Keyword<'lex> { type Rule = rule::Keyword; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -334,6 +358,7 @@ pub struct Bracket<'lex> { open: SpanId, close: SpanId, lexeme: Lexeme, + ctx: &'lex Context, spec: &'lex Spec, contents: Cursor<'lex>, } @@ -366,6 +391,10 @@ impl<'lex> Bracket<'lex> { impl<'lex> Token<'lex> for Bracket<'lex> { type Rule = rule::Bracket; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -420,6 +449,7 @@ impl Spanned for Bracket<'_> { #[derive(Copy, Clone)] pub struct Ident<'lex> { tok: &'lex rt::Token, + ctx: &'lex Context, spec: &'lex Spec, } @@ -438,8 +468,8 @@ impl<'lex> Ident<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_prefix(&self, ctx: &Context, expected: &str) -> bool { - self.prefix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_prefix(&self, expected: &str) -> bool { + self.prefix().is_some_and(|s| s.text(self.ctx) == expected) } /// Returns this token's suffix. @@ -448,14 +478,18 @@ impl<'lex> Ident<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_suffix(&self, ctx: &Context, expected: &str) -> bool { - self.suffix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_suffix(&self, expected: &str) -> bool { + self.suffix().is_some_and(|s| s.text(self.ctx) == expected) } } impl<'lex> Token<'lex> for Ident<'lex> { type Rule = rule::Ident; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -529,6 +563,7 @@ impl Spanned for Ident<'_> { pub struct Digital<'lex> { tok: &'lex rt::Token, idx: usize, + ctx: &'lex Context, spec: &'lex Spec, } @@ -570,6 +605,7 @@ impl<'lex> Digital<'lex> { pub fn exponents(self) -> impl Iterator> { (self.idx..self.exponent_slice().len()).map(move |idx| Self { tok: self.tok, + ctx: self.ctx, idx: idx + 1, spec: self.spec, }) @@ -585,8 +621,8 @@ impl<'lex> Digital<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_prefix(&self, ctx: &Context, expected: &str) -> bool { - self.prefix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_prefix(&self, expected: &str) -> bool { + self.prefix().is_some_and(|s| s.text(self.ctx) == expected) } /// Returns this token's suffix. @@ -600,8 +636,8 @@ impl<'lex> Digital<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_suffix(&self, ctx: &Context, expected: &str) -> bool { - self.suffix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_suffix(&self, expected: &str) -> bool { + self.suffix().is_some_and(|s| s.text(self.ctx) == expected) } /// Parses this token as an integer. @@ -614,7 +650,6 @@ impl<'lex> Digital<'lex> { #[track_caller] pub fn to_int( self, - ctx: &Context, range: impl RangeBounds, report: &Report, ) -> N @@ -635,7 +670,7 @@ impl<'lex> Digital<'lex> { .unexpected("exponent", self.lexeme(), extra); } - self.to_ints(ctx, range, report).drain(..).next().unwrap() + self.to_ints(range, report).drain(..).next().unwrap() } /// Parses the blocks of this digital literal as a sequence of integers; @@ -646,7 +681,6 @@ impl<'lex> Digital<'lex> { #[track_caller] pub fn to_ints( self, - ctx: &Context, range: impl RangeBounds, report: &Report, ) -> Vec @@ -660,7 +694,7 @@ impl<'lex> Digital<'lex> { self .digit_blocks() .map(|span| { - let text = span.text(ctx); + let text = span.text(self.ctx); let buf; let text = if !rule.separator.is_empty() && text.contains(&*rule.separator) { @@ -709,11 +743,10 @@ impl<'lex> Digital<'lex> { #[track_caller] pub fn to_float( self, - ctx: &Context, range: impl RangeBounds, report: &Report, ) -> Result { - let fp: Fp = self.parse_fp(ctx, report, false)?; + let fp: Fp = self.parse_fp(self.ctx, report, false)?; if !fp.__is_finite() || !range.contains(&fp) { report.builtins(self.spec()).literal_out_of_range( @@ -736,11 +769,10 @@ impl<'lex> Digital<'lex> { #[track_caller] pub fn to_float_exact( self, - ctx: &Context, range: impl RangeBounds, report: &Report, ) -> Result { - let fp: Fp = self.parse_fp(ctx, report, true)?; + let fp: Fp = self.parse_fp(self.ctx, report, true)?; if !fp.__is_finite() || !range.contains(&fp) { report.builtins(self.spec()).literal_out_of_range( @@ -870,6 +902,10 @@ impl_radix! { impl<'lex> Token<'lex> for Digital<'lex> { type Rule = rule::Digital; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -934,6 +970,7 @@ impl Spanned for Digital<'_> { #[derive(Copy, Clone)] pub struct Quoted<'lex> { tok: &'lex rt::Token, + ctx: &'lex Context, spec: &'lex Spec, } @@ -969,17 +1006,24 @@ impl<'lex> Quoted<'lex> { self.content_slice().iter().copied() } + /// Returns the unique single [`Content`] of this token, if it is unique. + pub fn unique_content(self) -> Option { + match self.content_slice() { + [unique] => Some(*unique), + _ => None + } + } + /// Constructs a UTF-8 string in the "obvious way", using this token and a /// mapping function for escapes. pub fn to_utf8( self, - ctx: &Context, mut decode_esc: impl FnMut(SpanId, Option, &mut String), ) -> String { let total = self .raw_content() .map(|c| match c { - Content::Lit(sp) => sp.text(ctx).len(), + Content::Lit(sp) => sp.text(self.ctx).len(), Content::Esc(..) => 1, }) .sum(); @@ -987,7 +1031,7 @@ impl<'lex> Quoted<'lex> { let mut buf = String::with_capacity(total); for chunk in self.raw_content() { match chunk { - Content::Lit(sp) => buf.push_str(sp.text(ctx)), + Content::Lit(sp) => buf.push_str(sp.text(self.ctx)), Content::Esc(sp, data) => decode_esc(sp, data, &mut buf), } } @@ -1007,8 +1051,8 @@ impl<'lex> Quoted<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_prefix(self, ctx: &Context, expected: &str) -> bool { - self.prefix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_prefix(self, expected: &str) -> bool { + self.prefix().is_some_and(|s| s.text(self.ctx) == expected) } /// Returns this token's suffix. @@ -1017,8 +1061,8 @@ impl<'lex> Quoted<'lex> { } /// Checks whether this identifier has a particular prefix. - pub fn has_suffix(self, ctx: &Context, expected: &str) -> bool { - self.suffix().is_some_and(|s| s.text(ctx) == expected) + pub fn has_suffix(self, expected: &str) -> bool { + self.suffix().is_some_and(|s| s.text(self.ctx) == expected) } } @@ -1059,6 +1103,10 @@ impl Content { impl<'lex> Token<'lex> for Quoted<'lex> { type Rule = rule::Quoted; + fn context(self) -> &'lex Context { + self.ctx + } + fn spec(self) -> &'lex Spec { self.spec } @@ -1114,6 +1162,10 @@ impl Spanned for Quoted<'_> { impl<'lex> Token<'lex> for Never { type Rule = Never; + fn context(self) -> &'lex Context { + self.from_nothing_anything() + } + fn spec(self) -> &'lex Spec { self.from_nothing_anything() } @@ -1143,12 +1195,13 @@ impl From for Any<'_> { /// Converts a lexeme into a string, for printing as a diagnostic. impl<'lex> Any<'lex> { - pub(crate) fn to_yarn(self, ctx: &Context) -> YarnBox<'lex, str> { + pub(crate) fn to_yarn(self) -> YarnBox<'lex, str> { let spec = self.spec(); if let Some(name) = spec.rule_name(self.lexeme()) { return name.to_box(); } + let ctx = self.context(); let (pre, suf, kind) = match self { Any::Eof(_) => return yarn!(""), Any::Keyword(tok) => return yarn!("`{}`", tok.text(ctx)), diff --git a/ilex/src/token/stream.rs b/ilex/src/token/stream.rs index 6a78521..9c5c974 100644 --- a/ilex/src/token/stream.rs +++ b/ilex/src/token/stream.rs @@ -4,6 +4,8 @@ use std::iter; use std::marker::PhantomData; use std::mem; +use crate::file::Context; +use crate::file::File; use crate::file::SpanId; use crate::report::Report; use crate::rt; @@ -13,27 +15,41 @@ use crate::spec::Lexeme; use crate::spec::Spec; use crate::token; -#[cfg(doc)] -use crate::file::File; - /// A tree-like stream of tokens. /// /// This is type returned by by [`File::lex()`] when lexing succeeds. #[derive(Clone)] -pub struct Stream<'spec> { - pub(crate) spec: &'spec Spec, +pub struct Stream<'ctx> { + pub(crate) file: File<'ctx>, + pub(crate) spec: &'ctx Spec, pub(crate) toks: Vec, } -impl<'spec> Stream<'spec> { +impl<'ctx> Stream<'ctx> { /// Returns a cursor over this stream. pub fn cursor(&self) -> Cursor { Cursor { + file: self.file, spec: self.spec, toks: &self.toks, cursor: 0, } } + + /// Returns the source code context this stream is associated with. + pub fn context(&self) -> &'ctx Context { + self.file.context() + } + + /// Returns the file this stream was lexed from. + pub fn file(&self) -> File<'ctx> { + self.file + } + + /// Returns the lexer spec this stream was lexed with. + pub fn spec(&self) -> &'ctx Spec { + self.spec + } } impl<'lex> IntoIterator for &'lex Stream<'_> { @@ -57,6 +73,7 @@ impl fmt::Debug for Stream<'_> { /// also be queried for more specific token kinds. #[derive(Copy, Clone)] pub struct Cursor<'lex> { + file: File<'lex>, spec: &'lex Spec, toks: &'lex [rt::Token], cursor: usize, @@ -67,6 +84,21 @@ impl<'lex> Cursor<'lex> { self.toks.last().unwrap().span } + /// Returns the source code context this stream is associated with. + pub fn context(&self) -> &'lex Context { + self.file.context() + } + + /// Returns the file this stream was lexed from. + pub fn file(&self) -> File<'lex> { + self.file + } + + /// Returns the lexer spec this stream was lexed with. + pub fn spec(&self) -> &'lex Spec { + self.spec + } + /// Returns whether this cursor has yielded all of its tokens. pub fn is_empty(&self) -> bool { self.cursor >= self.toks.len() @@ -187,10 +219,12 @@ impl<'lex> Cursor<'lex> { } pub(crate) fn fake_token( + file: File<'lex>, spec: &'lex Spec, tok: &'lex rt::Token, ) -> token::Any<'lex> { Self { + file, spec, toks: array::from_ref(tok), cursor: 0, @@ -232,13 +266,18 @@ impl<'lex> Iterator for Cursor<'lex> { let next = match &tok.kind { Kind::Eof => { self.cursor += 1; - token::Any::Eof(token::Eof { span: tok.span, spec: self.spec }) + token::Any::Eof(token::Eof { + span: tok.span, + ctx: self.context(), + spec: self.spec, + }) } Kind::Keyword => { self.cursor += 1; token::Any::Keyword(token::Keyword { lexeme: tok.lexeme.cast(), + ctx: self.context(), spec: self.spec, span: tok.span, _ph: PhantomData, @@ -256,6 +295,7 @@ impl<'lex> Iterator for Cursor<'lex> { open: tok.span, close: tok.span, lexeme: tok.lexeme.cast(), + ctx: self.context(), spec: self.spec, contents: *self, })); @@ -275,8 +315,10 @@ impl<'lex> Iterator for Cursor<'lex> { open: tok.span, close: close.span, lexeme: tok.lexeme.cast(), + ctx: self.context(), spec: self.spec, contents: Cursor { + file: self.file, spec: self.spec, toks: &self.toks[open_idx + 1..close_idx], cursor: 0, @@ -290,17 +332,30 @@ impl<'lex> Iterator for Cursor<'lex> { Kind::Ident { .. } => { self.cursor += 1; - token::Any::Ident(token::Ident { tok, spec: self.spec }) + token::Any::Ident(token::Ident { + tok, + ctx: self.context(), + spec: self.spec, + }) } Kind::Quoted { .. } => { self.cursor += 1; - token::Any::Quoted(token::Quoted { tok, spec: self.spec }) + token::Any::Quoted(token::Quoted { + tok, + ctx: self.context(), + spec: self.spec, + }) } Kind::Digital { .. } => { self.cursor += 1; - token::Any::Digital(token::Digital { tok, idx: 0, spec: self.spec }) + token::Any::Digital(token::Digital { + tok, + ctx: self.context(), + idx: 0, + spec: self.spec, + }) } }; diff --git a/ilex/tests/json.rs b/ilex/tests/json.rs index 8c7808e..652d6b0 100644 --- a/ilex/tests/json.rs +++ b/ilex/tests/json.rs @@ -249,7 +249,7 @@ fn parse0( cursor: &mut Cursor, ) -> Json { let quote2str = |str: token::Quoted| -> String { - str.to_utf8(ctx, |key, data, buf| { + str.to_utf8(|key, data, buf| { let char = match key.text(ctx) { "\\\"" => '\"', r"\\" => '\\', @@ -288,7 +288,7 @@ fn parse0( .case(json.true_, |_, _| Json::Bool(true)) .case(json.string, |str: token::Quoted, _| Json::Str(quote2str(str))) .case(json.number, |num: token::Digital, _| { - Json::Num(num.to_float::(ctx, .., report).unwrap().to_hard()) + Json::Num(num.to_float::(.., report).unwrap().to_hard()) }) .case(json.array, |array: token::Bracket, _| { let mut trailing = None; diff --git a/ilex/tests/numbers.rs b/ilex/tests/numbers.rs index e169f92..97ec5d7 100644 --- a/ilex/tests/numbers.rs +++ b/ilex/tests/numbers.rs @@ -93,7 +93,7 @@ fn numbers() { let value = token::switch() .case(Lexeme::eof(), |_, _| Err(false)) .cases([lex.dec, lex.bin, lex.oct, lex.hex, lex.qua], |num, _| { - Ok(num.to_float::(&ctx, .., &report).unwrap()) + Ok(num.to_float::(.., &report).unwrap()) }) .take(cursor, &report); match value {