Skip to content

Commit

Permalink
parser: add more advanced class parsing
Browse files Browse the repository at this point in the history
Fixes #31, #32
  • Loading branch information
jkbz64 committed Feb 14, 2024
1 parent 487274a commit 515e4de
Show file tree
Hide file tree
Showing 5 changed files with 90,717 additions and 79,248 deletions.
85 changes: 78 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@ module.exports = grammar({
$.query_definition,
$.temp_table_definition
],
[$.variable_definition, $.property_definition, $.temp_table_definition],
[$.property_definition, $.temp_table_definition],
[$.temp_table_definition, $.dataset_definition]
[$.temp_table_definition, $.dataset_definition],
[
$.variable_definition,
$.buffer_definition,
$.query_definition,
$.temp_table_definition,
$.data_source_definition
],
[
$.variable_definition,
$.buffer_definition,
$.query_definition,
$.temp_table_definition,
$.dataset_definition
]
],

rules: {
Expand Down Expand Up @@ -460,23 +475,32 @@ module.exports = grammar({
$._terminator
),

property_tuning: ($) => choice(kw("ABSTRACT"), kw("OVERRIDE")),
property_type: ($) => choice(kw("ABSTRACT"), kw("OVERRIDE")),
property_tuning: ($) =>
seq(
choice(
seq(kw("INITIAL"), $._expression),
seq(kw("DECIMALS"), $._expression),
seq(kw("EXTENT"), $.number_literal),
kw("NO-UNDO")
)
),

getter: ($) => seq(optional($.access_tuning), kw("GET"), $._terminator),
setter: ($) => seq(optional($.access_tuning), kw("SET"), $._terminator),
property_definition: ($) =>
seq(
kw("DEFINE"),
optional($.access_tuning),
repeat($.property_tuning),
repeat($.property_type),
optional($.serialization_tuning),
kw("PROPERTY"),
$.identifier,
choice(
seq(kw("AS"), $.primitive_type),
seq(kw("LIKE"), field("like", choice($.identifier, $.qualified_name)))
),
optional(seq(kw("EXTENT"), $.number_literal)),
optional(kw("NO-UNDO")),
repeat($.property_tuning),
repeat(choice($.getter, $.setter))
),

Expand All @@ -500,6 +524,7 @@ module.exports = grammar({
field("return_type", $.primitive_type),
$.identifier,
seq("(", optional(_list($.function_parameter, ",")), ")"),
optional(seq(":", optional($.body), kw("END"), optional("METHOD"))),
$._terminator
),

Expand Down Expand Up @@ -528,6 +553,35 @@ module.exports = grammar({
$._terminator
),

class_body: ($) =>
repeat1(
choice(
$.property_definition,
$.temp_table_definition,
$.event_definition,
$.method_definition,
$.dataset_definition,
$.constructor_definition,
$.variable_definition,
$.query_definition,
$.buffer_definition,
$.data_source_definition
)
),

constructor_definition: ($) =>
seq(
kw("CONSTRUCTOR"),
optional($.access_tuning),
$.identifier,
seq("(", optional(_list($.function_parameter, ",")), ")"),
":",
optional($.body),
kw("END"),
optional(kw("CONSTRUCTOR")),
$._terminator
),

class_statement: ($) =>
seq(
kw("CLASS"),
Expand All @@ -546,8 +600,7 @@ module.exports = grammar({
)
),
":",
optional($.body),
kw("END"),
choice(seq($.class_body, kw("END")), kw("END")),
optional(kw("CLASS")),
$._terminator
),
Expand Down Expand Up @@ -1059,6 +1112,24 @@ module.exports = grammar({
$.do_block
),

data_source_definition: ($) =>
seq(
kw("DEFINE"),
optional($.access_tuning),
optional($.scope_tuning),
kw("DATA-SOURCE"),
$.identifier,
kw("FOR"),
optional(seq(kw("QUERY"), $.identifier)),
choice(
seq(
_list(choice($.identifier, $.qualified_name), ","),
$._terminator
),
$._terminator
)
),

// Supertypes
_expression: ($) =>
choice(
Expand Down
Loading

0 comments on commit 515e4de

Please sign in to comment.