From d585678b7f37db73eaf2d4e8acb915b99eb320ec Mon Sep 17 00:00:00 2001 From: Kamil Jakubus Date: Thu, 28 Nov 2024 15:40:43 +0100 Subject: [PATCH] parser: add initial preselect_phrase Fixes #91 --- grammar.js | 24 ++++++++++++++++++++++-- test/corpus/basic.txt | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/grammar.js b/grammar.js index e98d853..dd13efc 100644 --- a/grammar.js +++ b/grammar.js @@ -27,6 +27,8 @@ module.exports = grammar({ supertypes: ($) => [$._expression, $._statement], conflicts: ($) => [ [$.input_expression], + [$.record_phrase], + [$.sort_clause], ...combinations([$._statement, $.if_statement]), // DEFINE * conflicts ...combinations([ @@ -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, @@ -462,6 +464,7 @@ module.exports = grammar({ seq( optional($.label), kw("REPEAT"), + optional($.preselect_phrase), optional($.to_phrase), optional($.while_phrase), repeat( @@ -473,7 +476,7 @@ module.exports = grammar({ ) ), repeat($.repeat_tuning), - optional($.body), + $.body, $._block_terminator ), @@ -992,6 +995,7 @@ module.exports = grammar({ seq( optional($.label), kw("DO"), + optional($.preselect_phrase), optional($.to_phrase), optional($.while_phrase), repeat($.do_tuning), @@ -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( diff --git a/test/corpus/basic.txt b/test/corpus/basic.txt index 03773d1..9d14c8b 100644 --- a/test/corpus/basic.txt +++ b/test/corpus/basic.txt @@ -708,6 +708,10 @@ REPEAT WHILE TRUE: x = 5. END. +REPEAT PRESELECT EACH Order, Customer OF Order, EACH OrderLine OF Order: + +END. + -------------------------------------------------------------------------------- (source_code @@ -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 @@ -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 @@ -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