From 6a4024270793eec85db6992ec7d8058895f63ddc Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 15 Apr 2023 22:55:36 -0300 Subject: [PATCH] better support for aliased type --- grammar.js | 6 ++---- test/corpus/type_declarations.txt | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/grammar.js b/grammar.js index c1ed37e..c2b2466 100644 --- a/grammar.js +++ b/grammar.js @@ -313,6 +313,7 @@ module.exports = grammar({ $._inline_type, $.variant_type, $.record_type, + $.as_aliasing_type, ), _inline_type: $ => choice( @@ -375,7 +376,6 @@ module.exports = grammar({ optional('|'), barSep1($.polyvar_declaration), ']', - optional($.as_aliasing_type) )), polyvar_declaration: $ => prec.right( @@ -417,7 +417,6 @@ module.exports = grammar({ seq('..', commaSept($._object_type_field)), ), '}', - optional($.as_aliasing_type) )), _object_type_field: $ => alias($.object_type_field, $.field), @@ -436,7 +435,6 @@ module.exports = grammar({ generic_type: $ => prec.left(seq( $._type_identifier, $.type_arguments, - optional($.as_aliasing_type) )), type_arguments: $ => seq( @@ -734,7 +732,7 @@ module.exports = grammar({ optional($.type_annotation) )), - as_aliasing_type: $ => seq('as', $.type_identifier), + as_aliasing_type: $ => seq($._type, 'as', $.type_identifier), assert_expression: $ => prec.left(seq('assert', $.expression)), diff --git a/test/corpus/type_declarations.txt b/test/corpus/type_declarations.txt index 66fd308..e9b3aa1 100644 --- a/test/corpus/type_declarations.txt +++ b/test/corpus/type_declarations.txt @@ -264,12 +264,13 @@ type t<'w> = [M.t<'w>] (type_binding (type_identifier) (type_parameters (type_identifier)) - (polyvar_type - (decorator (decorator_identifier)) - (polyvar_declaration (polyvar_identifier)) - (polyvar_declaration (polyvar_identifier)) - (polyvar_declaration (polyvar_identifier)) - (as_aliasing_type (type_identifier))))) + (as_aliasing_type + (polyvar_type + (decorator (decorator_identifier)) + (polyvar_declaration (polyvar_identifier)) + (polyvar_declaration (polyvar_identifier)) + (polyvar_declaration (polyvar_identifier))) + (type_identifier)))) (type_declaration (type_binding @@ -368,9 +369,10 @@ type t<'a> = {.."name": string} as 'a (type_binding (type_identifier) (type_parameters (type_identifier)) - (object_type - (field (property_identifier (string_fragment)) (type_identifier)) - (as_aliasing_type (type_identifier)))))) + (as_aliasing_type + (object_type + (field (property_identifier (string_fragment)) (type_identifier))) + (type_identifier))))) =========================================== Generic @@ -403,10 +405,11 @@ type t<'a> = generic<'a> as 's (type_binding (type_identifier) (type_parameters (type_identifier)) - (generic_type - (type_identifier) - (type_arguments (type_identifier)) - (as_aliasing_type (type_identifier)))))) + (as_aliasing_type + (generic_type + (type_identifier) + (type_arguments (type_identifier))) + (type_identifier))))) =========================================== Recursive