Skip to main content

surql_parser/upstream/syn/lexer/compound/
mod.rs

1use crate::upstream::syn::error::SyntaxError;
2use crate::upstream::syn::lexer::Lexer;
3use crate::upstream::syn::token::{Span, Token};
4mod js;
5mod number;
6mod regex;
7pub use js::javascript;
8pub use number::{
9	NumberKind, Numeric, NumericKind, ParsedInt, duration, float, integer, number, numeric,
10	numeric_kind, prepare_number_str,
11};
12pub use regex::regex;
13#[derive(Debug)]
14pub struct CompoundToken<T> {
15	pub value: T,
16	pub span: Span,
17}
18impl Lexer<'_> {
19	/// Lex a more complex token from the start token.
20	/// The start token should already be consumed.
21	pub fn lex_compound<F, R>(
22		&mut self,
23		start: Token,
24		f: F,
25	) -> Result<CompoundToken<R>, SyntaxError>
26	where
27		F: Fn(&mut Self, Token) -> Result<R, SyntaxError>,
28	{
29		assert_eq!(
30			self.last_offset,
31			start.span.offset + start.span.len,
32			"The start token given to compound was not the last token consumed."
33		);
34		self.last_offset = start.span.offset;
35		let res = f(self, start)?;
36		Ok(CompoundToken {
37			value: res,
38			span: self.advance_span(),
39		})
40	}
41}