Merge commit '20ffd6d3b4da1acdbf2d08204b2130a5b2f7c4b3'

pull/708/head
Wilfred Hughes 2024-04-28 23:51:13 +07:00
commit 9207220a02
48 changed files with 13611 additions and 18200 deletions

@ -0,0 +1,39 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2
[*.js]
indent_style = space
indent_size = 2
[*.rs]
indent_style = space
indent_size = 4
[*.{c,cc,h}]
indent_style = space
indent_size = 4
[*.{py,pyi}]
indent_style = space
indent_size = 4
[*.swift]
indent_style = space
indent_size = 4
[*.go]
indent_style = tab
indent_size = 8
[Makefile]
indent_style = tab
indent_size = 8

@ -0,0 +1,11 @@
* text eol=lf
src/*.json linguist-generated
src/parser.c linguist-generated
src/tree_sitter/* linguist-generated
bindings/** linguist-generated
binding.gyp linguist-generated
setup.py linguist-generated
Makefile linguist-generated
Package.swift linguist-generated

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-cmake"
description = "cmake grammar for the tree-sitter parsing library"
version = "0.2.0"
version = "0.4.3"
keywords = ["incremental", "parsing", "cmake"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/uyha/tree-sitter-cmake"
@ -20,7 +20,7 @@ include = [
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "~0.20"
tree-sitter = ">=0.22"
[build-dependencies]
cc = "1.0"

@ -0,0 +1,109 @@
VERSION := 0.0.1
LANGUAGE_NAME := tree-sitter-cmake
# repository
SRC_DIR := src
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
ifeq ($(PARSER_URL),)
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
PARSER_URL := $(subst :,/,$(PARSER_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
endif
endif
TS ?= tree-sitter
# ABI versioning
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig
# object files
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c))
# flags
ARFLAGS := rcs
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
# OS-specific bits
ifeq ($(OS),Windows_NT)
$(error "Windows is not supported")
else ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
endif
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
lib$(LANGUAGE_NAME).a: $(OBJS)
$(AR) $(ARFLAGS) $@ $^
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ifneq ($(STRIP),)
$(STRIP) $@
endif
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
sed -e 's|@URL@|$(PARSER_URL)|' \
-e 's|@VERSION@|$(VERSION)|' \
-e 's|@LIBDIR@|$(LIBDIR)|' \
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
-e 's|@REQUIRES@|$(REQUIRES)|' \
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
$(SRC_DIR)/parser.c: grammar.js
$(TS) generate --no-bindings
install: all
install -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -Dm755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
uninstall:
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
clean:
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
test:
$(TS) test
.PHONY: all install uninstall clean test

@ -0,0 +1,48 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterCmake",
platforms: [.macOS(.v10_13), .iOS(.v11)],
products: [
.library(name: "TreeSitterCmake", targets: ["TreeSitterCmake"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterCmake",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
],
cLanguageStandard: .c11
)

@ -1,19 +1,21 @@
{
"targets": [
{
"target_name": "tree_sitter_CMake_binding",
"target_name": "tree_sitter_cmake_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
"src",
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# If your language uses an external scanner, add it here.
# NOTE: if your language has an external scanner, add it here.
],
"cflags_c": [
"-std=c99",
]
"-std=c11",
],
}
]
}

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_CMAKE_H_
#define TREE_SITTER_CMAKE_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
const TSLanguage *tree_sitter_cmake(void);
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_CMAKE_H_

@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
Name: tree-sitter-cmake
Description: Cmake grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-cmake
Cflags: -I${includedir}

@ -0,0 +1,13 @@
package tree_sitter_cmake
// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
import "C"
import "unsafe"
// Get the tree-sitter Language for this grammar.
func Language() unsafe.Pointer {
return unsafe.Pointer(C.tree_sitter_cmake())
}

@ -0,0 +1,15 @@
package tree_sitter_cmake_test
import (
"testing"
tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-cmake"
)
func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_cmake.Language())
if language == nil {
t.Errorf("Error loading Cmake grammar")
}
}

@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-cmake
go 1.22
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8

@ -1,28 +1,20 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
#include <napi.h>
using namespace v8;
typedef struct TSLanguage TSLanguage;
extern "C" TSLanguage * tree_sitter_cmake();
extern "C" TSLanguage *tree_sitter_cmake();
namespace {
// "tree-sitter", "language" hashed with BLAKE2
const napi_type_tag LANGUAGE_TYPE_TAG = {
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
};
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cmake());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("cmake").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports["name"] = Napi::String::New(env, "cmake");
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_cmake());
language.TypeTag(&LANGUAGE_TYPE_TAG);
exports["language"] = language;
return exports;
}
NODE_MODULE(tree_sitter_cmake_binding, Init)
} // namespace
NODE_API_MODULE(tree_sitter_cmake_binding, Init)

@ -0,0 +1,28 @@
type BaseNode = {
type: string;
named: boolean;
};
type ChildNode = {
multiple: boolean;
required: boolean;
types: BaseNode[];
};
type NodeInfo =
| (BaseNode & {
subtypes: BaseNode[];
})
| (BaseNode & {
fields: { [name: string]: ChildNode };
children: ChildNode[];
});
type Language = {
name: string;
language: unknown;
nodeTypeInfo: NodeInfo[];
};
declare const language: Language;
export = language;

@ -1,18 +1,6 @@
try {
module.exports = require("../../build/Release/tree_sitter_cmake_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_cmake_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
const root = require("path").join(__dirname, "..", "..");
module.exports = require("node-gyp-build")(root);
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");

@ -0,0 +1,5 @@
"Cmake grammar for tree-sitter"
from ._binding import language
__all__ = ["language"]

@ -0,0 +1,27 @@
#include <Python.h>
typedef struct TSLanguage TSLanguage;
TSLanguage *tree_sitter_cmake(void);
static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_cmake());
}
static PyMethodDef methods[] = {
{"language", _binding_language, METH_NOARGS,
"Get the tree-sitter language for this grammar."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding",
.m_doc = NULL,
.m_size = -1,
.m_methods = methods
};
PyMODINIT_FUNC PyInit__binding(void) {
return PyModule_Create(&module);
}

@ -10,29 +10,10 @@ fn main() {
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
// If your language uses an external scanner written in C,
// then include this block of code:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
}

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_CMAKE_H_
#define TREE_SITTER_CMAKE_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
const TSLanguage *tree_sitter_cmake(void);
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_CMAKE_H_

@ -1,140 +0,0 @@
======================================================
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)
)
)
)

@ -1,147 +0,0 @@
====================
Empty if [condition]
====================
if ( cond )
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
)
(endif_command (endif))
)
)
===========================
Empty if elseif [condition]
===========================
if(cond)
elseif(cond)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
)
(elseif_command
(elseif)
(argument (unquoted_argument))
)
(endif_command (endif))
)
)
================================
Empty if elseif else [condition]
================================
if(cond)
elseif(cond)
else()
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
)
(elseif_command
(elseif)
(argument (unquoted_argument))
)
(else_command (else))
(endif_command (endif))
)
)
==========================================
If with one command invocation [condition]
==========================================
if(cond)
message(STATUS)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
)
(normal_command
(identifier)
(argument (unquoted_argument))
)
(endif_command (endif))
)
)
======================================
Condition with parentheses [condition]
======================================
if((A AND B) OR C)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(endif_command (endif))
)
)
==============================================
Condition with not and parentheses [condition]
==============================================
if(NOT (A AND B) OR C)
else(NOT (A AND B) OR C)
endif(NOT (A AND B) OR C)
---
(source_file
(if_condition
(if_command
(if)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(else_command
(else)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(endif_command
(endif)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)

@ -1,18 +0,0 @@
========================================
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))))))

@ -1,117 +0,0 @@
==================================
Empty foreach loop [foreach]
==================================
foreach(var)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)
===============================================================
Empty foreach loop with one argument endforeach [foreach]
===============================================================
foreach(var)
endforeach(var)
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command
(endforeach)
(argument (unquoted_argument))
)
))
=================================
Uppercase foreach [foreach]
=================================
FOREACH(var)
ENDFOREACH()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)
==================================
Mixed case foreach [foreach]
==================================
forEach(var)
endForEach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)
==================================
Empty IN [foreach]
==================================
foreach(var IN)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)
==================================
Empty RANGE [foreach]
==================================
foreach(var RANGE)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)

@ -12,7 +12,7 @@ commands = [
"macro",
"endmacro",
"block",
"endblock"
"endblock",
];
module.exports = grammar({
@ -27,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: (_) => choice(";","\\;"),
_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),
@ -45,43 +45,42 @@ module.exports = grammar({
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
quoted_element: ($) => repeat1(choice($.variable_ref, $.gen_exp, $._quoted_text, $.escape_sequence)),
_quoted_text: ($) => prec.left(repeat1(choice('$', /[^\\"]/))),
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, $.gen_exp, $._unquoted_text, $.escape_sequence))),
_unquoted_text: ($) => prec.left(repeat1(choice('$', /[^()#"\\']/))),
if_command: ($) => command($.if, repeat($._untrimmed_argument)),
elseif_command: ($) => command($.elseif, repeat($._untrimmed_argument)),
else_command: ($) => command($.else, repeat($._untrimmed_argument)),
endif_command: ($) => command($.endif, repeat($._untrimmed_argument)),
if_condition: ($) =>
seq(
$.if_command,
repeat(choice($._untrimmed_command_invocation, $.elseif_command, $.else_command)),
$.endif_command
),
foreach_command: ($) => command($.foreach, repeat($._untrimmed_argument)),
_quoted_text: (_) => prec.left(repeat1(choice("$", /[^\\"]/))),
unquoted_argument: ($) =>
prec.right(repeat1(choice($.variable_ref, $.gen_exp, $._unquoted_text, $.escape_sequence))),
_unquoted_text: (_) => prec.left(repeat1(choice("$", /[^()#"\\]/))),
body: ($) => prec.right(repeat1($._untrimmed_command_invocation)),
argument_list: ($) => repeat1($._untrimmed_argument),
if_command: ($) => command($.if, $.argument_list),
elseif_command: ($) => command($.elseif, $.argument_list),
else_command: ($) => command($.else, optional($.argument_list)),
endif_command: ($) => command($.endif, optional($.argument_list)),
if_condition: ($) => seq($.if_command, repeat(choice($.body, $.elseif_command, $.else_command)), $.endif_command),
foreach_command: ($) => command($.foreach, $.argument_list),
endforeach_command: ($) => command($.endforeach, optional($.argument)),
foreach_loop: ($) => seq($.foreach_command, repeat($._untrimmed_command_invocation), $.endforeach_command),
foreach_loop: ($) => seq($.foreach_command, $.body, $.endforeach_command),
while_command: ($) => command($.while, repeat($._untrimmed_argument)),
while_command: ($) => command($.while, $.argument_list),
endwhile_command: ($) => command($.endwhile, optional(seq(/\s*/, $.argument, /\s*/))),
while_loop: ($) => seq($.while_command, repeat($._untrimmed_command_invocation), $.endwhile_command),
while_loop: ($) => seq($.while_command, $.body, $.endwhile_command),
function_command: ($) => command($.function, repeat($._untrimmed_argument)),
endfunction_command: ($) => command($.endfunction, repeat($._untrimmed_argument)),
function_def: ($) => seq($.function_command, repeat($._untrimmed_command_invocation), $.endfunction_command),
function_command: ($) => command($.function, $.argument_list),
endfunction_command: ($) => command($.endfunction, optional($.argument_list)),
function_def: ($) => seq($.function_command, $.body, $.endfunction_command),
macro_command: ($) => command($.macro, repeat($._untrimmed_argument)),
endmacro_command: ($) => command($.endmacro, repeat($._untrimmed_argument)),
macro_def: ($) => seq($.macro_command, repeat($._untrimmed_command_invocation), $.endmacro_command),
macro_command: ($) => command($.macro, $.argument_list),
endmacro_command: ($) => command($.endmacro, optional($.argument_list)),
macro_def: ($) => seq($.macro_command, $.body, $.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),
block_command: ($) => command($.block, $.argument_list),
endblock_command: ($) => command($.endblock, optional($.argument_list)),
block_def: ($) => seq($.block_command, $.body, $.endblock_command),
normal_command: ($) => command($.identifier, repeat($._untrimmed_argument)),
normal_command: ($) => command($.identifier, optional($.argument_list)),
_command_invocation: ($) =>
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def, $.block_def),

