parser: prevent non-associative and equal precedence operators being used in same expression

This commit is contained in:
Ryan Chandler 2022-09-13 21:01:30 +01:00
parent be4e54c5be
commit b384bb81ec
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -8,7 +8,7 @@ use crate::{
use std::{fmt::Display, vec::IntoIter};
use trunk_lexer::{Span, Token, TokenKind};
use self::precedence::Precedence;
use self::precedence::{Precedence, Associativity};
type ParseResult<T> = Result<T, ParseError>;
@ -1812,6 +1812,7 @@ impl Parser {
break;
}
let span = self.current.span.clone();
let kind = self.current.kind.clone();
if is_postfix(&kind) {
@ -1834,6 +1835,10 @@ impl Parser {
break;
}
if rpred == precedence && matches!(rpred.associativity(), Some(Associativity::Non)) {
return Err(ParseError::UnexpectedToken(kind.to_string(), span));
}
self.next();
match kind {