Skip to content

Commit

Permalink
fix(language-metavariables/tree-sitter-kotlin): update with 'resource…
Browse files Browse the repository at this point in the history
…s/edit_grammars.mjs' script

fixes getgrit#570
  • Loading branch information
Alex-ley-scrub committed Nov 8, 2024
1 parent cd2fe7d commit 3a706e6
Show file tree
Hide file tree
Showing 23 changed files with 532,515 additions and 520,315 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = [
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">= 0.21, < 0.23"
tree-sitter = "~0.20"

[build-dependencies]
cc = "1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-w")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
#[cfg(target_env = "msvc")]
Expand All @@ -28,7 +28,7 @@ fn main() {
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-w")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
Expand Down
18 changes: 12 additions & 6 deletions resources/language-metavariables/tree-sitter-kotlin/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const PREC = {
ARGUMENTS: 1,
LAMBDA_LITERAL: 0,
RETURN_OR_THROW: 0,
COMMENT: 0
COMMENT: 0,
GRIT_METAVARIABLE: 100,
};
const DEC_DIGITS = token(sep1(/[0-9]+/, /_+/));
const HEX_DIGITS = token(sep1(/[0-9a-fA-F]+/, /_+/));
Expand Down Expand Up @@ -110,6 +111,8 @@ module.exports = grammar({
[$.type_modifiers],
// ambiguity between associating type modifiers
[$.not_nullable_type],
// grit_metavariable conflicts
[$._statement, $._literal_constant],
],

externals: $ => [
Expand Down Expand Up @@ -237,7 +240,7 @@ module.exports = grammar({
$._class_parameters
),

class_body: $ => seq("{", optional($._class_member_declarations), "}"),
class_body: $ => seq("{", optional(choice($._class_member_declarations, $.grit_metavariable)), "}"),

_class_parameters: $ => seq(
"(",
Expand Down Expand Up @@ -444,7 +447,7 @@ module.exports = grammar({
enum_class_body: $ => seq(
"{",
optional($._enum_entries),
optional(seq(";", optional($._class_member_declarations))),
optional(seq(";", optional(choice($._class_member_declarations, $.grit_metavariable)))),
"}"
),

Expand Down Expand Up @@ -553,7 +556,8 @@ module.exports = grammar({
$._loop_statement,
$._expression
)
)
),
$.grit_metavariable,
),

label: $ => token(seq(
Expand Down Expand Up @@ -762,12 +766,13 @@ module.exports = grammar({
$.real_literal,
$.null_literal,
$.long_literal,
$.unsigned_literal
$.unsigned_literal,
$.grit_metavariable,
),

string_literal: $ => seq(
$._string_start,
repeat(choice($.string_content, $._interpolation)),
choice($.grit_metavariable, repeat(choice($.string_content, $._interpolation))),
$._string_end,
),

Expand Down Expand Up @@ -1230,6 +1235,7 @@ module.exports = grammar({

_escaped_identifier: $ => /\\[tbrn'"\\$]/,

grit_metavariable: ($) => token(prec(PREC.GRIT_METAVARIABLE, choice("µ...", /µ[a-zA-Z_][a-zA-Z0-9_]*/))),
}
});

Expand Down
13 changes: 2 additions & 11 deletions resources/language-metavariables/tree-sitter-kotlin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,5 @@
"devDependencies": {
"tree-sitter-cli": "^0.22.6",
"prebuildify": "^6.0.0"
},
"tree-sitter": [
{
"scope": "source.kotlin",
"file-types": [
"kt",
"kts"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "kotlin",
"word": "_alpha_identifier",
"rules": {
Expand Down Expand Up @@ -607,8 +608,17 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_class_member_declarations"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_class_member_declarations"
},
{
"type": "SYMBOL",
"name": "grit_metavariable"
}
]
},
{
"type": "BLANK"
Expand Down Expand Up @@ -2047,8 +2057,17 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_class_member_declarations"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_class_member_declarations"
},
{
"type": "SYMBOL",
"name": "grit_metavariable"
}
]
},
{
"type": "BLANK"
Expand Down Expand Up @@ -2628,6 +2647,10 @@
]
}
]
},
{
"type": "SYMBOL",
"name": "grit_metavariable"
}
]
},
Expand Down Expand Up @@ -3816,6 +3839,10 @@
{
"type": "SYMBOL",
"name": "unsigned_literal"
},
{
"type": "SYMBOL",
"name": "grit_metavariable"
}
]
},
Expand All @@ -3827,20 +3854,29 @@
"name": "_string_start"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_content"
},
{
"type": "SYMBOL",
"name": "_interpolation"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "grit_metavariable"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_content"
},
{
"type": "SYMBOL",
"name": "_interpolation"
}
]
}
]
}
}
]
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -6234,6 +6270,26 @@
"_escaped_identifier": {
"type": "PATTERN",
"value": "\\\\[tbrn'\"\\\\$]"
},
"grit_metavariable": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 100,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "µ..."
},
{
"type": "PATTERN",
"value": "µ[a-zA-Z_][a-zA-Z0-9_]*"
}
]
}
}
}
},
"extras": [
Expand Down Expand Up @@ -6354,6 +6410,10 @@
],
[
"not_nullable_type"
],
[
"_statement",
"_literal_constant"
]
],
"precedences": [],
Expand Down
Loading

0 comments on commit 3a706e6

Please sign in to comment.