From 95986fed8307571aad84868b80f4c819b33820dc Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 14 Dec 2022 01:34:18 +0100 Subject: [PATCH] Fix lexer for signed integers. --- crates/lang/src/parser/lexer.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/lang/src/parser/lexer.rs b/crates/lang/src/parser/lexer.rs index 83c7f5a2..3c1d758b 100644 --- a/crates/lang/src/parser/lexer.rs +++ b/crates/lang/src/parser/lexer.rs @@ -5,7 +5,17 @@ use crate::ast::Span; use super::{error::ParseError, token::Token}; pub fn lexer() -> impl Parser, 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(( just("==").to(Token::EqualEqual),