Fix unlabeled constant record argument bug

pull/204/head
Jonathan Arnett 2022-01-01 20:21:52 +07:00
parent 0802930958
commit d22ce5f6ae
5 changed files with 12011 additions and 11724 deletions

@ -16,7 +16,8 @@ const a = <<52:size(4)-unit(4)>>
const a = <<"Hello Gleam 💫":utf8>> const a = <<"Hello Gleam 💫":utf8>>
const a = Node const a = Node
const a = Node() const a = Node()
const a = Node(name: "Billy", age: 52) const a = Cat("Ginny", 1950)
const a = Person(name: "Billy", age: 52)
const a = uri.Uri(host: "github.com") const a = uri.Uri(host: "github.com")
--- ---
@ -104,16 +105,34 @@ const a = uri.Uri(host: "github.com")
value: (record)) value: (record))
(constant (constant
name: (identifier) name: (identifier)
value: (record)) value: (record
(arguments)))
(constant (constant
name: (identifier) name: (identifier)
value: (record value: (record
(record_arg (string)) (arguments
(record_arg (integer)))) (argument
value: (string))
(argument
value: (integer)))))
(constant
name: (identifier)
value: (record
(arguments
(argument
label: (identifier)
value: (string))
(argument
label: (identifier)
value: (integer)))))
(constant (constant
name: (identifier) name: (identifier)
value: (remote_record value: (remote_record
(record_arg (string))))) module: (identifier)
(arguments
(argument
label: (identifier)
value: (string))))))
================= =================
Public constants Public constants
@ -133,7 +152,8 @@ pub const a = <<52:size(4)-unit(4)>>
pub const a = <<"Hello Gleam 💫":utf8>> pub const a = <<"Hello Gleam 💫":utf8>>
pub const a = Node pub const a = Node
pub const a = Node() pub const a = Node()
pub const a = Node(name: "Billy", age: 52) pub const a = Cat("Ginny", 1950)
pub const a = Person(name: "Billy", age: 52)
pub const a = uri.Uri(host: "github.com") pub const a = uri.Uri(host: "github.com")
--- ---
@ -221,13 +241,31 @@ pub const a = uri.Uri(host: "github.com")
value: (record)) value: (record))
(public_constant (public_constant
name: (identifier) name: (identifier)
value: (record)) value: (record
(arguments)))
(public_constant (public_constant
name: (identifier) name: (identifier)
value: (record value: (record
(record_arg (string)) (arguments
(record_arg (integer)))) (argument
value: (string))
(argument
value: (integer)))))
(public_constant
name: (identifier)
value: (record
(arguments
(argument
label: (identifier)
value: (string))
(argument
label: (identifier)
value: (integer)))))
(public_constant (public_constant
name: (identifier) name: (identifier)
value: (remote_record value: (remote_record
(record_arg (string))))) module: (identifier)
(arguments
(argument
label: (identifier)
value: (string))))))

@ -108,19 +108,27 @@ module.exports = grammar({
_constant_record: ($) => _constant_record: ($) =>
seq( seq(
$._upname, $._upname,
optional( optional(alias($._constant_record_arguments, $.arguments))
),
_constant_record_arguments: ($) =>
seq( seq(
"(", "(",
optional( optional(
series_of(alias($._constant_record_arg, $.record_arg), ",") series_of(alias($._constant_record_argument, $.argument), ",")
), ),
")" ")"
)
)
), ),
_constant_record_arg: ($) => _constant_record_argument: ($) =>
seq($._name, optional(seq(":", $._constant_value))), seq(
_constant_remote_record: ($) => seq($._name, ".", $._constant_record), optional(seq(field("label", $.identifier), ":")),
field("value", $._constant_value)
),
_constant_remote_record: ($) =>
seq(
field("module", alias($._name, $.identifier)),
".",
$._constant_record
),
/* Special constant types */ /* Special constant types */
// Versions of $._type, $._type_annotation, etc, that have constraints // Versions of $._type, $._type_annotation, etc, that have constraints

@ -828,6 +828,22 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_constant_record_arguments"
},
"named": true,
"value": "arguments"
},
{
"type": "BLANK"
}
]
}
]
},
"_constant_record_arguments": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -844,10 +860,10 @@
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_constant_record_arg" "name": "_constant_record_argument"
}, },
"named": true, "named": true,
"value": "record_arg" "value": "argument"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -862,10 +878,10 @@
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_constant_record_arg" "name": "_constant_record_argument"
}, },
"named": true, "named": true,
"value": "record_arg" "value": "argument"
} }
] ]
} }
@ -883,20 +899,9 @@
} }
] ]
}, },
{ "_constant_record_argument": {
"type": "BLANK"
}
]
}
]
},
"_constant_record_arg": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "_name"
},
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -904,12 +909,16 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "FIELD",
"value": ":" "name": "label",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}, },
{ {
"type": "SYMBOL", "type": "STRING",
"name": "_constant_value" "value": ":"
} }
] ]
}, },
@ -917,6 +926,14 @@
"type": "BLANK" "type": "BLANK"
} }
] ]
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_constant_value"
}
} }
] ]
}, },
@ -924,9 +941,18 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "FIELD",
"name": "module",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_name" "name": "_name"
}, },
"named": true,
"value": "identifier"
}
},
{ {
"type": "STRING", "type": "STRING",
"value": "." "value": "."

@ -172,7 +172,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "argument", "type": "argument",
@ -2799,59 +2799,12 @@
"type": "record", "type": "record",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "arguments",
"named": true
},
{
"type": "record_arg",
"named": true
}
]
}
},
{
"type": "record_arg",
"named": true,
"fields": {},
"children": { "children": {
"multiple": false, "multiple": false,
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "bit_string", "type": "arguments",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "record",
"named": true
},
{
"type": "remote_record",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "tuple",
"named": true "named": true
} }
] ]
@ -3111,7 +3064,7 @@
"fields": { "fields": {
"module": { "module": {
"multiple": false, "multiple": false,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "identifier",
@ -3121,15 +3074,15 @@
} }
}, },
"children": { "children": {
"multiple": true, "multiple": false,
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "record", "type": "arguments",
"named": true "named": true
}, },
{ {
"type": "record_arg", "type": "record",
"named": true "named": true
} }
] ]

File diff suppressed because it is too large Load Diff