fix peek_nth

This commit is contained in:
nora 2022-06-21 13:52:02 +02:00
parent d12fa25df9
commit abef21fa0a
3 changed files with 217 additions and 6 deletions

View file

@ -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);
}
}

View file

@ -0,0 +1,24 @@
---
source: parser/src/pre/lexer.rs
expression: tokens
---
[
(
Punctuator(
Dot,
),
0..1,
),
(
Punctuator(
LeftLeftChevronEq,
),
2..5,
),
(
Punctuator(
Dot,
),
6..7,
),
]

View file

@ -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,
),
]