Fix lexer for signed integers.

This commit is contained in:
KtorZ 2022-12-14 01:34:18 +01:00 committed by Lucas
parent 18bf89418a
commit 95986fed83
1 changed files with 11 additions and 1 deletions

View File

@ -5,7 +5,17 @@ use crate::ast::Span;
use super::{error::ParseError, token::Token}; use super::{error::ParseError, token::Token};
pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> { pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
let int = choice((text::int(10), text::int(16))).map(|value| Token::Int { value }); let int = choice((
text::int(10),
text::int(16),
just("-")
.ignore_then(text::int(10))
.map(|value: String| format!("-{}", &value)),
just("-")
.ignore_then(text::int(16))
.map(|value: String| format!("-{}", &value)),
))
.map(|value| Token::Int { value });
let op = choice(( let op = choice((
just("==").to(Token::EqualEqual), just("==").to(Token::EqualEqual),