From 1b517b872348839bce16235db3bfcd3d865744d0 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Sun, 23 Jul 2023 19:40:38 +0300 Subject: [PATCH] minor fixes --- corpus/test.langexp | 51 ++++++++++++++++++++++++--------------------- grammar.g4 | 4 ++-- grammar.js | 10 ++++----- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/corpus/test.langexp b/corpus/test.langexp index 4b3e72f..f5ace2a 100644 --- a/corpus/test.langexp +++ b/corpus/test.langexp @@ -219,6 +219,7 @@ arg_deduction_example 'name 'duration : <- String <- Float -> Task = Task 'name (import (simple_name_identifier)) (import + (placeholder) (simple_name_identifier)) (import (simple_name_identifier) @@ -635,13 +636,14 @@ arg_deduction_example 'name 'duration : <- String <- Float -> Task = Task 'name (simple_name_identifier)))) (type_definition (simple_type_identifier) - (tuple_type - (annotation_identifier) - (type - (simple_type_identifier)) - (annotation_identifier) - (type - (simple_type_identifier)))) + (variant_type + (tuple_type + (annotation_identifier) + (type + (simple_type_identifier)) + (annotation_identifier) + (type + (simple_type_identifier))))) (type_definition (simple_type_identifier) (variant_type @@ -800,27 +802,28 @@ arg_deduction_example 'name 'duration : <- String <- Float -> Task = Task 'name (simple_type_identifier) (argument_type_identifier) (argument_type_identifier) - (tuple_type - (annotation_identifier) - (type - (simple_type_identifier)) - (annotation_identifier) - (type - (simple_type_identifier)) - (annotation_identifier) - (type - (simple_type_identifier) + (variant_type + (tuple_type + (annotation_identifier) (type - (argument_type_identifier)) + (simple_type_identifier)) + (annotation_identifier) (type - (argument_type_identifier))) - (annotation_identifier) - (type - (simple_type_identifier) + (simple_type_identifier)) + (annotation_identifier) (type - (argument_type_identifier)) + (simple_type_identifier) + (type + (argument_type_identifier)) + (type + (argument_type_identifier))) + (annotation_identifier) (type - (argument_type_identifier))))) + (simple_type_identifier) + (type + (argument_type_identifier)) + (type + (argument_type_identifier)))))) (type_definition (simple_type_identifier) (function_definition diff --git a/grammar.g4 b/grammar.g4 index c952ef2..b6401cb 100644 --- a/grammar.g4 +++ b/grammar.g4 @@ -18,7 +18,7 @@ import: ('::' | 'import') (SIMPLE_NAME_IDENTIFIER | '_') ('=' SIMPLE_NAME_IDENTI constraint: '?' expression ; type_definition: (DEFINITION_INFO)? (ANNOTATION_INFO)* ('^')? - SIMPLE_TYPE_IDENTIFIER ((ARGUMENT_TYPE_IDENTIFIER)* '=' (variant_type | typle_type))? + SIMPLE_TYPE_IDENTIFIER ((ARGUMENT_TYPE_IDENTIFIER)* '=' variant_type)? (('{' function_definietion '}')|';') ; @@ -122,7 +122,7 @@ not_name_scoped_expression: block | '(' super_expression ')' ; -variant_type: ('|')? tuple_type ('|' tuple_type)+ ; +variant_type: ('|')? tuple_type ('|' tuple_type)* ; tuple_type: ('&')? annotated_type ('&' _annotated_type)* ; diff --git a/grammar.js b/grammar.js index 5b482b6..f2ca4a5 100644 --- a/grammar.js +++ b/grammar.js @@ -25,7 +25,7 @@ module.exports = grammar({ import: $ => seq( choice('::', 'import'), - field('name', choice($.simple_name_identifier, '_')), + field('name', choice($.simple_name_identifier, $.placeholder)), optional(seq('=', field('module', $.simple_name_identifier))), optional(seq(':', repeat1(choice( $.simple_type_identifier, @@ -45,7 +45,7 @@ module.exports = grammar({ repeat($.annotation_info), optional('^'), field('name', $.simple_type_identifier), - optional(seq(repeat($.argument_type_identifier), '=', choice($.variant_type, $.tuple_type))), + optional(seq(repeat($.argument_type_identifier), '=', $.variant_type)), choice(seq('{', repeat($.function_definition), '}'), ';') ), @@ -53,7 +53,7 @@ module.exports = grammar({ optional($.definition_info), repeat($.annotation_info), repeat(seq($.constraint, ';')), - /*optional(seq(*/optional($._var_let)/*, '.'))*/, + optional($._var_let), choice(field('name', $.simple_name_identifier), seq('(', field('name', $.operator), ')')), repeat(seq( optional($.annotation_identifier), @@ -71,7 +71,7 @@ module.exports = grammar({ typeclass_definition: $ => seq( optional($.definition_info), - repeat($.annotation_info), + // no argumenmts => no annotation info field('name', $.typeclass_identifier), optional(seq(':', repeat1($.typeclass_identifier))), choice(seq('{', repeat($.function_definition), '}'), ';'), @@ -218,7 +218,7 @@ module.exports = grammar({ variant_type: $ => seq( optional('|'), $.tuple_type, - repeat1(seq('|', $.tuple_type)), + repeat(seq('|', $.tuple_type)), ), tuple_type: $ => seq(