Skip to content

Commit

Permalink
parser: add generic type and expression
Browse files Browse the repository at this point in the history
Fixes #84
  • Loading branch information
jkbz64 committed Sep 27, 2024
1 parent 80abd4d commit 24c34a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 16 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,23 @@ module.exports = grammar({
),

class_type: ($) => seq(kw("CLASS"), choice($.identifier, $.qualified_name)),
generic_parameter: ($) => seq($.identifier, $.type_tuning),
generic_expression: ($) =>
seq(
"<",
_list(choice($.identifier, $.qualified_name, $.generic_parameter), ","),
">"
),
generic_type: ($) =>
seq(choice($.identifier, $.qualified_name), $.generic_expression),
_type: ($) =>
choice($.primitive_type, $.identifier, $.qualified_name, $.class_type),
choice(
$.primitive_type,
$.identifier,
$.qualified_name,
$.class_type,
$.generic_type
),

when_expression: ($) => seq(kw("WHEN"), $._expression),
assignment: ($) =>
Expand Down
14 changes: 13 additions & 1 deletion test/corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,9 @@ VAR INT x = a + b , y = a - b, z = x - y.
/* Indeterminate integer array initialized using expressions */
VAR INT[ ] x = [funct( ), a + b].

/* Generic type */
var List<Ant> ListOfAnts.

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

(source_code
Expand Down Expand Up @@ -2472,7 +2475,16 @@ VAR INT[ ] x = [funct( ), a + b].
(arguments))
(additive_expression
(identifier)
(identifier)))))))
(identifier))))))
(comment)
(var_statement
(type_tuning
(generic_type
(identifier)
(generic_expression
(identifier))))
(variable
(identifier))))

================================================================================
RUN statement
Expand Down

0 comments on commit 24c34a6

Please sign in to comment.