Skip to content

Commit 7fdee06

Browse files
authored
Merge pull request #118 from NoamDev/fix-lexer-int
2 parents 3fbe78b + 5717c95 commit 7fdee06

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/par/lexer.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,36 @@ pub fn lex<'s>(input: &'s str, file: &FileName) -> Vec<Token<'s>> {
204204
while let Ok(c) = peek(any::<&str, Error>).parse_next(input) {
205205
let column = last_newline - input.len(); // starting column
206206
let Some((raw, kind)) = (match c {
207-
'-' => Some(
208-
alt((
207+
'-' => {
208+
let (raw, mut kind) = alt((
209209
("->").map(|raw| (raw, TokenKind::ThinArrow)),
210210
(
211-
take(1 as usize),
211+
take(1usize),
212212
take_while(0.., |c| matches!(c, '0'..='9' | '_')),
213213
)
214214
.take()
215215
.map(|raw| (raw, TokenKind::Integer)),
216216
))
217-
.parse_next(input)?,
218-
),
217+
.parse_next(input)?;
218+
if let TokenKind::Integer = kind {
219+
if !raw.contains(|c| matches!(c, '0'..='9')) {
220+
kind = TokenKind::Unknown;
221+
}
222+
}
223+
Some((raw, kind))
224+
}
219225
'0'..='9' | '+' => {
220226
let raw = (
221-
take(1 as usize),
227+
take(1usize),
222228
take_while(0.., |c| matches!(c, '0'..='9' | '_')),
223229
)
224230
.take()
225231
.parse_next(input)?;
226-
Some((raw, TokenKind::Integer))
232+
if !raw.contains(|c| matches!(c, '0'..='9')) {
233+
Some((raw, TokenKind::Unknown))
234+
} else {
235+
Some((raw, TokenKind::Integer))
236+
}
227237
}
228238
'"' => {
229239
any.parse_next(input)?;

0 commit comments

Comments
 (0)