grammar.g4 new types fixes

This commit is contained in:
ProgramSnail 2023-08-12 14:44:05 +03:00
parent 8e0cea277e
commit c9bef5a02e
4 changed files with 195 additions and 106 deletions

View file

@ -56,7 +56,7 @@ module.exports = grammar({
repeat1(seq(
optional($.annotation_identifier),
optional($._reference),
$.type,
$._scoped_type,
)),
)),
choice(seq('=', choice(prec(2, choice($.block, $.array)), seq($._super_expression, ';'))), ';'),
@ -70,7 +70,7 @@ module.exports = grammar({
field('name', choice($.simple_type_identifier, $.typeclass_identifier)),
optional(seq('[', repeat($.typeclass_identifier), ']')), // parametric typeclasses ??
repeat($.argument_type_identifier), // for datatypes only
optional(seq('=', $.variant_type)), // for datatypes only
optional(seq('=', $._type)), // for datatypes only
';',
),
@ -152,7 +152,7 @@ module.exports = grammar({
name_expression: $ => seq(
choice(
seq($.type, '.', field('name', $.simple_name_identifier)),
seq($._scoped_type, '.', field('name', $.simple_name_identifier)),
seq($._scoped_expression, '.', field('name', $.simple_name_identifier)),
field('name', $._name_identifier),
seq('(', field('name', $.operator), ')'),
@ -161,7 +161,7 @@ module.exports = grammar({
),
constructor: $ => seq(
field('type', $.type),
field('type', $._scoped_type),
repeat1(seq(optional($.annotation_identifier), $._scoped_expression)),
),
@ -212,25 +212,54 @@ module.exports = grammar({
// --- type
// same to Variant[...]
variant_type: $ => seq(
optional('|'),
$.tuple_type,
repeat(seq('|', $.tuple_type)),
$._annotated_type,
repeat1(seq('|', $._annotated_type)),
),
// same to Tuple[...]
tuple_type: $ => seq(
optional('&'),
$._annotated_type,
repeat(seq('&', $._annotated_type)),
repeat1(seq('&', $._annotated_type)),
),
_annotated_type: $ => seq(optional($.annotation_identifier), $.type),
// add annotations to in all types ??
_annotated_type: $ => seq(optional($.annotation_identifier), $._scoped_type),
type: $ => seq(
optional('^'),
// same to Array[...]
array_type: $ => seq('[[', $._type, ']]'),
reference_type: $ => prec(-1, seq('^', $._scoped_type)),
// same to Optional[...] or Result[...]
modified_type: $ => seq($._scoped_type, $._optional_or_result),
simple_type: $ => seq(
field('name', $._type_identifier),
optional($._optional_or_result),
optional(seq('[', repeat1($.type), ']'))
optional(seq('[', repeat1($._scoped_type), ']'))
),
_type: $ => choice(
$.simple_type,
$.reference_type,
$.modified_type,
$.array_type,
$.variant_type,
$.tuple_type,
),
_scoped_type: $ => choice(
$.simple_type,
$.reference_type,
$.modified_type,
$.array_type,
seq('(', choice(
$.variant_type,
$.tuple_type,
), ')'),
),
// --- comments