Skip to content

Commit

Permalink
fix: fix single types being incorrectly parsed as union_type
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 5, 2024
1 parent 657546d commit e6ed6cf
Show file tree
Hide file tree
Showing 11 changed files with 3,909 additions and 3,934 deletions.
8 changes: 6 additions & 2 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function defineGrammar(dialect) {
[$._array_destructing_element, $.array_element_initializer],
[$._primary_expression, $._array_destructing_element],

[$.union_type, $.intersection_type],
[$._type, $.union_type, $.intersection_type],
[$.intersection_type],
[$.if_statement],

Expand Down Expand Up @@ -517,7 +517,11 @@ module.exports = function defineGrammar(dialect) {
field('name', $.variable_name),
),

_type: $ => choice($.union_type, $.intersection_type),
_type: $ => choice(
$._types,
$.union_type,
$.intersection_type,
),

_types: $ => choice(
$.optional_type,
Expand Down
129 changes: 43 additions & 86 deletions common/test/corpus/class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ class A {
body: (declaration_list
(property_declaration
(visibility_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
(property_element (variable_name (name)))
)
(property_declaration
(visibility_modifier)
(static_modifier)
type: (union_type (named_type (name)))
type: (named_type (name))
(property_element (variable_name (name)))
)
(property_declaration
(visibility_modifier)
type: (union_type (optional_type (primitive_type)))
type: (optional_type (primitive_type))
(property_element (variable_name (name)))
)
(property_declaration
Expand Down Expand Up @@ -371,20 +371,19 @@ class Point {
parameters: (formal_parameters
(property_promotion_parameter
visibility: (visibility_modifier)
type: (union_type
(primitive_type)
)
type: (primitive_type)

name: (variable_name (name))
default_value: (float)
)
(simple_parameter
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))
default_value: (float)
)
(property_promotion_parameter
visibility: (visibility_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))
default_value: (float)
)
Expand Down Expand Up @@ -451,282 +450,240 @@ class A {
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(visibility_modifier)
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(visibility_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(primitive_type))
(primitive_type)
(property_element
(variable_name
(name))))
(property_declaration
(readonly_modifier)
(union_type
(named_type
(name)))
(named_type (name))
(property_element
(variable_name
(name)))))))
Expand Down Expand Up @@ -765,7 +722,7 @@ class Point {
(property_promotion_parameter
visibility: (visibility_modifier)
readonly: (readonly_modifier)
type: (union_type (primitive_type))
type: (primitive_type)
name: (variable_name (name))))
body: (compound_statement)))))

Expand Down
Loading

0 comments on commit e6ed6cf

Please sign in to comment.