Skip to content

Commit

Permalink
feat!: Add more fields to grammar, inline and hide block node
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `(block)` node of the grammar is no longer visible.
  • Loading branch information
reiniscirpons committed Aug 29, 2024
1 parent d1eb1a7 commit e2ba306
Show file tree
Hide file tree
Showing 6 changed files with 12,193 additions and 11,588 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package-lock.json
node_modules
build
*.log
temp*/
temp_*/
log.html
examples/corpus_*.tar.gz
*.egg-info
65 changes: 40 additions & 25 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = grammar({

extras: ($) => [$.comment, $.pragma, /\s/, $._line_continuation],

inline: ($) => [$._expression, $._statement],
inline: ($) => [$._expression, $._statement, $._block],

conflicts: ($) => [
// The parameters of an atomic function do not necessarily have to use the
Expand All @@ -79,6 +79,8 @@ module.exports = grammar({
),

// Statements
_block: ($) => repeat1($._statement),

_statement: ($) =>
choice(
seq($._statement_inner, ";"),
Expand Down Expand Up @@ -115,7 +117,7 @@ module.exports = grammar({
"if",
field("condition", $._expression),
"then",
repeat($._statement),
optional(field("body", $._block)),
repeat($.elif_clause),
optional($.else_clause),
"fi",
Expand All @@ -126,24 +128,24 @@ module.exports = grammar({
"elif",
field("condition", $._expression),
"then",
repeat($._statement),
optional(field("body", $._block)),
),

else_clause: ($) => seq("else", repeat($._statement)),
else_clause: ($) => seq("else", optional(field("body", $._block))),

while_statement: ($) =>
seq(
"while",
field("condition", $._expression),
"do",
repeat($._statement),
optional(field("body", $._block)),
"od",
),

repeat_statement: ($) =>
seq(
"repeat",
repeat($._statement),
optional(field("body", $._block)),
"until",
field("condition", $._expression),
),
Expand All @@ -155,7 +157,7 @@ module.exports = grammar({
"in",
field("values", $._expression),
"do",
repeat($._statement),
optional(field("body", $._block)),
"od",
),

Expand All @@ -168,7 +170,7 @@ module.exports = grammar({
commaSep1(choice($.qualified_expression, $._expression)),
),
"do",
repeat($._statement),
optional(field("body", $._block)),
"od",
),

Expand Down Expand Up @@ -231,8 +233,10 @@ module.exports = grammar({
seq(
field("variable", $._expression),
"[",
$._expression,
optional(seq(",", $._expression)),
field(
"selector",
seq($._expression, optional(seq(",", $._expression))),
),
"]",
),
),
Expand All @@ -241,14 +245,24 @@ module.exports = grammar({
sublist_selector: ($) =>
prec.left(
PREC.CALL,
seq(field("variable", $._expression), "{", $._expression, "}"),
seq(
field("variable", $._expression),
"{",
field("selector", $._expression),
"}",
),
),

// GAP source file location: src/read.c ReadSelector
positional_selector: ($) =>
prec.left(
PREC.CALL,
seq(field("variable", $._expression), "![", $._expression, "]"),
seq(
field("variable", $._expression),
"![",
field("selector", $._expression),
"]",
),
),

// GAP source file location: src/read.c ReadSelector
Expand Down Expand Up @@ -372,8 +386,8 @@ module.exports = grammar({
seq(
"function",
field("parameters", $.parameters),
field("locals", optional($.locals)),
field("body", optional($.block)),
optional(field("locals", $.locals)),
optional(field("body", $._block)),
"end",
),

Expand All @@ -382,13 +396,11 @@ module.exports = grammar({
"atomic",
"function",
field("parameters", $.qualified_parameters),
field("locals", optional($.locals)),
field("body", optional($.block)),
optional(field("locals", $.locals)),
optional(field("body", $._block)),
"end",
),

block: ($) => repeat1($._statement),

lambda: ($) =>
prec.right(
PREC.LAMBDA,
Expand Down Expand Up @@ -452,13 +464,11 @@ module.exports = grammar({
),

argument_list: ($) =>
choice(
seq(
"(",
commaSep($._expression),
optional(seq(":", commaSep($.function_call_option))),
")",
),
seq(
"(",
commaSep($._expression),
optional(seq(":", commaSep($.function_call_option))),
")",
),

// GAP source file location: src/read.c ReadFuncCallOption
Expand Down Expand Up @@ -524,6 +534,11 @@ module.exports = grammar({

parenthesized_expression: ($) => seq("(", $._expression, ")"),

// TODO: (reiniscirpons): Match the `@` character separately for
// identifiers to allow for namespace determination.
// See Chapter 4.10 of the GAP reference manual
// https://docs.gap-system.org/doc/ref/chap4.html#X7DF8774F7D542298
// for more details.
identifier: (_) =>
lineContinuation(
LITERAL_REGEXP.IDENTIFIER,
Expand Down
Loading

0 comments on commit e2ba306

Please sign in to comment.