surrealdb_core/syn/lexer/compound/
mod.rs

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