1mod context;
2pub use context::*;
3
4mod token;
5use lang_util::position::LexerPosition;
6pub use token::*;
7
8mod lang_token;
9
10pub mod min;
11
12#[cfg(feature = "full")]
13pub mod full;
14
15pub trait HasLexerError {
17 type Error: lang_util::error::LexicalError;
19}
20
21pub trait LangLexer<'i>: HasLexerError + Sized {
23 type Input: 'i;
25 type Iter: LangLexerIterator + HasLexerError<Error = Self::Error>;
27
28 fn new(source: Self::Input, opts: &ParseOptions) -> Self;
35
36 fn run(self, ctx: ParseContext) -> Self::Iter;
38}
39
40pub trait LangLexerIterator:
42 Iterator<Item = Result<(LexerPosition, Token, LexerPosition), Self::Error>> + HasLexerError
43{
44 fn resolve_err(
45 &self,
46 err: lalrpop_util::ParseError<LexerPosition, Token, Self::Error>,
47 ) -> lang_util::error::ParseError<Self::Error>;
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 const HASH_IDENT_TEST_CASE: &str = "# (ident) = hello";
55
56 fn test_hash_ident_with_lexer<'i>(lexer: impl LangLexer<'i, Input = &'i str>) {
57 let tokens: Vec<_> = lexer.run(ParseContext::default()).collect();
58 eprintln!("{:#?}", tokens);
59 assert!(tokens.len() > 1);
60 }
61
62 #[test]
63 fn test_hash_ident_min() {
64 test_hash_ident_with_lexer(min::str::Lexer::new(
65 HASH_IDENT_TEST_CASE,
66 &ParseOptions {
67 allow_rs_ident: true,
68 ..Default::default()
69 },
70 ));
71 }
72
73 #[cfg(feature = "full")]
74 #[test]
75 fn test_hash_ident_full() {
76 test_hash_ident_with_lexer(full::str::Lexer::new(
77 HASH_IDENT_TEST_CASE,
78 &ParseOptions {
79 allow_rs_ident: true,
80 ..Default::default()
81 },
82 ));
83 }
84}