Skip to content

Commit

Permalink
fix: Fix precedence bug and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reiniscirpons committed Dec 26, 2024
1 parent 141b063 commit acd05b2
Show file tree
Hide file tree
Showing 4 changed files with 10,978 additions and 10,398 deletions.
17 changes: 12 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const PREC = {
// in the following, we mention the names of the corresponding
// GAP kernel function
// GAP source file location: src/expr.c PrintPrecedence
// GAP source file location: src/read.c functions given below
LAMBDA: 0, // ReadFuncExprAbbrevSingle, ReadFuncExprAbbrevMulti => ->
OR: 1, // ReadExpr => or
AND: 2, // ReadAnd => and
COMPARE: 3, // ReadRel => = <> < > <= >= in
NOT: 3, // ReadRel => not
COMPARE: 4, // ReadRel => = <> < > <= >= in
PLUS: 9, // ReadAri => + - (binary)
MULTI: 10, // ReadTerm => * / mod
UNARY: 11, // ReadFactor => not + - (unary)
UNARY: 11, // ReadFactor => + - (unary)
POWER: 12, // ReadFactor => ^
CALL: 13,
};
Expand Down Expand Up @@ -333,7 +334,10 @@ module.exports = grammar({
),

unary_expression: ($) =>
prec.left(PREC.UNARY, seq(choice("not", "+", "-"), $._expression)),
choice(
prec.left(PREC.UNARY, seq(choice("+", "-"), $._expression)),
prec.left(PREC.NOT, seq("not", $._expression)),
),

// GAP source file location: src/scanner.c GetNumber
integer: (_) =>
Expand Down Expand Up @@ -464,6 +468,9 @@ module.exports = grammar({
),

argument_list: ($) =>
// TODO: (reiniscirpons) add fields to separate arguments from call
// options. Possibly also remove function_call_option node to decrease
// height.
seq(
"(",
commaSep($._expression),
Expand Down
68 changes: 43 additions & 25 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit acd05b2

Please sign in to comment.