@ -1,12 +1,22 @@
{
"name": "tree-sitter-cmake",
"version": "0.2.0",
"version": "0.4.3",
"description": "CMake grammar for tree-sitter",
"main": "bindings/node",
"types": "bindings/node",
"author": "Uy Ha",
"license": "MIT",
"dependencies": {
"nan": "^2.16.0"
"node-addon-api": "^7.1.0",
"node-gyp-build": "^4.8.0"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
},
"peerDependenciesMeta": {
"tree_sitter": {
"optional": true
}
},
"tree-sitter": [
{
@ -18,6 +28,19 @@
}
],
"devDependencies": {
"tree-sitter-cli": "^0.20.6"
}
"tree-sitter-cli": "^0.21.0",
"prebuildify": "^6.0.0"
},
"scripts": {
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip"
},
"files": [
"grammar.js",
"binding.gyp",
"prebuilds/**",
"bindings/node/*",
"queries/*",
"src/**"
]
}

@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "tree-sitter-cmake"
description = "Cmake grammar for tree-sitter"
version = "0.0.1"
keywords = ["incremental", "parsing", "tree-sitter", "cmake"]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Compilers",
"Topic :: Text Processing :: Linguistic",
"Typing :: Typed"
]
requires-python = ">=3.8"
license.text = "MIT"
readme = "README.md"
[project.urls]
Homepage = "https://github.com/tree-sitter/tree-sitter-cmake"
[project.optional-dependencies]
core = ["tree-sitter~=0.21"]
[tool.cibuildwheel]
build = "cp38-*"
build-frontend = "build"

