mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] More elegant prevention of parsing "3=4>x" and "4<x=3"
This commit is contained in:
@@ -15,8 +15,8 @@ Expression Parser::parseUntil(Token::Type stoppingType) {
|
||||
typedef void (Parser::*TokenParser)(Expression & leftHandSide);
|
||||
static constexpr TokenParser tokenParsers[] = {
|
||||
&Parser::parseUnexpected, // Token::EndOfStream
|
||||
&Parser::parseEqual, // Token::Equal
|
||||
&Parser::parseStore, // Token::Store
|
||||
&Parser::parseEqual, // Token::Equal
|
||||
&Parser::parseUnexpected, // Token::RightBracket
|
||||
&Parser::parseUnexpected, // Token::RightParenthesis
|
||||
&Parser::parseUnexpected, // Token::RightBrace
|
||||
@@ -170,10 +170,8 @@ void Parser::parseEqual(Expression & leftHandSide) {
|
||||
}
|
||||
Expression rightHandSide;
|
||||
if (parseBinaryOperator(leftHandSide, rightHandSide, Token::Equal)) {
|
||||
if (rightHandSide.type() == ExpressionNode::Type::Store) {
|
||||
m_status = Status::Error; // Equal cannot have a Store on the right
|
||||
return;
|
||||
}
|
||||
/* We parse until finding a token of lesser precedence than Equal. The next
|
||||
* token is thus either EndOfStream or Store. */
|
||||
leftHandSide = Equal(leftHandSide, rightHandSide);
|
||||
}
|
||||
if (!m_nextToken.is(Token::EndOfStream)) {
|
||||
|
||||
@@ -17,8 +17,13 @@ public:
|
||||
enum Type {
|
||||
// Ordered from lower to higher precedence to make Parser's job easier
|
||||
EndOfStream = 0, // Must be the first
|
||||
Equal,
|
||||
Store,
|
||||
Equal,
|
||||
/* Equal should have a higher precedence than Store, because
|
||||
* Tokenizer::parseEqual looks for a right hand side until it finds a
|
||||
* token of lesser precedence than Equal, and this prevents expressions
|
||||
* such as "3=4>a". Tokenizer::parseStore uses a special algorithm that
|
||||
* prevents (3>4=a). */
|
||||
RightBracket,
|
||||
RightParenthesis,
|
||||
RightBrace,
|
||||
|
||||
Reference in New Issue
Block a user