Merge commit '399605a02bcd5daa309ce63a6459c600dce3473f'

pull/502/head
Wilfred Hughes 2023-03-16 08:19:45 +07:00
commit b914149ccf
10 changed files with 18078 additions and 10350 deletions

@ -8,7 +8,7 @@ Added support for Ada.
Improved parsing for TOML.
Updated grammars for Bash, C, C++, C# and Clojure.
Updated grammars for Bash, C, C++, C#, Clojure and CMake.
Difftastic now prefers treating files as 'mostly UTF-8' or binary rather than
UTF-16. Many files can be decoded as UTF-16 without decoding errors

@ -127,3 +127,6 @@ scanner.obj
# Rust files
target/**
Cargo.lock
#pnpm
pnpm-lock.yaml

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-cmake"
description = "cmake grammar for the tree-sitter parsing library"
version = "0.1.0"
version = "0.2.0"
keywords = ["incremental", "parsing", "cmake"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/uyha/tree-sitter-cmake"

@ -0,0 +1,140 @@
======================================================
Function definition with no arguments [block_commands]
======================================================
function(fn)
endfunction()
---
(source_file
(function_def
(function_command
(function)
(argument
(unquoted_argument)
)
)
(endfunction_command
(endfunction)
)
)
)
========================================================
Function definition with many arguments [block_commands]
========================================================
function(fn arg1 arg2 arg3)
endfunction()
---
(source_file
(function_def
(function_command
(function)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
)
(endfunction_command
(endfunction)
)
)
)
===================================================
Macro definition with no arguments [block_commands]
===================================================
macro(fn)
endmacro()
---
(source_file
(macro_def
(macro_command
(macro)
(argument
(unquoted_argument)
)
)
(endmacro_command
(endmacro)
)
)
)
========================================================
macro definition with many arguments [block_commands]
========================================================
macro(fn arg1 arg2 arg3)
endmacro()
---
(source_file
(macro_def
(macro_command
(macro)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
)
(endmacro_command
(endmacro)
)
)
)
============================
Block scope [block_commands]
============================
block(SCOPE_FOR POLICIES VARIABLES PROPAGATE var)
endblock()
---
(source_file
(block_def
(block_command
(block)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
(argument
(unquoted_argument)
)
)
(endblock_command
(endblock)
)
)
)

@ -0,0 +1,18 @@
========================================
Escape sequence of "\;" [Escape_sequence]
=========================================
set(var "It is \; and \"")
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument))
(argument
(quoted_argument
(quoted_element
(escape_sequence)
(escape_sequence))))))

@ -11,6 +11,8 @@ commands = [
"endfunction",
"macro",
"endmacro",
"block",
"endblock"
];
module.exports = grammar({
@ -25,7 +27,7 @@ module.exports = grammar({
escape_sequence: ($) => choice($._escape_identity, $._escape_encoded, $._escape_semicolon),
_escape_identity: (_) => /\\[^A-Za-z0-9;]/,
_escape_encoded: (_) => choice("\\t", "\\r", "\\n"),
_escape_semicolon: (_) => ";",
_escape_semicolon: (_) => choice(";","\\;"),
variable: ($) => prec.left(repeat1(choice(/[a-zA-Z0-9/_.+-]/, $.escape_sequence, $.variable_ref))),
variable_ref: ($) => choice($.normal_var, $.env_var, $.cache_var),
@ -75,10 +77,14 @@ module.exports = grammar({
endmacro_command: ($) => command($.endmacro, repeat($._untrimmed_argument)),
macro_def: ($) => seq($.macro_command, repeat($._untrimmed_command_invocation), $.endmacro_command),
block_command: ($) => command($.block, repeat($._untrimmed_argument)),
endblock_command: ($) => command($.endblock, repeat($._untrimmed_argument)),
block_def: ($) => seq($.block_command, repeat($._untrimmed_command_invocation), $.endblock_command),
normal_command: ($) => command($.identifier, repeat($._untrimmed_argument)),
_command_invocation: ($) =>
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def),
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def, $.block_def),
_untrimmed_command_invocation: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $._command_invocation),
...commandNames(...commands),

@ -1,6 +1,6 @@
{
"name": "tree-sitter-cmake",
"version": "0.1.0",
"version": "0.2.0",
"description": "CMake grammar for tree-sitter",
"main": "bindings/node",
"author": "Uy Ha",

@ -47,8 +47,17 @@
]
},
"_escape_semicolon": {
"type": "STRING",
"value": ";"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "STRING",
"value": "\\;"
}
]
},
"variable": {
"type": "PREC_LEFT",
@ -932,6 +941,88 @@
}
]
},
"block_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[\\t ]"
}
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"endblock_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "endblock"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[\\t ]"
}
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"block_def": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "block_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
},
{
"type": "SYMBOL",
"name": "endblock_command"
}
]
},
"normal_command": {
"type": "SEQ",
"members": [
@ -989,6 +1080,10 @@
{
"type": "SYMBOL",
"name": "macro_def"
},
{
"type": "SYMBOL",
"name": "block_def"
}
]
},
@ -1061,6 +1156,14 @@
"type": "PATTERN",
"value": "[eE][nN][dD][mM][aA][cC][rR][oO]"
},
"block": {
"type": "PATTERN",
"value": "[bB][lL][oO][cC][kK]"
},
"endblock": {
"type": "PATTERN",
"value": "[eE][nN][dD][bB][lL][oO][cC][kK]"
},
"identifier": {
"type": "PATTERN",
"value": "[A-Za-z_][A-Za-z0-9_]*"

@ -22,6 +22,88 @@
]
}
},
{
"type": "block_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "block",
"named": true
},
{
"type": "bracket_comment",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
},
{
"type": "block_def",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block_command",
"named": true
},
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
},
{
"type": "endblock_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "line_comment",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
},
{
"type": "cache_var",
"named": true,
@ -91,6 +173,33 @@
]
}
},
{
"type": "endblock_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"named": true
},
{
"type": "endblock",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
},
{
"type": "endforeach_command",
"named": true,
@ -265,6 +374,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -343,6 +456,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -436,6 +553,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -522,6 +643,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -653,6 +778,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -788,6 +917,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"named": true
@ -851,6 +984,10 @@
"type": ":",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<",
"named": false
@ -867,6 +1004,10 @@
"type": "ENV",
"named": false
},
{
"type": "\\;",
"named": false
},
{
"type": "\\n",
"named": false
@ -879,6 +1020,10 @@
"type": "\\t",
"named": false
},
{
"type": "block",
"named": true
},
{
"type": "bracket_argument",
"named": true
@ -895,6 +1040,10 @@
"type": "elseif",
"named": true
},
{
"type": "endblock",
"named": true
},
{
"type": "endforeach",
"named": true

File diff suppressed because it is too large Load Diff