@ -0,0 +1,57 @@
from os.path import isdir, join
from platform import system
from setuptools import Extension, find_packages, setup
from setuptools.command.build import build
from wheel.bdist_wheel import bdist_wheel
class Build(build):
def run(self):
if isdir("queries"):
dest = join(self.build_lib, "tree_sitter_cmake", "queries")
self.copy_tree("queries", dest)
super().run()
class BdistWheel(bdist_wheel):
def get_tag(self):
python, abi, platform = super().get_tag()
if python.startswith("cp"):
python, abi = "cp38", "abi3"
return python, abi, platform
setup(
packages=find_packages("bindings/python"),
package_dir={"": "bindings/python"},
package_data={
"tree_sitter_cmake": ["*.pyi", "py.typed"],
"tree_sitter_cmake.queries": ["*.scm"],
},
ext_package="tree_sitter_cmake",
ext_modules=[
Extension(
name="_binding",
sources=[
"bindings/python/tree_sitter_cmake/binding.c",
"src/parser.c",
# NOTE: if your language uses an external scanner, add it here.
],
extra_compile_args=(
["-std=c11"] if system() != 'Windows' else []
),
define_macros=[
("Py_LIMITED_API", "0x03080000"),
("PY_SSIZE_T_CLEAN", None)
],
include_dirs=["src"],
py_limited_api=True,
)
],
cmdclass={
"build": Build,
"bdist_wheel": BdistWheel
},
zip_safe=False
)

