Skip to content

Commit

Permalink
fix multiple eq bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fhackett committed Jul 10, 2024
1 parent baaff79 commit 5b78986
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
32 changes: 32 additions & 0 deletions samples/infix/examples/multi_eq_bad.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! --expect-fail calculate
//! --enable-tuples --expect-fail calculate
//! --enable-tuples --tuples-require-parens --expect-fail calculate
//! --enable-tuples --tuples-require-parens --use-parser-tuples --expect-fail calculate
(top
{}
(infix-calculation
{
x = infix-assign}
(error
(errormsg 14:Invalid assign)
(errorast
(infix-equals
(group
(infix-ident 1:x))
(group
(infix-int 1:5))
(group
(infix-int 1:6)))))
(infix-assign
(infix-ident 1:x)
(infix-expression
(infix-int 1:1)))
(error
(errormsg 14:Invalid assign)
(errorast
(infix-equals
(group
(infix-ident 1:x))
(group)
(group
(infix-int 1:1)))))))
3 changes: 3 additions & 0 deletions samples/infix/examples/multi_eq_bad.infix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = 5 = 6;
x = 1 =; // this is not an error, surprisingly
x = = 1;
2 changes: 1 addition & 1 deletion samples/infix/examples/simple.infix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x = 5 = 5;
x = 5;
print "x" x;
y = 2 - 1;
print "1 + 10" 1 + 10;
2 changes: 2 additions & 0 deletions samples/infix/parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace infix
R"([[:digit:]]+\b)" >> [](auto& m) { m.add(Int); },

// Line comment.
// Note: care is taken to handle all 3 possible line endings: \n, \r,
// \r\n
R"(//[^\n\r]*(\r\n?|\n))" >> [](auto&) {}, // another no-op

// Print.
Expand Down
2 changes: 1 addition & 1 deletion samples/infix/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace
// an Assign node that has two children: the Ident and the
// an Expression, which will take the children of the Group.
In(Calculation) *
(T(Equals) << ((T(Group) << T(Ident)[Id]) * T(Group)[Rhs])) >>
(T(Equals) << ((T(Group) << T(Ident)[Id]) * T(Group)[Rhs] * End)) >>
[](Match& _) { return Assign << _(Id) << (Expression << *_[Rhs]); },

// This rule selects a Group that matches the Output pattern
Expand Down

0 comments on commit 5b78986

Please sign in to comment.