Replace '_typed_field' by more specific grammar

Instead of re-using a common rule, inline its definition and use
'_field_identifier' where appropriate.

This is useful for more accurate high-lighting.
This commit is contained in:
Bruno BELANYI 2022-06-03 10:40:14 +02:00
parent 5d37bf7bd1
commit da494122ea
5 changed files with 1715 additions and 1573 deletions

View file

@ -272,16 +272,17 @@ module.exports = grammar({
record_type: ($) => seq( record_type: ($) => seq(
"{", "{",
sepBy(",", $._typed_field), sepBy(
",",
seq(
field("name", $._field_identifier),
":",
field("type", $._type_identifier),
),
),
"}", "}",
), ),
_typed_field: ($) => seq(
field("name", $.identifier),
":",
field("type", $.identifier),
),
array_type: ($) => seq( array_type: ($) => seq(
"array", "array",
"of", "of",
@ -308,7 +309,14 @@ module.exports = grammar({
parameters: ($) => seq( parameters: ($) => seq(
"(", "(",
sepBy(",", $._typed_field), sepBy(
",",
seq(
field("name", $.identifier),
":",
field("type", $._type_identifier),
),
),
")", ")",
), ),

View file

@ -1161,8 +1161,29 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "_typed_field" "members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_field_identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -1174,8 +1195,29 @@
"value": "," "value": ","
}, },
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "_typed_field" "members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_field_identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
} }
] ]
} }
@ -1193,31 +1235,6 @@
} }
] ]
}, },
"_typed_field": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
"array_type": { "array_type": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -1337,8 +1354,29 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "_typed_field" "members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -1350,8 +1388,29 @@
"value": "," "value": ","
}, },
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "_typed_field" "members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
} }
] ]
} }

View file

@ -1414,7 +1414,7 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "type_identifier",
"named": true "named": true
} }
] ]
@ -1570,7 +1570,7 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "field_identifier",
"named": true "named": true
} }
] ]
@ -1580,7 +1580,7 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "type_identifier",
"named": true "named": true
} }
] ]

File diff suppressed because it is too large Load diff

View file

@ -32,10 +32,10 @@ type record = { a: int, b: str }
(type_declaration (type_declaration
name: (identifier) name: (identifier)
value: (record_type value: (record_type
name: (identifier) name: (field_identifier)
type: (identifier) type: (type_identifier)
name: (identifier) name: (field_identifier)
type: (identifier)))) type: (type_identifier))))
================================================================================ ================================================================================
Record type declaration single field Record type declaration single field
@ -49,8 +49,8 @@ type record = { a: int }
(type_declaration (type_declaration
name: (identifier) name: (identifier)
value: (record_type value: (record_type
name: (identifier) name: (field_identifier)
type: (identifier)))) type: (type_identifier))))
================================================================================ ================================================================================
Record type declaration no fields Record type declaration no fields
@ -77,8 +77,8 @@ type record = { a: int, }
(type_declaration (type_declaration
name: (identifier) name: (identifier)
value: (record_type value: (record_type
name: (identifier) name: (field_identifier)
type: (identifier) type: (type_identifier)
(ERROR)))) (ERROR))))
================================================================================ ================================================================================
@ -125,9 +125,9 @@ function func(a: int, b: int) = "string"
name: (identifier) name: (identifier)
parameters: (parameters parameters: (parameters
name: (identifier) name: (identifier)
type: (identifier) type: (type_identifier)
name: (identifier) name: (identifier)
type: (identifier)) type: (type_identifier))
body: (string_literal))) body: (string_literal)))
================================================================================ ================================================================================
@ -143,9 +143,9 @@ function func(a: int, b: int) : string = "string"
name: (identifier) name: (identifier)
parameters: (parameters parameters: (parameters
name: (identifier) name: (identifier)
type: (identifier) type: (type_identifier)
name: (identifier) name: (identifier)
type: (identifier)) type: (type_identifier))
return_type: (type_identifier) return_type: (type_identifier)
body: (string_literal))) body: (string_literal)))
@ -162,7 +162,7 @@ function func(a: int) = "string"
name: (identifier) name: (identifier)
parameters: (parameters parameters: (parameters
name: (identifier) name: (identifier)
type: (identifier)) type: (type_identifier))
body: (string_literal))) body: (string_literal)))
================================================================================ ================================================================================