@ -427,12 +427,30 @@
},
{
"type": "PATTERN",
"value": "[^()#\"\\\\']"
"value": "[^()#\"\\\\]"
}
]
}
}
},
"body": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
}
},
"argument_list": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
},
"if_command": {
"type": "SEQ",
"members": [
@ -452,11 +470,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -483,11 +498,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -514,11 +526,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -545,11 +562,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -571,7 +593,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
"name": "body"
},
{
"type": "SYMBOL",
@ -609,11 +631,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -665,11 +684,8 @@
"name": "foreach_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
"type": "SYMBOL",
"name": "body"
},
{
"type": "SYMBOL",
@ -696,11 +712,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -765,11 +778,8 @@
"name": "while_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
"type": "SYMBOL",
"name": "body"
},
{
"type": "SYMBOL",
@ -796,11 +806,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -827,11 +834,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -847,11 +859,8 @@
"name": "function_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
"type": "SYMBOL",
"name": "body"
},
{
"type": "SYMBOL",
@ -878,11 +887,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -909,11 +915,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -929,11 +940,8 @@
"name": "macro_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
"type": "SYMBOL",
"name": "body"
},
{
"type": "SYMBOL",
@ -960,11 +968,8 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "STRING",
@ -991,11 +996,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -1011,11 +1021,8 @@
"name": "block_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_command_invocation"
}
"type": "SYMBOL",
"name": "body"
},
{
"type": "SYMBOL",
@ -1042,11 +1049,16 @@
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_untrimmed_argument"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument_list"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -1193,4 +1205,3 @@
"inline": [],
"supertypes": []
}

