Skip to content

Commit

Permalink
fix: expressions should not have optional line terminator in grammar
Browse files Browse the repository at this point in the history
Only a `ExpressionStatement` should look out for a line/file terminator
  • Loading branch information
shenyih0ng committed Apr 4, 2024
1 parent 7ab344c commit 457ad78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/go-slang/parser/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ function peg$parse(input, options) {
}

function peg$parseCallExpression() {
var s0, s1, s2, s3, s4, s5;
var s0, s1, s2, s3, s4;

var key = peg$currPos * 99 + 29;
var cached = peg$resultsCache[key];
Expand Down Expand Up @@ -1915,7 +1915,6 @@ function peg$parse(input, options) {
if (peg$silentFails === 0) { peg$fail(peg$e1); }
}
if (s4 !== peg$FAILED) {
s5 = peg$parseEOS();
peg$savedPos = s0;
s0 = peg$f15(s1, s3);
} else {
Expand Down Expand Up @@ -2192,7 +2191,7 @@ function peg$parse(input, options) {
s1 = peg$parseGO_TOKEN();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
s3 = peg$parseCallExpression();
s3 = peg$parseRelationalExpression();
if (s3 !== peg$FAILED) {
s4 = peg$parseEOS();
peg$savedPos = s0;
Expand Down Expand Up @@ -2226,7 +2225,7 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$parseRelationalExpression();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s2 = peg$parse__();
if (input.substr(peg$currPos, 2) === peg$c8) {
s3 = peg$c8;
peg$currPos += 2;
Expand All @@ -2235,7 +2234,7 @@ function peg$parse(input, options) {
if (peg$silentFails === 0) { peg$fail(peg$e22); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
s4 = peg$parse__();
s5 = peg$parseRelationalExpression();
if (s5 !== peg$FAILED) {
s6 = peg$parseEOS();
Expand Down
6 changes: 3 additions & 3 deletions src/go-slang/parser/go.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ RelationalOperator
/ ">"

CallExpression
= callee:PrimaryExpression "(" args:ExpressionList? ")" EOS {
= callee:PrimaryExpression "(" args:ExpressionList? ")" {
return makeNode({ type: "CallExpression", callee, args: args ?? [] })
}

Expand Down Expand Up @@ -232,14 +232,14 @@ ReceiveExpression
/* Go Statement */

GoStatement
= GO_TOKEN __ call:CallExpression EOS {
= GO_TOKEN __ call:Expression EOS {
return makeNode({ type: "GoStatement", call })
}

/* Send Declaration */

SendStatement
= channel:Channel _ "<-" _ value:Expression EOS {
= channel:Channel __ "<-" __ value:Expression EOS {
return makeNode({ type: "SendStatement", channel, value })
}

Expand Down

0 comments on commit 457ad78

Please sign in to comment.