diff --git a/corpus/test.langexp b/corpus/test.langexp index b9e7510..c076d9b 100644 --- a/corpus/test.langexp +++ b/corpus/test.langexp @@ -220,7 +220,7 @@ parse_number : Unit! = { } : example of or_in and or_out usage for template operators (tuple input and tuple output) -( & ) |-> 'a |-> 'b <-| 'x <-| 'y = ('a := 'x) && ('b := 'y); +( & ) --|-> 'a --|-> 'b <-|-- 'x <-|-- 'y = ('a := 'x) && ('b := 'y); : function, that return result ('!' not used on calls) : useful when tuples returned diff --git a/grammar.js b/grammar.js index e736950..c92a60c 100644 --- a/grammar.js +++ b/grammar.js @@ -18,8 +18,8 @@ module.exports = grammar({ _statement: $ => choice( $.import, - $.type_definition, $.function_definition, + $.type_definition, $.typeclass_definition, $.empty_lines, ), @@ -41,15 +41,6 @@ module.exports = grammar({ // --- definitions - type_definition: $ => seq( - optional($.definition_info), - repeat($.annotation_info), - optional('^'), - field('name', $.simple_type_identifier), - optional(seq(repeat($.argument_type_identifier), '=', $.variant_type)), - choice(seq('{', repeat($.function_definition), '}'), ';') - ), - function_definition: $ => seq( optional($.definition_info), repeat($.annotation_info), @@ -71,6 +62,15 @@ module.exports = grammar({ choice(seq('=', choice(prec(2, choice($.block, $.array)), seq($._super_expression, ';'))), ';'), ), + type_definition: $ => seq( + optional($.definition_info), + repeat($.annotation_info), + optional('^'), + field('name', $.simple_type_identifier), + optional(seq(repeat($.argument_type_identifier), '=', $.variant_type)), + choice(seq('{', repeat($.function_definition), '}'), ';') + ), + typeclass_definition: $ => seq( optional($.definition_info), // no argumenmts => no annotation info @@ -256,7 +256,18 @@ module.exports = grammar({ _do: $ => choice('=>', 'do'), _var_let: $ => choice(choice('%', 'let'), choice('$', 'var')), _optional_result: $ => choice('?', '!'), - _reference: $ => choice(choice('->', 'out'), choice('<-', 'in'), choice('<>', 'ref'), choice('|->', 'or_out'), choice('<-|', 'or_in')), + //_reference: $ => choice(choice('->', 'out'), choice('<-', 'in'), choice('<>', 'ref'), choice('|->', 'or_out'), choice('<-|', 'or_in')), + + // _reference: $ => seq(optional(choice('->', 'out')), optional(choice('<>', 'ref')), optional(choice('--', 'const')), optional(choice('<-', 'in'))), + + _reference: $ => choice(choice('<-', '<>', '--', '->', + '<-|<>', '<-|--', '<>|->', '--|->', '<>|--', '<-|->', + '<-|<>|->', '<-|--|->', '<-|<>|--', '<>|--|->', + '<-|<>|--|->'), + choice('in', 'ref', 'const', 'out', + 'in|ref', 'in|const', 'ref|out', 'const|out', 'ref|const', 'in|out', + 'in|ref|out', 'in|const|out', 'in|ref|const', 'ref|const|out', + 'in|ref|const|out')), _name_identifier: $ => choice($.argument_name_identifier, $.simple_name_identifier), _type_identifier: $ => choice($.argument_type_identifier, $.simple_type_identifier),