@ -23,27 +23,42 @@
}
},
{
"type": "block_command",
"type": "argument_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "block",
"type": "bracket_comment",
"named": true
},
{
"type": "bracket_comment",
"type": "line_comment",
"named": true
}
]
}
},
{
"type": "block_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument_list",
"named": true
},
{
"type": "line_comment",
"type": "block",
"named": true
}
]
@ -62,15 +77,30 @@
"named": true
},
{
"type": "block_def",
"type": "body",
"named": true
},
{
"type": "bracket_comment",
"type": "endblock_command",
"named": true
}
]
}
},
{
"type": "body",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "endblock_command",
"type": "bracket_comment",
"named": true
},
{
@ -128,20 +158,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "else",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -155,20 +177,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "elseif",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -182,20 +196,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "endblock",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -228,20 +234,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "endfunction",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -255,20 +253,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "endif",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -282,20 +272,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "endmacro",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -348,20 +330,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "foreach",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -375,11 +349,7 @@
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"type": "body",
"named": true
},
{
@ -389,34 +359,6 @@
{
"type": "foreach_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
}
]
}
@ -430,20 +372,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "function",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -457,48 +391,16 @@
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"type": "body",
"named": true
},
{
"type": "endfunction_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "function_command",
"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
}
]
}
@ -527,20 +429,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -554,11 +448,7 @@
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"type": "body",
"named": true
},
{
@ -573,37 +463,9 @@
"type": "endif_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_command",
"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
}
]
}
@ -617,15 +479,7 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"named": true
},
{
"type": "line_comment",
"type": "argument_list",
"named": true
},
{
@ -644,48 +498,16 @@
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"type": "body",
"named": true
},
{
"type": "endmacro_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_command",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
@ -699,20 +521,12 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"type": "argument_list",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "line_comment",
"named": true
}
]
}
@ -891,15 +705,7 @@
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "bracket_comment",
"named": true
},
{
"type": "line_comment",
"type": "argument_list",
"named": true
},
{
@ -918,48 +724,16 @@
"required": true,
"types": [
{
"type": "block_def",
"named": true
},
{
"type": "bracket_comment",
"type": "body",
"named": true
},
{
"type": "endwhile_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_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}

File diff suppressed because it is too large Load Diff

@ -1,16 +1,19 @@
#include <cwctype>
#include <tree_sitter/parser.h>
#include <wctype.h>
namespace {
enum TokenType { BRACKET_ARGUMENT, BRACKET_COMMENT, LINE_COMMENT };
void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
void skip_wspace(TSLexer *lexer) {
while (std::iswspace(lexer->lookahead)) {
static void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
static void skip_wspace(TSLexer *lexer) {
while (iswspace(lexer->lookahead)) {
skip(lexer);
}
}
bool is_bracket_argument(TSLexer *lexer) {
static bool is_bracket_argument(TSLexer *lexer) {
if (lexer->lookahead != '[') {
return false;
}
@ -45,7 +48,8 @@ bool is_bracket_argument(TSLexer *lexer) {
}
return false;
}
bool scan(void *payload, TSLexer *lexer, bool const *valid_symbols) {
static bool scan(void *payload, TSLexer *lexer, bool const *valid_symbols) {
skip_wspace(lexer);
if (lexer->lookahead != '#' && valid_symbols[BRACKET_ARGUMENT]) {
@ -72,19 +76,20 @@ bool scan(void *payload, TSLexer *lexer, bool const *valid_symbols) {
return false;
}
} // namespace
extern "C" {
void *tree_sitter_cmake_external_scanner_create() { return NULL; }
void tree_sitter_cmake_external_scanner_destroy(void *payload) {}
unsigned tree_sitter_cmake_external_scanner_serialize(void *payload,
char *buffer) {
return 0;
}
void tree_sitter_cmake_external_scanner_deserialize(void *payload,
char const *buffer,
unsigned length) {}
bool tree_sitter_cmake_external_scanner_scan(void *payload, TSLexer *lexer,
bool const *valid_symbols) {
return scan(payload, lexer, valid_symbols);
}
}

@ -0,0 +1,54 @@
#ifndef TREE_SITTER_ALLOC_H_
#define TREE_SITTER_ALLOC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
// Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR
extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);
#ifndef ts_malloc
#define ts_malloc ts_current_malloc
#endif
#ifndef ts_calloc
#define ts_calloc ts_current_calloc
#endif
#ifndef ts_realloc
#define ts_realloc ts_current_realloc
#endif
#ifndef ts_free
#define ts_free ts_current_free
#endif
#else
#ifndef ts_malloc
#define ts_malloc malloc
#endif
#ifndef ts_calloc
#define ts_calloc calloc
#endif
#ifndef ts_realloc
#define ts_realloc realloc
#endif
#ifndef ts_free
#define ts_free free
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_ALLOC_H_

@ -0,0 +1,290 @@
#ifndef TREE_SITTER_ARRAY_H_
#define TREE_SITTER_ARRAY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "./alloc.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#pragma warning(disable : 4101)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#define Array(T) \
struct { \
T *contents; \
uint32_t size; \
uint32_t capacity; \
}
/// Initialize an array.
#define array_init(self) \
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
/// Create an empty array.
#define array_new() \
{ NULL, 0, 0 }
/// Get a pointer to the element at a given `index` in the array.
#define array_get(self, _index) \
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
/// Get a pointer to the first element in the array.
#define array_front(self) array_get(self, 0)
/// Get a pointer to the last element in the array.
#define array_back(self) array_get(self, (self)->size - 1)
/// Clear the array, setting its size to zero. Note that this does not free any
/// memory allocated for the array's contents.
#define array_clear(self) ((self)->size = 0)
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
/// less than the array's current capacity, this function has no effect.
#define array_reserve(self, new_capacity) \
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
/// Free any memory allocated for this array. Note that this does not free any
/// memory allocated for the array's contents.
#define array_delete(self) _array__delete((Array *)(self))
/// Push a new `element` onto the end of the array.
#define array_push(self, element) \
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
(self)->contents[(self)->size++] = (element))
/// Increase the array's size by `count` elements.
/// New elements are zero-initialized.
#define array_grow_by(self, count) \
do { \
if ((count) == 0) break; \
_array__grow((Array *)(self), count, array_elem_size(self)); \
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
(self)->size += (count); \
} while (0)
/// Append all elements from one array to the end of another.
#define array_push_all(self, other) \
array_extend((self), (other)->size, (other)->contents)
/// Append `count` elements to the end of the array, reading their values from the
/// `contents` pointer.
#define array_extend(self, count, contents) \
_array__splice( \
(Array *)(self), array_elem_size(self), (self)->size, \
0, count, contents \
)
/// Remove `old_count` elements from the array starting at the given `index`. At
/// the same index, insert `new_count` new elements, reading their values from the
/// `new_contents` pointer.
#define array_splice(self, _index, old_count, new_count, new_contents) \
_array__splice( \
(Array *)(self), array_elem_size(self), _index, \
old_count, new_count, new_contents \
)
/// Insert one `element` into the array at the given `index`.
#define array_insert(self, _index, element) \
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
/// Remove one element from the array at the given `index`.
#define array_erase(self, _index) \
_array__erase((Array *)(self), array_elem_size(self), _index)
/// Pop the last element off the array, returning the element by value.
#define array_pop(self) ((self)->contents[--(self)->size])
/// Assign the contents of one array to another, reallocating if necessary.
#define array_assign(self, other) \
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
/// Swap one array with another
#define array_swap(self, other) \
_array__swap((Array *)(self), (Array *)(other))
/// Get the size of the array contents
#define array_elem_size(self) (sizeof *(self)->contents)
/// Search a sorted array for a given `needle` value, using the given `compare`
/// callback to determine the order.
///
/// If an existing element is found to be equal to `needle`, then the `index`
/// out-parameter is set to the existing value's index, and the `exists`
/// out-parameter is set to true. Otherwise, `index` is set to an index where
/// `needle` should be inserted in order to preserve the sorting, and `exists`
/// is set to false.
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
/// Search a sorted array for a given `needle` value, using integer comparisons
/// of a given struct field (specified with a leading dot) to determine the order.
///
/// See also `array_search_sorted_with`.
#define array_search_sorted_by(self, field, needle, _index, _exists) \
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
/// Insert a given `value` into a sorted array, using the given `compare`
/// callback to determine the order.
#define array_insert_sorted_with(self, compare, value) \
do { \
unsigned _index, _exists; \
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
if (!_exists) array_insert(self, _index, value); \
} while (0)
/// Insert a given `value` into a sorted array, using integer comparisons of
/// a given struct field (specified with a leading dot) to determine the order.
///
/// See also `array_search_sorted_by`.
#define array_insert_sorted_by(self, field, value) \
do { \
unsigned _index, _exists; \
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
if (!_exists) array_insert(self, _index, value); \
} while (0)
// Private
typedef Array(void) Array;
/// This is not what you're looking for, see `array_delete`.
static inline void _array__delete(Array *self) {
if (self->contents) {
ts_free(self->contents);
self->contents = NULL;
self->size = 0;
self->capacity = 0;
}
}
/// This is not what you're looking for, see `array_erase`.
static inline void _array__erase(Array *self, size_t element_size,
uint32_t index) {
assert(index < self->size);
char *contents = (char *)self->contents;
memmove(contents + index * element_size, contents + (index + 1) * element_size,
(self->size - index - 1) * element_size);
self->size--;
}
/// This is not what you're looking for, see `array_reserve`.
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
if (new_capacity > self->capacity) {
if (self->contents) {
self->contents = ts_realloc(self->contents, new_capacity * element_size);
} else {
self->contents = ts_malloc(new_capacity * element_size);
}
self->capacity = new_capacity;
}
}
/// This is not what you're looking for, see `array_assign`.
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
_array__reserve(self, element_size, other->size);
self->size = other->size;
memcpy(self->contents, other->contents, self->size * element_size);
}
/// This is not what you're looking for, see `array_swap`.
static inline void _array__swap(Array *self, Array *other) {
Array swap = *other;
*other = *self;
*self = swap;
}
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
uint32_t new_size = self->size + count;
if (new_size > self->capacity) {
uint32_t new_capacity = self->capacity * 2;
if (new_capacity < 8) new_capacity = 8;
if (new_capacity < new_size) new_capacity = new_size;
_array__reserve(self, element_size, new_capacity);
}
}
/// This is not what you're looking for, see `array_splice`.
static inline void _array__splice(Array *self, size_t element_size,
uint32_t index, uint32_t old_count,
uint32_t new_count, const void *elements) {
uint32_t new_size = self->size + new_count - old_count;
uint32_t old_end = index + old_count;
uint32_t new_end = index + new_count;
assert(old_end <= self->size);
_array__reserve(self, element_size, new_size);
char *contents = (char *)self->contents;
if (self->size > old_end) {
memmove(
contents + new_end * element_size,
contents + old_end * element_size,
(self->size - old_end) * element_size
);
}
if (new_count > 0) {
if (elements) {
memcpy(
(contents + index * element_size),
elements,
new_count * element_size
);
} else {
memset(
(contents + index * element_size),
0,
new_count * element_size
);
}
}
self->size += new_count - old_count;
}
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
do { \
*(_index) = start; \
*(_exists) = false; \
uint32_t size = (self)->size - *(_index); \
if (size == 0) break; \
int comparison; \
while (size > 1) { \
uint32_t half_size = size / 2; \
uint32_t mid_index = *(_index) + half_size; \
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
if (comparison <= 0) *(_index) = mid_index; \
size -= half_size; \
} \
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
if (comparison == 0) *(_exists) = true; \
else if (comparison < 0) *(_index) += 1; \
} while (0)
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
/// parameter by reference in order to work with the generic sorting function above.
#define _compare_int(a, b) ((int)*(a) - (int)(b))
#ifdef _MSC_VER
#pragma warning(default : 4101)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_ARRAY_H_

@ -13,9 +13,8 @@ extern "C" {
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSStateId;
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
@ -130,9 +129,16 @@ struct TSLanguage {
* Lexer Macros
*/
#ifdef _MSC_VER
#define UNUSED __pragma(warning(suppress : 4101))
#else
#define UNUSED __attribute__((unused))
#endif
#define START_LEXER() \
bool result = false; \
bool skip = false; \
UNUSED \
bool eof = false; \
int32_t lookahead; \
goto start; \
@ -166,7 +172,7 @@ struct TSLanguage {
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
#define STATE(id) id
@ -176,7 +182,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
.state = (state_value) \
} \
}}
@ -184,7 +190,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.state = (state_value), \
.repetition = true \
} \
}}

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

@ -8,7 +8,9 @@ message([[]])
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
)
)
)
@ -22,7 +24,9 @@ message([[an argument]])
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
)
)
)
@ -36,8 +40,10 @@ message([[first argument]] [[second argument]])
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
(argument (bracket_argument))
)
)
)
@ -54,8 +60,10 @@ message(
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
(argument (bracket_argument))
)
)
)
@ -71,7 +79,9 @@ with line break
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
)
)
)
@ -87,7 +97,9 @@ with line break ]==]
(source_file
(normal_command
(identifier)
(argument (bracket_argument))
(argument_list
(argument (bracket_argument))
)
)
)

