start of working on nullable types as well as adding another failing test from syntax we are not currently handling

pull/185/head
Tim Whiting 2020-07-14 21:13:04 +07:00
parent ccbabd6e6a
commit 245ef1215a
5 changed files with 96814 additions and 92996 deletions

@ -183,6 +183,7 @@ module.exports = grammar({
[$.library_name, $.dotted_identifier_list],
[$._top_level_definition, $.inferred_type],
[$._final_const_var_or_type, $._top_level_definition, $.function_signature],
[$._function_type_tail]
],
word: $ => $.identifier,
@ -1164,17 +1165,19 @@ module.exports = grammar({
// ),
type_arguments: $ => $._type_args,
_type_args: $ => choice(
_type_args: $ => prec.right(choice(
seq(
'<',
'>'
'>',
optional($._nullable_type)
),
seq(
'<',
commaSep1($._type),
'>'
'>',
optional($._nullable_type)
)
),
),),
wildcard: $ => seq(
optional($._metadata),
@ -1564,8 +1567,8 @@ module.exports = grammar({
part_of_directive: $ => seq(
optional($._metadata),
'part of',
$.uri,
'part','of',
choice($.dotted_identifier_list, $.uri),
$._semicolon
),
@ -2219,7 +2222,9 @@ module.exports = grammar({
_function_type_tail: $ => seq(
$._function_builtin_identifier,
optional($.type_parameters),
$.parameter_type_list
optional($._nullable_type),
$.parameter_type_list,
optional($._nullable_type),
),
parameter_type_list: $ => seq(
@ -2333,7 +2338,8 @@ module.exports = grammar({
),
optional(
$._type_dot_identifier
)
),
optional($._nullable_type),
)
),
@ -2353,6 +2359,8 @@ module.exports = grammar({
$.identifier
),
_nullable_type: $ => prec(DART_PREC.BUILTIN, '?'),
floating_point_type: $ => choice(
'float',
'double'

@ -4098,60 +4098,88 @@
"name": "_type_args"
},
"_type_args": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": ">"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_type"
}
]
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": ">"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nullable_type"
},
{
"type": "BLANK"
}
}
]
},
{
"type": "STRING",
"value": ">"
}
]
}
]
]
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_type"
}
]
}
}
]
},
{
"type": "STRING",
"value": ">"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nullable_type"
},
{
"type": "BLANK"
}
]
}
]
}
]
}
},
"wildcard": {
"type": "SEQ",
@ -5612,11 +5640,24 @@
},
{
"type": "STRING",
"value": "part of"
"value": "part"
},
{
"type": "SYMBOL",
"name": "uri"
"type": "STRING",
"value": "of"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "dotted_identifier_list"
},
{
"type": "SYMBOL",
"name": "uri"
}
]
},
{
"type": "SYMBOL",
@ -8027,9 +8068,33 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nullable_type"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "parameter_type_list"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nullable_type"
},
{
"type": "BLANK"
}
]
}
]
},
@ -8328,6 +8393,18 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nullable_type"
},
{
"type": "BLANK"
}
]
}
]
}
@ -8367,6 +8444,14 @@
}
]
},
"_nullable_type": {
"type": "PREC",
"value": 0,
"content": {
"type": "STRING",
"value": "?"
}
},
"floating_point_type": {
"type": "CHOICE",
"members": [
@ -9888,6 +9973,9 @@
"_final_const_var_or_type",
"_top_level_definition",
"function_signature"
],
[
"_function_type_tail"
]
],
"externals": [

@ -7745,6 +7745,10 @@
"type": "annotation",
"named": true
},
{
"type": "dotted_identifier_list",
"named": true
},
{
"type": "marker_annotation",
"named": true
@ -10729,19 +10733,19 @@
"named": true
},
{
"type": "on",
"type": "of",
"named": false
},
{
"type": "operator",
"type": "on",
"named": false
},
{
"type": "part",
"type": "operator",
"named": false
},
{
"type": "part of",
"type": "part",
"named": false
},
{

File diff suppressed because it is too large Load Diff

@ -451,4 +451,27 @@ class MyClass {
(type_identifier) (type_arguments (type_identifier))
(initialized_identifier_list (initialized_identifier (identifier) (list_literal (string_literal) (string_literal) (string_literal) (string_literal) (string_literal))))
(type_identifier) (static_final_declaration_list (static_final_declaration (identifier) (string_literal)))
(class_definition (identifier) (class_body)))
(class_definition (identifier) (class_body)))
==================================
Nullable Function Parameter
==================================
void callback(Future<void> Function(String?) handler) {
}
---
(program
(function_signature (void_type) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (type_arguments (void_type))
(parameter_type_list (normal_parameter_type (type_identifier))) (identifier))))
(function_body (block)))
==================================
Type with Library Prefix
==================================
const my.MyType newMyType = my.MyType();
---