fix: object expressions

pull/625/head^2
Nikolaj Sidorenco 2024-04-18 22:27:26 +07:00
parent 385792d371
commit ee8d1dcc6e
No known key found for this signature in database
5 changed files with 223670 additions and 246690 deletions

@ -1 +1,4 @@
let x = "\""
let x =
{ new Base with
member _.A() = ()
member _.B() = () }

@ -477,7 +477,7 @@ module.exports = grammar({
_object_expression_inner: $ =>
seq(
$._object_members,
$._interface_implementations,
repeat($.interface_implementation),
),
object_expression: $ =>
@ -485,7 +485,7 @@ module.exports = grammar({
seq(
'new',
$._base_call,
scoped($._object_expression_inner, $._indent, $._dedent),
$._object_expression_inner,
)),
_base_call: $ =>
@ -1429,11 +1429,10 @@ module.exports = grammar({
_type_defn_elements: $ =>
choice(
$._member_defns,
$._interface_implementations,
prec.left(repeat1($.interface_implementation)),
// $._interface_signature
),
_interface_implementations: $ => prec.right(repeat1($.interface_implementation)),
interface_implementation: $ =>
prec.left(
seq(

46
src/grammar.json generated

@ -1697,8 +1697,11 @@
"name": "_object_members"
},
{
"type": "SYMBOL",
"name": "_interface_implementations"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "interface_implementation"
}
}
]
},
@ -1717,21 +1720,8 @@
"name": "_base_call"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "SYMBOL",
"name": "_object_expression_inner"
},
{
"type": "SYMBOL",
"name": "_dedent"
}
]
"type": "SYMBOL",
"name": "_object_expression_inner"
}
]
}
@ -5490,22 +5480,18 @@
"name": "_member_defns"
},
{
"type": "SYMBOL",
"name": "_interface_implementations"
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "interface_implementation"
}
}
}
]
},
"_interface_implementations": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "interface_implementation"
}
}
},
"interface_implementation": {
"type": "PREC_LEFT",
"value": 0,

470259
src/parser.c generated

File diff suppressed because it is too large Load Diff

@ -1737,3 +1737,46 @@ let test =
(identifier)))
(const
(int))))))))
================================================================================
object interface expression
================================================================================
let x =
{ new IBase with
member _.A() = ()
member _.B() = () }
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(brace_expression
(object_expression
(object_construction
(type
(long_identifier
(identifier))))
(member_defn
(method_or_prop_defn
(property_or_ident
(identifier)
(identifier))
(const_pattern
(unit))
(const
(unit))))
(member_defn
(method_or_prop_defn
(property_or_ident
(identifier)
(identifier))
(const_pattern
(unit))
(const
(unit)))))))))