@ -19,10 +19,12 @@ message(STATUS #[[Some comment]] "comment is next" #[[Some comment]])
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(bracket_comment)
(argument (quoted_argument (quoted_element)))
(bracket_comment)
(argument_list
(argument (unquoted_argument))
(bracket_comment)
(argument (quoted_argument (quoted_element)))
(bracket_comment)
)
)
)
@ -50,9 +52,11 @@ Second #Some other line comment
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(line_comment)
(argument (unquoted_argument))
(line_comment)
(argument_list
(argument (unquoted_argument))
(line_comment)
(argument (unquoted_argument))
(line_comment)
)
)
)

@ -0,0 +1,304 @@
====================
Empty if [condition]
====================
if ( cond )
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endif_command (endif))
)
)
===========================
Empty if elseif [condition]
===========================
if(cond)
elseif(cond)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(elseif_command
(elseif)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endif_command (endif))
)
)
================================
Empty if elseif else [condition]
================================
if(cond)
elseif(cond)
else()
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(elseif_command
(elseif)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(else_command (else))
(body)
(endif_command (endif))
)
)
============================================
If with many command invocations [condition]
============================================
if(cond)
message(STATUS)
message(STATUS)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
(endif_command (endif))
)
)
==============================================================
If, elseof, and else with many command invocations [condition]
==============================================================
if(cond)
message(STATUS)
message(STATUS)
elseif(cond)
message(STATUS)
message(STATUS)
else(cond)
message(STATUS)
message(STATUS)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
(elseif_command
(elseif)
(argument_list
(argument (unquoted_argument))
)
)
(body
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
(else_command
(else)
(argument_list
(argument (unquoted_argument))
)
)
(body
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
(endif_command (endif))
)
)
======================================
Condition with parentheses [condition]
======================================
if((A AND B) OR C)
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(body)
(endif_command (endif))
)
)
==============================================
Condition with not and parentheses [condition]
==============================================
if(NOT (A AND B) OR C)
else(NOT (A AND B) OR C)
endif(NOT (A AND B) OR C)
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(body)
(else_command
(else)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(body)
(endif_command
(endif)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)
)
============================
Nested condition [condition]
============================
if(A)
if(A)
endif()
endif()
---
(source_file
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body
(if_condition
(if_command
(if)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endif_command (endif))
)
)
(endif_command (endif))
)
)

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

