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,14 +272,15 @@ module.exports = grammar({
record_type: ($) => seq(
"{",
sepBy(",", $._typed_field),
"}",
),
_typed_field: ($) => seq(
field("name", $.identifier),
sepBy(
",",
seq(
field("name", $._field_identifier),
":",
field("type", $.identifier),
field("type", $._type_identifier),
),
),
"}",
),
array_type: ($) => seq(
@ -308,7 +309,14 @@ module.exports = grammar({
parameters: ($) => seq(
"(",
sepBy(",", $._typed_field),
sepBy(
",",
seq(
field("name", $.identifier),
":",
field("type", $._type_identifier),
),
),
")",
),

View file

@ -1161,8 +1161,29 @@
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_typed_field"
"name": "_field_identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
},
{
"type": "REPEAT",
@ -1174,8 +1195,29 @@
"value": ","
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_typed_field"
"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": {
"type": "SEQ",
"members": [
@ -1337,8 +1354,29 @@
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_typed_field"
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
},
{
"type": "REPEAT",
@ -1350,8 +1388,29 @@
"value": ","
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_typed_field"
"name": "identifier"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
}
]
}
]
}

View file

@ -1414,7 +1414,7 @@
"required": false,
"types": [
{
"type": "identifier",
"type": "type_identifier",
"named": true
}
]
@ -1570,7 +1570,7 @@
"required": false,
"types": [
{
"type": "identifier",
"type": "field_identifier",
"named": true
}
]
@ -1580,7 +1580,7 @@
"required": false,
"types": [
{
"type": "identifier",
"type": "type_identifier",
"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
name: (identifier)
value: (record_type
name: (identifier)
type: (identifier)
name: (identifier)
type: (identifier))))
name: (field_identifier)
type: (type_identifier)
name: (field_identifier)
type: (type_identifier))))
================================================================================
Record type declaration single field
@ -49,8 +49,8 @@ type record = { a: int }
(type_declaration
name: (identifier)
value: (record_type
name: (identifier)
type: (identifier))))
name: (field_identifier)
type: (type_identifier))))
================================================================================
Record type declaration no fields
@ -77,8 +77,8 @@ type record = { a: int, }
(type_declaration
name: (identifier)
value: (record_type
name: (identifier)
type: (identifier)
name: (field_identifier)
type: (type_identifier)
(ERROR))))
================================================================================
@ -125,9 +125,9 @@ function func(a: int, b: int) = "string"
name: (identifier)
parameters: (parameters
name: (identifier)
type: (identifier)
type: (type_identifier)
name: (identifier)
type: (identifier))
type: (type_identifier))
body: (string_literal)))
================================================================================
@ -143,9 +143,9 @@ function func(a: int, b: int) : string = "string"
name: (identifier)
parameters: (parameters
name: (identifier)
type: (identifier)
type: (type_identifier)
name: (identifier)
type: (identifier))
type: (type_identifier))
return_type: (type_identifier)
body: (string_literal)))
@ -162,7 +162,7 @@ function func(a: int) = "string"
name: (identifier)
parameters: (parameters
name: (identifier)
type: (identifier))
type: (type_identifier))
body: (string_literal)))
================================================================================