Skip to content

Commit

Permalink
Support aliased inline types
Browse files Browse the repository at this point in the history
This allows adding aliased types to record fields without allowing illegal non-inline types such as record or variants.
  • Loading branch information
Emilios1995 committed Mar 20, 2024
1 parent e0bc632 commit e39df74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ module.exports = grammar({
$.module_pack,
$.unit,
$.polymorphic_type,
alias($._as_aliasing_non_function_inline_type, $.as_aliasing_type)
),

polymorphic_type: $ => seq(
Expand Down Expand Up @@ -706,6 +707,9 @@ module.exports = grammar({

as_aliasing_type: $ => seq($._type, 'as', $.type_identifier),

_as_aliasing_non_function_inline_type: $ =>
prec(2, seq($._non_function_inline_type, 'as', $.type_identifier)),

assert_expression: $ => prec.left(seq('assert', $.expression)),

call_expression: $ => prec('call', seq(
Expand Down
12 changes: 10 additions & 2 deletions test/corpus/type_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ type t = {

mutable x: int,

opt?: string
opt?: string,

env: {..} as 'env
}

type t = Mod.t = {a: int}
Expand Down Expand Up @@ -140,7 +142,13 @@ type t = {
(record_type_field
(property_identifier)
(type_annotation
(type_identifier))))))
(type_identifier)))
(record_type_field
(property_identifier)
(type_annotation
(as_aliasing_type
(object_type)
(type_identifier)))))))
(type_declaration
(type_binding
(type_identifier)
Expand Down

0 comments on commit e39df74

Please sign in to comment.