Skip to content

Commit

Permalink
parser: add initial preselect_phrase
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
jkbz64 committed Nov 28, 2024
1 parent ea8aae3 commit d585678
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
24 changes: 22 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = grammar({
supertypes: ($) => [$._expression, $._statement],
conflicts: ($) => [
[$.input_expression],
[$.record_phrase],
[$.sort_clause],
...combinations([$._statement, $.if_statement]),
// DEFINE * conflicts
...combinations([
Expand All @@ -47,7 +49,7 @@ module.exports = grammar({
rules: {
source_code: ($) => repeat($._statement),

body: ($) => seq(choice(":"), repeat($._statement)),
body: ($) => seq(":", repeat($._statement)),
dot_body: ($) => seq(choice(":", "."), repeat($._statement)),

file_name: ($) => /[A-z-_|0-9|\/]+\.[i]/i,
Expand Down Expand Up @@ -462,6 +464,7 @@ module.exports = grammar({
seq(
optional($.label),
kw("REPEAT"),
optional($.preselect_phrase),
optional($.to_phrase),
optional($.while_phrase),
repeat(
Expand All @@ -473,7 +476,7 @@ module.exports = grammar({
)
),
repeat($.repeat_tuning),
optional($.body),
$.body,
$._block_terminator
),

Expand Down Expand Up @@ -992,6 +995,7 @@ module.exports = grammar({
seq(
optional($.label),
kw("DO"),
optional($.preselect_phrase),
optional($.to_phrase),
optional($.while_phrase),
repeat($.do_tuning),
Expand Down Expand Up @@ -1493,6 +1497,22 @@ module.exports = grammar({
$._terminator
),

record_phrase: ($) =>
seq(
optional(field("type", choice(kw("EACH"), kw("FIRST"), kw("LAST")))),
_list(choice($.identifier, $.qualified_name), ","),
optional($.of)
),
preselect_phrase: ($) =>
seq(
kw("PRESELECT"),
_list($.record_phrase, ","),
optional($._pre_tuning),
optional($.where_clause),
repeat($.query_tuning),
optional(repeat($.sort_clause))
),

// Supertypes
_expression: ($) =>
choice(
Expand Down
36 changes: 34 additions & 2 deletions test/corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,10 @@ REPEAT WHILE TRUE:
x = 5.
END.

REPEAT PRESELECT EACH Order, Customer OF Order, EACH OrderLine OF Order:

END.

--------------------------------------------------------------------------------

(source_code
Expand All @@ -719,7 +723,19 @@ END.
(assignment
(identifier)
(assignment_operator)
(number_literal))))))
(number_literal)))))
(repeat_statement
(preselect_phrase
(record_phrase
(identifier)
(identifier)
(of
(identifier)))
(record_phrase
(identifier)
(of
(identifier))))
(body)))

================================================================================
DO statement
Expand All @@ -742,6 +758,10 @@ DO x = 5 TO 20:
LEAVE z.
END.


DO PRESELECT EACH Order NO-LOCK WHERE Order.OrderNum > 5:
END.

--------------------------------------------------------------------------------

(source_code
Expand Down Expand Up @@ -798,7 +818,19 @@ END.
(body
(abl_statement
(identifier)
(identifier)))))
(identifier))))
(do_block
(preselect_phrase
(record_phrase
(identifier))
(query_tuning)
(where_clause
(comparison_expression
(qualified_name
(identifier)
(identifier))
(number_literal))))
(body)))

================================================================================
PROCEDURE statement
Expand Down

0 comments on commit d585678

Please sign in to comment.