@ -0,0 +1,136 @@
==================================
Empty foreach loop [foreach]
==================================
foreach(var)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endforeach_command (endforeach))
)
)
===============================================================
Empty foreach loop with one argument endforeach [foreach]
===============================================================
foreach(var)
endforeach(var)
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endforeach_command
(endforeach)
(argument (unquoted_argument))
)
)
)
=================================
Uppercase foreach [foreach]
=================================
FOREACH(var)
ENDFOREACH()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endforeach_command (endforeach))
)
)
==================================
Mixed case foreach [foreach]
==================================
forEach(var)
endForEach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endforeach_command (endforeach))
)
)
==================================
Empty IN [foreach]
==================================
foreach(var IN)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(body)
(endforeach_command (endforeach))
)
)
==================================
Empty RANGE [foreach]
==================================
foreach(var RANGE)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(body)
(endforeach_command (endforeach))
)
)

@ -7,12 +7,14 @@ add_custom_target(OUTPUT somefile)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)
================================================
add_custom_target with new line [function_calls]
@ -24,9 +26,11 @@ add_custom_target(
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)

@ -8,9 +8,15 @@ message($<>)
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(gen_exp)))))
(argument_list
(argument
(unquoted_argument
(gen_exp)
)
)
)
)
)
=====================================
Quoted generator expression [gen_exp]
@ -22,10 +28,17 @@ message("$<>")
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(argument_list
(argument
(quoted_argument
(quoted_element
(gen_exp))))))
(gen_exp)
)
)
)
)
)
)
=====================
No argument [gen_exp]
@ -37,11 +50,19 @@ message($<ANGLE-R>)
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(argument_list
(argument
(unquoted_argument
(gen_exp
(argument
(unquoted_argument)))))))
(unquoted_argument)
)
)
)
)
)
)
)
============================================
No argument with superfluous colon [gen_exp]
@ -53,11 +74,19 @@ message($<ANGLE-R:>)
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(gen_exp
(argument
(unquoted_argument)))))))
(argument_list
(argument
(unquoted_argument
(gen_exp
(argument
(unquoted_argument)
)
)
)
)
)
)
)
======================
One argument [gen_exp]
@ -69,13 +98,21 @@ message($<BOOL:-NOTFOUND>)
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(argument_list
(argument
(unquoted_argument
(gen_exp
(argument
(unquoted_argument))
(unquoted_argument))
(argument
(unquoted_argument)))))))
(unquoted_argument)
)
)
)
)
)
)
)
=======================
Two arguments [gen_exp]
@ -87,12 +124,20 @@ message($<AND:TRUE,FALSE>)
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(gen_exp
(argument
(argument_list
(argument
(unquoted_argument
(gen_exp
(argument
(unquoted_argument))
(argument
(argument
(unquoted_argument))
(argument
(unquoted_argument)))))))
(argument
(unquoted_argument)
)
)
)
)
)
)
)

@ -7,10 +7,10 @@ message()
---
(source_file
(normal_command
(identifier)
)
)
(normal_command
(identifier)
)
)
=================================
No argument with spaces [message]
@ -21,10 +21,11 @@ message( )
---
(source_file
(normal_command
(identifier)
)
)
(normal_command
(identifier)
(argument_list)
)
)
===============================================
Message without argument with newline [message]
@ -37,10 +38,11 @@ message(
---
(source_file
(normal_command
(identifier)
)
)
(normal_command
(identifier)
(argument_list)
)
)
==================================================
Message with STATUS and bracket argument [message]
@ -53,8 +55,10 @@ message(STATUS [=[Some argument ]==] ]=] )
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (bracket_argument))
(argument_list
(argument (unquoted_argument))
(argument (bracket_argument))
)
)
)
@ -69,12 +73,14 @@ message(STATUS
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (bracket_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
(argument (bracket_argument))
)
)
)
======================================================
Message with STATUS and an unquoted argument [message]
@ -87,7 +93,9 @@ message(STATUS argument)
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)

