surrealdb_core/syn/lexer/compound/
ident.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::syn::{
	error::{bail, SyntaxError},
	lexer::{unicode::is_identifier_continue, Lexer},
	token::{Token, TokenKind},
};
use std::mem;

pub fn flexible_ident(lexer: &mut Lexer, start: Token) -> Result<String, SyntaxError> {
	match start.kind {
		TokenKind::Digits => {
			let mut res = lexer.span_str(start.span).to_owned();
			while let Some(x) = lexer.reader.peek() {
				if is_identifier_continue(x) {
					lexer.reader.next();
					res.push(x as char);
				} else {
					break;
				}
			}
			Ok(res)
		}
		TokenKind::Identifier => Ok(mem::take(&mut lexer.string).unwrap()),
		x => bail!("Unexpected token {x}, expected flexible identifier", @start.span),
	}
}