支持全局函数补全
This commit is contained in:
@@ -49,6 +49,7 @@ const kPrec = {
|
||||
|
||||
kArray: 20,
|
||||
};
|
||||
|
||||
const kSemicolon = ";";
|
||||
|
||||
module.exports = grammar({
|
||||
@@ -117,34 +118,31 @@ module.exports = grammar({
|
||||
seq(
|
||||
kw("const"),
|
||||
field("name", $.identifier),
|
||||
optional($._type_annotation),
|
||||
optional($._type_clause),
|
||||
"=",
|
||||
field("value", $.expression),
|
||||
kSemicolon,
|
||||
),
|
||||
|
||||
var_declaration: ($) =>
|
||||
seq(kw("var"), $._variable_declaration, optional($._type_annotation)),
|
||||
seq(kw("var"), $._variable_declaration, optional($._type_clause)),
|
||||
|
||||
static_declaration: ($) =>
|
||||
seq(kw("static"), $._variable_declaration, optional($._type_annotation)),
|
||||
seq(kw("static"), $._variable_declaration, optional($._type_clause)),
|
||||
|
||||
global_declaration: ($) =>
|
||||
seq(kw("global"), $._variable_declaration, optional($._type_annotation)),
|
||||
seq(kw("global"), $._variable_declaration, optional($._type_clause)),
|
||||
|
||||
_variable_declaration: ($) => sep1(field("name", $.identifier), ","),
|
||||
|
||||
_type_annotation: ($) => seq(":", $.type_specification),
|
||||
_type_clause: ($) => seq(":", field("type_name", $.type_name)),
|
||||
|
||||
type_specification: ($) =>
|
||||
field(
|
||||
"type",
|
||||
token(
|
||||
choice(
|
||||
// array of xxx
|
||||
seq("array", /\s+/, "of", /\s+/, /[_a-zA-Z][_a-zA-Z0-9_.]*/),
|
||||
/[_a-zA-Z][_a-zA-Z0-9_.]*/,
|
||||
),
|
||||
type_name: (_) =>
|
||||
token(
|
||||
choice(
|
||||
// array of xxx
|
||||
seq("array", /\s+/, "of", /\s+/, /[_a-zA-Z][_a-zA-Z0-9_.]*/),
|
||||
/[_a-zA-Z][_a-zA-Z0-9_.]*/,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -590,7 +588,7 @@ module.exports = grammar({
|
||||
seq(
|
||||
kw("function"),
|
||||
$._parameter_signature,
|
||||
field("return_type", optional($._type_annotation)),
|
||||
field("return_type", optional($._type_clause)),
|
||||
optional(kSemicolon),
|
||||
field("body", $.block_statement),
|
||||
),
|
||||
@@ -599,8 +597,8 @@ module.exports = grammar({
|
||||
|
||||
_unpack_vars: ($) =>
|
||||
seq(
|
||||
field("variable", $.identifier),
|
||||
repeat1(seq(",", field("variable", $.identifier))),
|
||||
field("name", $.identifier),
|
||||
repeat1(seq(",", field("name", $.identifier))),
|
||||
),
|
||||
|
||||
_left_hand_side: ($) =>
|
||||
@@ -1093,7 +1091,7 @@ module.exports = grammar({
|
||||
|
||||
case_branch: ($) =>
|
||||
seq(
|
||||
field("values", $.case_values),
|
||||
$.case_values,
|
||||
":",
|
||||
field("consequence", $._statement_suite),
|
||||
),
|
||||
@@ -1105,9 +1103,9 @@ module.exports = grammar({
|
||||
try_statement: ($) =>
|
||||
seq(
|
||||
kw("try"),
|
||||
optional(field("body", repeat1($._statement))),
|
||||
optional(field("try_body", repeat1($._statement))),
|
||||
kw("except"),
|
||||
optional(field("body", repeat1($._statement))),
|
||||
optional(field("except_body", repeat1($._statement))),
|
||||
kw("end"),
|
||||
optional(kSemicolon),
|
||||
),
|
||||
@@ -1120,7 +1118,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
field("name", $.identifier),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
kSemicolon,
|
||||
),
|
||||
|
||||
@@ -1129,7 +1127,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
field("name", $.identifier),
|
||||
$._parameter_signature,
|
||||
field("return_type", optional($._type_annotation)),
|
||||
field("return_type", optional($._type_clause)),
|
||||
optional(kSemicolon),
|
||||
field("body", $.block_statement),
|
||||
optional(kSemicolon),
|
||||
@@ -1142,9 +1140,9 @@ module.exports = grammar({
|
||||
|
||||
parameter: ($) =>
|
||||
seq(
|
||||
optional(choice(field("var", kw("var")), field("out", kw("out")))),
|
||||
optional(choice(kw("var"), kw("out"))),
|
||||
sep1(field("name", $.identifier), ","),
|
||||
optional(field("type", $._type_annotation)),
|
||||
optional(field("type", $._type_clause)),
|
||||
optional(seq("=", field("default", $.expression))),
|
||||
),
|
||||
|
||||
@@ -1199,7 +1197,7 @@ module.exports = grammar({
|
||||
choice($.static_declaration, $.nostatic_declaration),
|
||||
|
||||
nostatic_declaration: ($) =>
|
||||
seq($._variable_declaration, optional($._type_annotation)),
|
||||
seq($._variable_declaration, optional($._type_clause)),
|
||||
|
||||
method_declaration: ($) =>
|
||||
choice(
|
||||
@@ -1214,7 +1212,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
field("name", $.method_name),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
kSemicolon,
|
||||
),
|
||||
|
||||
@@ -1223,7 +1221,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
field("name", $.method_name),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
kSemicolon,
|
||||
field("modifier", $.method_modifier),
|
||||
kSemicolon,
|
||||
@@ -1236,7 +1234,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
field("name", $.method_name),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
optional(kSemicolon),
|
||||
field("body", $.block_statement),
|
||||
optional(kSemicolon),
|
||||
@@ -1261,7 +1259,7 @@ module.exports = grammar({
|
||||
seq(
|
||||
kw("property"),
|
||||
field("name", $.identifier),
|
||||
optional($._type_annotation),
|
||||
optional($._type_clause),
|
||||
optional($._property_index),
|
||||
field("accessors", $.property_accessors),
|
||||
kSemicolon,
|
||||
@@ -1357,7 +1355,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
$._qualified_method_name,
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
kSemicolon,
|
||||
field("modifier", $.method_modifier),
|
||||
kSemicolon,
|
||||
@@ -1374,7 +1372,7 @@ module.exports = grammar({
|
||||
kw("function"),
|
||||
$._qualified_method_name,
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
optional(kSemicolon),
|
||||
field("body", $.block_statement),
|
||||
optional(kSemicolon),
|
||||
@@ -1388,7 +1386,7 @@ module.exports = grammar({
|
||||
".",
|
||||
field("operator", $._overloadable_operator),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
optional(kSemicolon),
|
||||
field("body", $.block_statement),
|
||||
optional(kSemicolon),
|
||||
@@ -1402,7 +1400,7 @@ module.exports = grammar({
|
||||
".",
|
||||
field("operator", $._overloadable_operator),
|
||||
$._parameter_signature,
|
||||
optional(field("return_type", $._type_annotation)),
|
||||
optional(field("return_type", $._type_clause)),
|
||||
kSemicolon,
|
||||
field("modifier", $.method_modifier),
|
||||
kSemicolon,
|
||||
|
||||
Reference in New Issue
Block a user