@ -6,8 +6,10 @@ message(STATUS (TEST))
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)
@ -19,8 +21,11 @@ message(STATUS (TEST)
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument)) (MISSING ")")
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(MISSING ")")
)
)
@ -32,8 +37,11 @@ message(STATUS ((TEST))
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument)) (MISSING ")")
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
(MISSING ")")
)
)
@ -45,8 +53,10 @@ message(STATUS (TEST SECOND_TEST))
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)

@ -6,11 +6,13 @@ message("")
---
(source_file
(normal_command
(identifier)
(argument (quoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (quoted_argument))
)
)
)
=====================================
One quoted argument [quoted_argument]
@ -20,11 +22,13 @@ message("An argument")
---
(source_file
(normal_command
(identifier)
(argument (quoted_argument (quoted_element)))
)
)
(normal_command
(identifier)
(argument_list
(argument (quoted_argument (quoted_element)))
)
)
)
======================================
Two quoted arguments [quoted_argument]
@ -34,12 +38,14 @@ message("First argument" "Second argument")
---
(source_file
(normal_command
(identifier)
(argument (quoted_argument (quoted_element)))
(argument (quoted_argument (quoted_element)))
)
)
(normal_command
(identifier)
(argument_list
(argument (quoted_argument (quoted_element)))
(argument (quoted_argument (quoted_element)))
)
)
)
===================================================
A quoted argument with line break [quoted_argument]
@ -50,11 +56,13 @@ with line break")
---
(source_file
(normal_command
(identifier)
(argument (quoted_argument (quoted_element)))
)
)
(normal_command
(identifier)
(argument_list
(argument (quoted_argument (quoted_element)))
)
)
)
========================================
One variable reference [quoted_argument]
@ -64,17 +72,19 @@ message("${var}")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable)))
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable)))
)
)
)
)
)
)
)
)
)
=========================================
Two Variable references [quoted_argument]
@ -84,18 +94,20 @@ message("${var} ${var}")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable)))
(variable_ref (normal_var (variable)))
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable)))
(variable_ref (normal_var (variable)))
)
)
)
)
)
)
)
)
)
======================================================================
Variable reference inside another variable reference [quoted_argument]
@ -105,17 +117,19 @@ message("${var_${var}}")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)
)
)
)
)
)
======================================================================
Lookalike bracket comment inside quoted argument [quoted_argument]
@ -125,17 +139,19 @@ message("${var_${var}} #[[comment]]")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)
)
)
)
)
)
======================================================================
Lookalike line comment inside quoted argument [quoted_argument]
@ -145,17 +161,19 @@ message("${var_${var}} #comment")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)
)
)
)
)
)
===========================================================
Lookalike variable inside quoted argument [quoted_argument]
@ -165,12 +183,14 @@ message("$var")
---
(source_file
(normal_command
(identifier)
(argument
(quoted_argument
(quoted_element)
)
(normal_command
(identifier)
(argument_list
(argument
(quoted_argument
(quoted_element)
)
)
)
)
)
)
)

@ -7,11 +7,13 @@ message(STATUS)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
=========================================================
Command invocation with two arguments [unquoted_argument]
@ -22,12 +24,14 @@ message(STATUS Hello)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
(argument (unquoted_argument))
)
)
)
===============================================================
Command invocations with leading seperation [unquoted_argument]
@ -39,15 +43,20 @@ STATUS)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
)
(normal_command
(identifier)
(argument (unquoted_argument))
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
============================================================
Command invocations with escape sequence [unquoted_argument]
============================================================
@ -58,15 +67,19 @@ STATUS)
---
(source_file
(normal_command
(identifier)
(argument (unquoted_argument))
)
(normal_command
(identifier)
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
(normal_command
(identifier)
(argument_list
(argument (unquoted_argument))
)
)
)
========================================
Variable referencing [unquoted_argument]
@ -75,15 +88,17 @@ message(${var_ref})
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(variable_ref (normal_var (variable)))
)
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument
(variable_ref (normal_var (variable)))
)
)
)
)
)
)
)
====================================================================
Variable referencing inside variable referencing [unquoted_argument]
@ -92,15 +107,17 @@ message(${var_${var_ref}})
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument
(variable_ref (normal_var (variable (variable_ref (normal_var (variable))))))
)
)
)
)
)
)
)
===============================================================
Lookalike variable inside unquoted argument [unquoted_argument]
@ -110,10 +127,30 @@ message($var)
---
(source_file
(normal_command
(identifier)
(argument
(unquoted_argument)
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument)
)
)
)
)
=====================================================
Single quote in unquoted_argument [unquoted_argument]
=====================================================
message(hello'world)
---
(source_file
(normal_command
(identifier)
(argument_list
(argument
(unquoted_argument)
)
)
)
)
)

@ -11,8 +11,11 @@ endwhile()
(while_loop
(while_command
(while)
(argument (unquoted_argument))
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endwhile_command (endwhile))
)
)
@ -30,8 +33,11 @@ endwhile(cond)
(while_loop
(while_command
(while)
(argument (unquoted_argument))
(argument_list
(argument (unquoted_argument))
)
)
(body)
(endwhile_command
(endwhile)
(argument (unquoted_argument))