diff --git a/parser/src/pre/lexer.rs b/parser/src/pre/lexer.rs index 9ef0a1e..68a8ab1 100644 --- a/parser/src/pre/lexer.rs +++ b/parser/src/pre/lexer.rs @@ -199,11 +199,6 @@ where fn s_p(&mut self) -> Option<&(usize, u8)> { self.src.peek() } - - /// source peek nth - fn s_p_n(&mut self, n: usize) -> Option<&(usize, u8)> { - self.src.peek_nth(n) - } } macro_rules! triple_punct { @@ -270,7 +265,7 @@ where let (span, char1) = self.src.next()?; start_span = span; let char2 = self.src.peek().map(|(_, c)| *c); - let char3 = self.src.peek_nth(2).map(|(_, c)| *c); + let char3 = self.src.peek_nth(1).map(|(_, c)| *c); match (char1, char2, char3) { // IDENTIFIER @@ -377,6 +372,12 @@ mod tests { lex_test!(src); } + #[test] + fn left_left_chevron_eq() { + let src = r#". <<= ."#; + lex_test!(src); + } + #[test] fn hello_world() { let src = r#" @@ -386,4 +387,16 @@ int main() { "#; lex_test!(src); } + + #[test] + fn some_operators() { + let src= r#" +int hello(const char* uwu) <% + uwu[5] <<= 23; + *uwu * (p++); + return p; +%>"#; + + lex_test!(src); + } } diff --git a/parser/src/pre/snapshots/parser__pre__lexer__tests__left_left_chevron_eq.snap b/parser/src/pre/snapshots/parser__pre__lexer__tests__left_left_chevron_eq.snap new file mode 100644 index 0000000..5b29a9c --- /dev/null +++ b/parser/src/pre/snapshots/parser__pre__lexer__tests__left_left_chevron_eq.snap @@ -0,0 +1,24 @@ +--- +source: parser/src/pre/lexer.rs +expression: tokens +--- +[ + ( + Punctuator( + Dot, + ), + 0..1, + ), + ( + Punctuator( + LeftLeftChevronEq, + ), + 2..5, + ), + ( + Punctuator( + Dot, + ), + 6..7, + ), +] diff --git a/parser/src/pre/snapshots/parser__pre__lexer__tests__some_operators.snap b/parser/src/pre/snapshots/parser__pre__lexer__tests__some_operators.snap new file mode 100644 index 0000000..70218e3 --- /dev/null +++ b/parser/src/pre/snapshots/parser__pre__lexer__tests__some_operators.snap @@ -0,0 +1,174 @@ +--- +source: parser/src/pre/lexer.rs +expression: tokens +--- +[ + ( + Identifier( + "int", + ), + 1..4, + ), + ( + Identifier( + "hello", + ), + 5..10, + ), + ( + Punctuator( + ParenOpen, + ), + 10..11, + ), + ( + Identifier( + "const", + ), + 11..16, + ), + ( + Identifier( + "char", + ), + 17..21, + ), + ( + Punctuator( + Asterisk, + ), + 21..22, + ), + ( + Identifier( + "uwu", + ), + 23..26, + ), + ( + Punctuator( + ParenClose, + ), + 26..27, + ), + ( + Punctuator( + BraceOpen, + ), + 28..30, + ), + ( + Identifier( + "uwu", + ), + 35..38, + ), + ( + Punctuator( + BracketOpen, + ), + 38..39, + ), + ( + PpNumber( + "5", + ), + 39..40, + ), + ( + Punctuator( + BracketClose, + ), + 40..41, + ), + ( + Punctuator( + LeftLeftChevronEq, + ), + 42..45, + ), + ( + PpNumber( + "23", + ), + 46..48, + ), + ( + Punctuator( + Semicolon, + ), + 48..49, + ), + ( + Punctuator( + Asterisk, + ), + 54..55, + ), + ( + Identifier( + "uwu", + ), + 55..58, + ), + ( + Punctuator( + Asterisk, + ), + 59..60, + ), + ( + Punctuator( + ParenOpen, + ), + 61..62, + ), + ( + Identifier( + "p", + ), + 62..63, + ), + ( + Punctuator( + PlusPlus, + ), + 63..65, + ), + ( + Punctuator( + ParenClose, + ), + 65..66, + ), + ( + Punctuator( + Semicolon, + ), + 66..67, + ), + ( + Identifier( + "return", + ), + 72..78, + ), + ( + Identifier( + "p", + ), + 79..80, + ), + ( + Punctuator( + Semicolon, + ), + 80..81, + ), + ( + Punctuator( + BraceClose, + ), + 82..84, + ), +]