improve tree-sitter

This commit is contained in:
csh 2025-10-26 22:51:27 +08:00
parent 9385aaf2c1
commit dbccd5b605
9 changed files with 270641 additions and 270588 deletions

View File

@ -2413,20 +2413,20 @@
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
@ -5601,7 +5601,7 @@
}
]
},
"function_declaration_statement": {
"_function_header": {
"type": "SEQ",
"members": [
{
@ -5640,6 +5640,15 @@
"type": "BLANK"
}
]
}
]
},
"function_declaration_statement": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_function_header"
},
{
"type": "STRING",
@ -5650,42 +5659,9 @@
"function_definition_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)function"
},
"named": false,
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
"name": "_function_header"
},
{
"type": "CHOICE",
@ -5724,42 +5700,9 @@
"function_definition_with_overload_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)function"
},
"named": false,
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
"name": "_function_header"
},
{
"type": "STRING",
@ -6115,11 +6058,20 @@
]
},
"class_body": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "class_member"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "uses_statement"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "class_member"
}
}
]
},
"class_member": {
"type": "CHOICE",
@ -6156,10 +6108,6 @@
"name": "property_declaration"
}
]
},
{
"type": "SYMBOL",
"name": "uses_statement"
}
]
},
@ -7396,8 +7344,33 @@
]
},
"_operator_method": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_operator_overload_method"
},
{
"type": "SYMBOL",
"name": "_operator_method_with_modifier"
}
]
},
"_normal_method": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
@ -7408,33 +7381,8 @@
"value": "function"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)operator"
},
"named": false,
"value": "operator"
},
{
"type": "FIELD",
"name": "class_name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "SYMBOL",
"name": "_overloadable_operator"
}
"type": "SYMBOL",
"name": "_qualified_method_name"
},
{
"type": "SYMBOL",
@ -7490,21 +7438,9 @@
}
]
},
"_normal_method": {
"_operator_overload_method": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
@ -7515,8 +7451,33 @@
"value": "function"
},
{
"type": "SYMBOL",
"name": "_qualified_method_name"
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)operator"
},
"named": false,
"value": "operator"
},
{
"type": "FIELD",
"name": "class_name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "SYMBOL",
"name": "_overloadable_operator"
}
},
{
"type": "SYMBOL",

View File

@ -1127,6 +1127,10 @@
{
"type": "class_member",
"named": true
},
{
"type": "uses_statement",
"named": true
}
]
}
@ -1230,10 +1234,6 @@
"type": "property_declaration",
"named": true
},
{
"type": "uses_statement",
"named": true
},
{
"type": "variable_declaration",
"named": true
@ -1680,7 +1680,7 @@
"fields": {
"body": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "block_suite",
@ -1690,7 +1690,7 @@
},
"class_name": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "identifier",

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,2 @@
function abc();
begin
uses m1, m2;
data := `r | data;
type A = class(B.c)
end;

View File

@ -16,6 +16,8 @@ ROOT_DIRS=(
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext/other"
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext/tsword"
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext/word2arr"
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext/tsoffice"
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext/OfficeXml-dev"
# "/mnt/d/code/tinysoft/PdfConverter"
# 可以添加更多目录
# "/path/to/third/directory"

View File

@ -130,13 +130,28 @@ module.exports = grammar({
),
var_declaration: ($) =>
seq(kw("var"), $._variable_declaration, optional($._type_clause), optional($._initial_value)),
seq(
kw("var"),
$._variable_declaration,
optional($._type_clause),
optional($._initial_value),
),
static_declaration: ($) =>
seq(kw("static"), $._variable_declaration, optional($._type_clause), optional($._initial_value)),
seq(
kw("static"),
$._variable_declaration,
optional($._type_clause),
optional($._initial_value),
),
global_declaration: ($) =>
seq(kw("global"), $._variable_declaration, optional($._type_clause), optional($._initial_value)),
seq(
kw("global"),
$._variable_declaration,
optional($._type_clause),
optional($._initial_value),
),
_initial_value: ($) =>
seq(":=", field("initial_value", $._right_hand_side)),
@ -177,14 +192,23 @@ module.exports = grammar({
// inherited_statement: ($) => seq($._inherited_expression, kSemicolon),
_built_in_expression: ($) =>
choice($.echo_expression, $.raise_expression, $.new_expression, $.inherited_expression),
choice(
$.echo_expression,
$.raise_expression,
$.new_expression,
$.inherited_expression,
),
echo_expression: ($) =>
prec.left(1, seq(kw("echo"), sep1(field("argument", $.expression), ","))),
raise_expression: ($) => seq(kw("raise"), field("exception", $.expression)),
inherited_expression: ($) => prec.left(0, seq(kw("inherited"), field("class", optional($.expression)))),
inherited_expression: ($) =>
prec.left(
0,
seq(kw("inherited"), field("class", optional($.expression))),
),
new_expression: ($) => seq(kw("new"), field("class", $.expression)),
@ -323,24 +347,26 @@ module.exports = grammar({
kPrec.kComparsion,
seq(
field("left", $.expression),
field("operator", choice(
"=",
"<>",
">",
">=",
"<",
"<=",
".=",
".<>",
".>",
".>=",
".<",
".<=",
$.in,
kw("is"),
kw("like"),
),
),
field(
"operator",
choice(
"=",
"<>",
">",
">=",
"<",
"<=",
".=",
".<>",
".>",
".>=",
".<",
".<=",
$.in,
kw("is"),
kw("like"),
),
),
field("right", $.expression),
),
),
@ -600,7 +626,7 @@ module.exports = grammar({
seq(
kw("function"),
$._parameter_signature,
field("return_type", optional($._type_clause)),
optional(field("return_type", $._type_clause)),
optional(kSemicolon),
field("body", $.block_suite),
),
@ -614,12 +640,7 @@ module.exports = grammar({
),
_left_hand_side: ($) =>
choice(
$._identifier_like,
$.attribute,
$.subscript,
$.unpack_pattern,
),
choice($._identifier_like, $.attribute, $.subscript, $.unpack_pattern),
_right_hand_side: ($) =>
choice(
@ -929,7 +950,8 @@ module.exports = grammar({
),
),
_parenthesized_expression: ($) => seq("(", optional($._assignable_expression), ")"),
_parenthesized_expression: ($) =>
seq("(", optional($._assignable_expression), ")"),
array: ($) =>
prec(
@ -985,15 +1007,7 @@ module.exports = grammar({
),
parenthesized_array: ($) =>
prec(
1,
seq(
"(",
sep1($.array_element, ","),
optional(","),
")",
),
),
prec(1, seq("(", sep1($.array_element, ","), optional(","), ")")),
line_comment: (_) => token(seq("//", /.*/)),
@ -1004,11 +1018,7 @@ module.exports = grammar({
if_statement: ($) =>
prec.right(
kPrec.kIf,
seq(
$.if_clause,
repeat($.else_if_clause),
optional($.else_clause),
),
seq($.if_clause, repeat($.else_if_clause), optional($.else_clause)),
),
if_clause: ($) =>
@ -1115,21 +1125,23 @@ module.exports = grammar({
anonymous_function_statement: ($) =>
seq($.anonymous_function_expression, optional(kSemicolon)),
function_declaration_statement: ($) =>
_function_header: ($) =>
seq(
kw("function"),
field("name", $.identifier),
$._parameter_signature,
optional(field("return_type", $._type_clause)),
),
function_declaration_statement: ($) =>
seq(
$._function_header,
kSemicolon,
),
function_definition_statement: ($) =>
seq(
kw("function"),
field("name", $.identifier),
$._parameter_signature,
field("return_type", optional($._type_clause)),
$._function_header,
optional(kSemicolon),
field("body", $.block_suite),
optional(kSemicolon),
@ -1137,10 +1149,7 @@ module.exports = grammar({
function_definition_with_overload_statement: ($) =>
seq(
kw("function"),
field("name", $.identifier),
$._parameter_signature,
field("return_type", optional($._type_clause)),
$._function_header,
kSemicolon,
kw("overload"),
kSemicolon,
@ -1180,7 +1189,10 @@ module.exports = grammar({
")",
),
class_body: ($) => repeat1($.class_member),
class_body: ($) => choice(
$.uses_statement,
repeat1($.class_member),
),
class_member: ($) =>
choice(
@ -1191,7 +1203,6 @@ module.exports = grammar({
$._method_declaration,
$.property_declaration,
),
$.uses_statement,
),
access_modifier: (_) =>
@ -1209,13 +1220,23 @@ module.exports = grammar({
reference_modifier: (_) => choice(kw("weakref"), kw("autoref")),
member_variable: ($) => choice($.static_member_variable, $.field_member_variable),
member_variable: ($) =>
choice($.static_member_variable, $.field_member_variable),
static_member_variable: ($) =>
seq(kw("static"), $._variable_declaration, optional($._type_clause), optional(seq("=", field("initial_value", $._right_hand_side)))),
seq(
kw("static"),
$._variable_declaration,
optional($._type_clause),
optional(seq("=", field("initial_value", $._right_hand_side))),
),
field_member_variable: ($) =>
seq($._variable_declaration, optional($._type_clause), optional(seq("=", field("initial_value", $._right_hand_side)))),
seq(
$._variable_declaration,
optional($._type_clause),
optional(seq("=", field("initial_value", $._right_hand_side))),
),
_method_declaration: ($) =>
choice(
@ -1283,7 +1304,8 @@ module.exports = grammar({
kSemicolon,
),
_property_index: ($) => seq(kw("index"), field("index", choice($.number, $.string))),
_property_index: ($) =>
seq(kw("index"), field("index", choice($.number, $.string))),
property_accessors: ($) =>
choice(
@ -1298,10 +1320,20 @@ module.exports = grammar({
_write_only_accessor: ($) => seq(kw("write"), field("write", $.identifier)),
_read_write_accessor: ($) =>
seq(kw("read"), field("read", $.identifier), kw("write"), field("write", $.identifier)),
seq(
kw("read"),
field("read", $.identifier),
kw("write"),
field("write", $.identifier),
),
_write_read_accessor: ($) =>
seq(kw("write"), field("write", $.identifier), kw("read"), field("read", $.identifier)),
seq(
kw("write"),
field("write", $.identifier),
kw("read"),
field("read", $.identifier),
),
// 类外方法实现
external_method_statement: ($) =>
@ -1382,7 +1414,7 @@ module.exports = grammar({
),
_operator_method: ($) =>
choice($._operator_method, $._operator_method_with_modifier),
choice($._operator_overload_method, $._operator_method_with_modifier),
_normal_method: ($) =>
seq(
@ -1396,7 +1428,7 @@ module.exports = grammar({
optional(kSemicolon),
),
_operator_method: ($) =>
_operator_overload_method: ($) =>
seq(
kw("function"),
kw("operator"),
@ -1447,8 +1479,7 @@ module.exports = grammar({
".",
),
interface_section: ($) =>
seq(kw("interface"), repeat($._statement)),
interface_section: ($) => seq(kw("interface"), repeat($._statement)),
implementation_section: ($) =>
seq(kw("implementation"), repeat($._statement)),
@ -1456,8 +1487,7 @@ module.exports = grammar({
initialization_section: ($) =>
seq(kw("initialization"), repeat($._statement)),
finalization_section: ($) =>
seq(kw("finalization"), repeat($._statement)),
finalization_section: ($) => seq(kw("finalization"), repeat($._statement)),
uses_statement: ($) =>
seq(kw("uses"), sep1(field("unit", $.identifier), ","), kSemicolon),

View File

@ -2413,20 +2413,20 @@
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
@ -5601,7 +5601,7 @@
}
]
},
"function_declaration_statement": {
"_function_header": {
"type": "SEQ",
"members": [
{
@ -5640,6 +5640,15 @@
"type": "BLANK"
}
]
}
]
},
"function_declaration_statement": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_function_header"
},
{
"type": "STRING",
@ -5650,42 +5659,9 @@
"function_definition_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)function"
},
"named": false,
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
"name": "_function_header"
},
{
"type": "CHOICE",
@ -5724,42 +5700,9 @@
"function_definition_with_overload_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)function"
},
"named": false,
"value": "function"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
"name": "_parameter_signature"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_clause"
},
{
"type": "BLANK"
}
]
}
"name": "_function_header"
},
{
"type": "STRING",
@ -6115,11 +6058,20 @@
]
},
"class_body": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "class_member"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "uses_statement"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "class_member"
}
}
]
},
"class_member": {
"type": "CHOICE",
@ -6156,10 +6108,6 @@
"name": "property_declaration"
}
]
},
{
"type": "SYMBOL",
"name": "uses_statement"
}
]
},
@ -7396,8 +7344,33 @@
]
},
"_operator_method": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_operator_overload_method"
},
{
"type": "SYMBOL",
"name": "_operator_method_with_modifier"
}
]
},
"_normal_method": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
@ -7408,33 +7381,8 @@
"value": "function"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)operator"
},
"named": false,
"value": "operator"
},
{
"type": "FIELD",
"name": "class_name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "SYMBOL",
"name": "_overloadable_operator"
}
"type": "SYMBOL",
"name": "_qualified_method_name"
},
{
"type": "SYMBOL",
@ -7490,21 +7438,9 @@
}
]
},
"_normal_method": {
"_operator_overload_method": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
@ -7515,8 +7451,33 @@
"value": "function"
},
{
"type": "SYMBOL",
"name": "_qualified_method_name"
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "(?i)operator"
},
"named": false,
"value": "operator"
},
{
"type": "FIELD",
"name": "class_name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "operator",
"content": {
"type": "SYMBOL",
"name": "_overloadable_operator"
}
},
{
"type": "SYMBOL",

View File

@ -1127,6 +1127,10 @@
{
"type": "class_member",
"named": true
},
{
"type": "uses_statement",
"named": true
}
]
}
@ -1230,10 +1234,6 @@
"type": "property_declaration",
"named": true
},
{
"type": "uses_statement",
"named": true
},
{
"type": "variable_declaration",
"named": true
@ -1680,7 +1680,7 @@
"fields": {
"body": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "block_suite",
@ -1690,7 +1690,7 @@
},
"class_name": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "identifier",

File diff suppressed because it is too large Load Diff