1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

Fix tokenizing not

This commit is contained in:
Tjaden Hess 2018-11-14 17:57:15 -05:00
parent 711f60fe7f
commit 78ecb9e3ca
3 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,3 @@
def main(field a) -> (field):
field x = if !(!(a < 5) && !(a > 1) || a < 4) then 3 else 4 fi
return x

View file

@ -83,6 +83,17 @@ fn parse_bfactor<T: Field>(
pos: &Position,
) -> Result<(Expression<T>, String, Position), Error<T>> {
match next_token::<T>(input, pos) {
(Token::Not, s1, p1) => match next_token(&s1, &p1) {
(Token::Open, _, _) => match parse_bfactor(&s1, &p1) {
Ok((e3, s3, p3)) => Ok((Expression::Not(box e3), s3, p3)),
Err(err) => Err(err),
},
(t2, _, p2) => Err(Error {
expected: vec![Token::Open],
got: t2,
pos: p2,
}),
},
(Token::Open, s1, p1) => match parse_bexpr(&s1, &p1) {
Ok((e2, s2, p2)) => match next_token::<T>(&s2, &p2) {
(Token::Close, s3, p3) => Ok((e2, s3, p3)),

View file

@ -259,8 +259,16 @@ pub fn next_token<T: Field>(input: &String, pos: &Position) -> (Token<T>, String
line: pos.line,
col: pos.col + offset + 1,
},
),
),
},
Some('!') => (
Token::Not,
input[offset+1..].to_string(),
Position {
line: pos.line,
col: pos.col + offset + 1,
}
),
Some('+') => (
Token::Add,
input[offset + 1..].to_string(),