Compare commits
20 commits
295e3956a3
...
629a7cd5a7
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 629a7cd5a7 | ||
Bruno BELANYI | 8f4af134e3 | ||
Bruno BELANYI | 387dc2d3ad | ||
Bruno BELANYI | 69000556d4 | ||
Bruno BELANYI | bb8a48812c | ||
Bruno BELANYI | cc84a43055 | ||
Bruno BELANYI | 0ca28eb2e9 | ||
Bruno BELANYI | f8f328fa17 | ||
Bruno BELANYI | 9ee889d7ad | ||
Bruno BELANYI | 9889191245 | ||
Bruno BELANYI | 6bd28f2b6b | ||
Bruno BELANYI | 9e9fde6c77 | ||
Bruno BELANYI | 615bb266cc | ||
Bruno BELANYI | 9457caf3a2 | ||
Bruno BELANYI | adec624d74 | ||
Bruno BELANYI | b62fc19da9 | ||
Bruno BELANYI | aa8472e73f | ||
Bruno BELANYI | 508ea00920 | ||
Bruno BELANYI | dc1d139d35 | ||
Bruno BELANYI | ebb642cb14 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,6 @@
|
|||
/.pre-commit-config.yaml
|
||||
|
||||
# Tree-sitter artifact
|
||||
/tree-sitter-blueprint.wasm
|
||||
/tree-sitter-bp.wasm
|
||||
# Rust bindings
|
||||
/target
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
[package]
|
||||
name = "tree-sitter-blueprint"
|
||||
name = "tree-sitter-bp"
|
||||
description = "Blueprint grammar for the tree-sitter parsing library"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
keywords = ["incremental", "parsing", "android", "blueprint"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://git.belanyi.fr/ambroisie/tree-sitter-blueprint"
|
||||
repository = "https://git.belanyi.fr/ambroisie/tree-sitter-bp"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
|
|
9
Makefile
9
Makefile
|
@ -1,15 +1,18 @@
|
|||
.PHONE: all
|
||||
.PHONY: all
|
||||
all:
|
||||
tree-sitter generate
|
||||
|
||||
.PHONE: test
|
||||
.PHONY: test
|
||||
test: all
|
||||
tree-sitter test --apply-all-captures
|
||||
nvim-test-runner
|
||||
|
||||
.PHONE: update-tests
|
||||
.PHONY: update-tests
|
||||
update-tests: all
|
||||
tree-sitter test -u --apply-all-captures
|
||||
nvim-test-runner
|
||||
|
||||
.PHONY: playground
|
||||
playground:
|
||||
nix shell pkgs#emscripten --command tree-sitter build-wasm
|
||||
tree-sitter playground
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# tree-sitter-blueprint
|
||||
# tree-sitter-bp
|
||||
|
||||
Tree-sitter grammar for [Blueprint][blueprint-aosp], the meta-build system used
|
||||
in AOSP for its `Android.bp` files.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_blueprint_binding",
|
||||
"target_name": "tree_sitter_bp_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_blueprint();
|
||||
extern "C" TSLanguage * tree_sitter_bp();
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -17,12 +17,12 @@ void Init(Local<Object> exports, Local<Object> module) {
|
|||
|
||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_blueprint());
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_bp());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("blueprint").ToLocalChecked());
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("bp").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_blueprint_binding, Init)
|
||||
NODE_MODULE(tree_sitter_bp_binding, Init)
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_blueprint_binding");
|
||||
module.exports = require("../../build/Release/tree_sitter_bp_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_blueprint_binding");
|
||||
module.exports = require("../../build/Debug/tree_sitter_bp_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! This crate provides blueprint support for the [tree-sitter][] parsing library.
|
||||
//! This crate provides bp support for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! Typically, you will use the [language][language func] function to add this language to a
|
||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
|
@ -6,7 +6,7 @@
|
|||
//! ```
|
||||
//! let code = "";
|
||||
//! let mut parser = tree_sitter::Parser::new();
|
||||
//! parser.set_language(tree_sitter_blueprint::language()).expect("Error loading txtpb grammar");
|
||||
//! parser.set_language(tree_sitter_bp::language()).expect("Error loading txtpb grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
|
@ -18,14 +18,14 @@
|
|||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_blueprint() -> Language;
|
||||
fn tree_sitter_bp() -> Language;
|
||||
}
|
||||
|
||||
/// Get the tree-sitter [Language][] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_blueprint() }
|
||||
unsafe { tree_sitter_bp() }
|
||||
}
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
|
@ -47,6 +47,6 @@ mod tests {
|
|||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(super::language())
|
||||
.expect("Error loading blueprint language");
|
||||
.expect("Error loading bp language");
|
||||
}
|
||||
}
|
||||
|
|
34
flake.nix
34
flake.nix
|
@ -37,6 +37,7 @@
|
|||
}:
|
||||
let
|
||||
inherit (flake-utils.lib) eachDefaultSystem;
|
||||
inherit (nixpkgs) lib;
|
||||
in
|
||||
eachDefaultSystem
|
||||
(system:
|
||||
|
@ -46,6 +47,25 @@
|
|||
overlays = [ self.overlays.default ];
|
||||
};
|
||||
|
||||
nvim-test-runner = pkgs.writeShellApplication {
|
||||
name = "nvim-test-runner";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
highlight-assertions
|
||||
neovim
|
||||
];
|
||||
|
||||
text = ''
|
||||
export NVIM_PLENARY='${pkgs.vimPlugins.plenary-nvim}'
|
||||
export NVIM_TREESITTER='${pkgs.vimPlugins.nvim-treesitter}'
|
||||
export NVIM_TREESITTER_TEXTOBJECTS='${pkgs.vimPlugins.nvim-treesitter-textobjects}'
|
||||
export NVIM_TREESITTER_PARSER='${pkgs.vimPlugins.nvim-treesitter.grammarToPlugin self.packages.${system}.tree-sitter-bp}'
|
||||
|
||||
nvim --headless --noplugin -u ${scripts/minimal_init.lua} \
|
||||
-c "PlenaryBustedDirectory test/ { minimal_init = '${./scripts/minimal_init.lua}' }"
|
||||
'';
|
||||
};
|
||||
|
||||
bump-version = pkgs.writeShellScriptBin "bump-version" ''
|
||||
set -eu
|
||||
|
||||
|
@ -90,6 +110,13 @@
|
|||
enable = true;
|
||||
};
|
||||
|
||||
nvim-test-runner = {
|
||||
enable = true;
|
||||
name = "nvim tests";
|
||||
entry = "${lib.getExe nvim-test-runner}";
|
||||
pass_filenames = false;
|
||||
};
|
||||
|
||||
tree-sitter = {
|
||||
enable = true;
|
||||
name = "tree-sitter tests";
|
||||
|
@ -112,6 +139,7 @@
|
|||
nativeBuildInputs = with pkgs; [
|
||||
bump-version
|
||||
nodejs
|
||||
nvim-test-runner
|
||||
# FIXME: waiting on #301336
|
||||
# (tree-sitter.override { webUISupport = true; })
|
||||
tree-sitter
|
||||
|
@ -122,9 +150,9 @@
|
|||
};
|
||||
|
||||
packages = {
|
||||
default = packages.tree-sitter-blueprint;
|
||||
default = packages.tree-sitter-bp;
|
||||
|
||||
inherit (pkgs.tree-sitter.passthru.builtGrammars) tree-sitter-blueprint;
|
||||
inherit (pkgs.tree-sitter.passthru.builtGrammars) tree-sitter-bp;
|
||||
|
||||
inherit (pkgs) tree-sitter;
|
||||
};
|
||||
|
@ -133,7 +161,7 @@
|
|||
default = final: prev: {
|
||||
tree-sitter = prev.tree-sitter.override {
|
||||
extraGrammars = {
|
||||
tree-sitter-blueprint = {
|
||||
tree-sitter-bp = {
|
||||
src = ./.;
|
||||
};
|
||||
};
|
||||
|
|
34
grammar.js
34
grammar.js
|
@ -2,17 +2,12 @@ function commaSeparated(elem) {
|
|||
return seq(elem, repeat(seq(",", elem)), optional(","))
|
||||
}
|
||||
|
||||
function trailingCommaSeparated(elem) {
|
||||
return repeat(seq(elem, ","))
|
||||
}
|
||||
|
||||
module.exports = grammar({
|
||||
name: "blueprint",
|
||||
name: "bp",
|
||||
|
||||
extras: ($) => [
|
||||
/\s+/,
|
||||
$.line_comment,
|
||||
$.block_comment,
|
||||
$.comment,
|
||||
],
|
||||
|
||||
rules: {
|
||||
|
@ -23,9 +18,10 @@ module.exports = grammar({
|
|||
$.module,
|
||||
),
|
||||
|
||||
line_comment: (_) => seq("//", /[^\n]*/),
|
||||
|
||||
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
|
||||
comment: (_) => choice(
|
||||
seq("//", /(\\+(.|\r?\n)|[^\\\n])*/),
|
||||
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/"),
|
||||
),
|
||||
|
||||
// Definitions {{{
|
||||
|
||||
|
@ -123,10 +119,11 @@ module.exports = grammar({
|
|||
"(",
|
||||
choice($.select_value, $.soong_config_variable),
|
||||
",",
|
||||
$.select_cases,
|
||||
$._select_cases,
|
||||
")",
|
||||
),
|
||||
|
||||
// FIXME: simplify with 'soong_config_variable'?
|
||||
select_value: ($) => seq(
|
||||
field("type", alias(
|
||||
choice("product_variable", "release_variable", "variant"),
|
||||
|
@ -137,6 +134,7 @@ module.exports = grammar({
|
|||
")",
|
||||
),
|
||||
|
||||
// FIXME
|
||||
soong_config_variable: ($) => seq(
|
||||
field("type", alias("soong_config_variable", $.selection_type)),
|
||||
"(",
|
||||
|
@ -151,26 +149,18 @@ module.exports = grammar({
|
|||
")",
|
||||
),
|
||||
|
||||
select_cases: ($) => seq(
|
||||
_select_cases: ($) => seq(
|
||||
"{",
|
||||
optional(trailingCommaSeparated($.select_case)),
|
||||
// default *must* be the last one, enforced at parse-time...
|
||||
optional(seq($.default_case, ",")),
|
||||
optional(repeat(seq($.select_case, ","))),
|
||||
"}",
|
||||
),
|
||||
|
||||
select_case: ($) => seq(
|
||||
field("pattern", $._string_literal),
|
||||
field("pattern", choice(alias("default", $.default), $._string_literal)),
|
||||
":",
|
||||
field("value", $._case_value)
|
||||
),
|
||||
|
||||
default_case: ($) => seq(
|
||||
field("pattern", "default"),
|
||||
":",
|
||||
field("value", $._case_value),
|
||||
),
|
||||
|
||||
_case_value: ($) => choice(
|
||||
alias("unset", $.unset),
|
||||
$._expr,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tree-sitter-blueprint",
|
||||
"version": "0.1.0",
|
||||
"name": "tree-sitter-bp",
|
||||
"version": "0.2.0",
|
||||
"description": "Blueprint grammar for tree-sitter",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
|
@ -18,7 +18,7 @@
|
|||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.blueprint",
|
||||
"scope": "source.bp",
|
||||
"file-types": [
|
||||
"bp"
|
||||
],
|
||||
|
|
8
queries/folds.scm
Normal file
8
queries/folds.scm
Normal file
|
@ -0,0 +1,8 @@
|
|||
[
|
||||
(list_expression)
|
||||
(map_expression)
|
||||
(module)
|
||||
(select_expression)
|
||||
] @fold
|
||||
|
||||
; vim: sw=2 foldmethod=marker
|
|
@ -1,7 +1,4 @@
|
|||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @comment
|
||||
(comment) @comment
|
||||
|
||||
; Operators {{{
|
||||
(operator) @operator
|
||||
|
@ -52,7 +49,7 @@
|
|||
; Built-ins {{{
|
||||
[
|
||||
(unset)
|
||||
"default"
|
||||
(default)
|
||||
] @variable.builtin
|
||||
(selection_type) @function.builtin
|
||||
; }}}
|
||||
|
|
29
queries/indents.scm
Normal file
29
queries/indents.scm
Normal file
|
@ -0,0 +1,29 @@
|
|||
; Expressions {{{
|
||||
(list_expression) @indent.begin
|
||||
(list_expression
|
||||
"]" @indent.branch)
|
||||
|
||||
(map_expression) @indent.begin
|
||||
(map_expression
|
||||
"}" @indent.branch)
|
||||
|
||||
(select_expression) @indent.begin
|
||||
(select_expression
|
||||
")" @indent.branch)
|
||||
|
||||
; FIXME: how to fix this
|
||||
; (select_expression
|
||||
; "{" @indent.begin)
|
||||
; (select_expression
|
||||
; "}" @indent.branch)
|
||||
; }}}
|
||||
|
||||
; Declarations {{{
|
||||
(module) @indent.begin
|
||||
(module
|
||||
")" @indent.branch)
|
||||
(module
|
||||
"}" @indent.branch)
|
||||
; }}}
|
||||
|
||||
; vim: sw=2 foldmethod=marker
|
4
queries/injections.scm
Normal file
4
queries/injections.scm
Normal file
|
@ -0,0 +1,4 @@
|
|||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; vim: sw=2 foldmethod=marker
|
1
scripts/dummy_plugin/queries/bp
Symbolic link
1
scripts/dummy_plugin/queries/bp
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../queries
|
40
scripts/minimal_init.lua
Normal file
40
scripts/minimal_init.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
vim.opt.runtimepath:append(vim.env.NVIM_PLENARY)
|
||||
vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER)
|
||||
vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER_TEXTOBJECTS)
|
||||
vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER_PARSER)
|
||||
|
||||
vim.cmd.runtime({ "plugin/plenary.vim", bang = true })
|
||||
vim.cmd.runtime({ "plugin/nvim-treesitter.lua", bang = true })
|
||||
vim.cmd.runtime({ "plugin/nvim-treesitter-textobjects.lua", bang = true })
|
||||
|
||||
local Path = require("plenary.path")
|
||||
|
||||
local project_root = Path:new(".") -- FIXME: relies on current working directory
|
||||
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
bp = "bp",
|
||||
},
|
||||
})
|
||||
|
||||
vim.o.swapfile = false
|
||||
vim.bo.swapfile = false
|
||||
|
||||
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
|
||||
parser_config.bp = {
|
||||
install_info = {
|
||||
url = project_root.filename,
|
||||
files = {"src/parser.c"},
|
||||
},
|
||||
}
|
||||
|
||||
require("nvim-treesitter.configs").setup({
|
||||
indent = { enable = true },
|
||||
highlight = { enable = true },
|
||||
})
|
||||
|
||||
-- We need a hierarchy of `queries/bp/*.scm` in the runtimepath, otherwise
|
||||
-- `nvim-treesitter` doesn't enable some of its features (e.g: folding).
|
||||
-- The dummy plugin has a symlink following that format for our queries.
|
||||
local dummy_plugin_path = project_root / "scripts" / "dummy_plugin"
|
||||
vim.opt.runtimepath:append(dummy_plugin_path.filename)
|
127
src/grammar.json
generated
127
src/grammar.json
generated
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "blueprint",
|
||||
"name": "bp",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "REPEAT",
|
||||
|
@ -21,33 +21,38 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"line_comment": {
|
||||
"type": "SEQ",
|
||||
"comment": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "//"
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "//"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "(\\\\+(.|\\r?\\n)|[^\\\\\\n])*"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\n]*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"block_comment": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/*"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/"
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/*"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -482,7 +487,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "select_cases"
|
||||
"name": "_select_cases"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
|
@ -592,7 +597,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"select_cases": {
|
||||
"_select_cases": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
|
@ -623,27 +628,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "default_case"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
|
@ -657,33 +641,22 @@
|
|||
"type": "FIELD",
|
||||
"name": "pattern",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_string_literal"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "value",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_case_value"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"default_case": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "pattern",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "default"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "default"
|
||||
},
|
||||
"named": true,
|
||||
"value": "default"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_string_literal"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -956,11 +929,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "line_comment"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block_comment"
|
||||
"name": "comment"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
|
|
98
src/node-types.json
generated
98
src/node-types.json
generated
|
@ -167,77 +167,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "default_case",
|
||||
"type": "comment",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"pattern": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "default",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "interpreted_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "list_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "map_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "raw_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "select_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unset",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
|
@ -259,11 +197,6 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "line_comment",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "list_expression",
|
||||
"named": true,
|
||||
|
@ -420,6 +353,10 @@
|
|||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "default",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "interpreted_string_literal",
|
||||
"named": true
|
||||
|
@ -478,25 +415,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "select_cases",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "default_case",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "select_case",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "select_expression",
|
||||
"named": true,
|
||||
|
@ -506,7 +424,7 @@
|
|||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "select_cases",
|
||||
"type": "select_case",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
|
@ -673,7 +591,7 @@
|
|||
},
|
||||
{
|
||||
"type": "default",
|
||||
"named": false
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
|
|
4036
src/parser.c
generated
4036
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@ Empty comment
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(line_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Single comment
|
||||
|
@ -18,7 +18,7 @@ Single comment
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(line_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Multiple comments
|
||||
|
@ -30,8 +30,8 @@ Multiple comments
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(line_comment)
|
||||
(line_comment))
|
||||
(comment)
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Empty block comment
|
||||
|
@ -42,7 +42,7 @@ Empty block comment
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Whitespace block comment
|
||||
|
@ -53,7 +53,7 @@ Whitespace block comment
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Block comment
|
||||
|
@ -64,7 +64,7 @@ Block comment
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Block comment with slashes
|
||||
|
@ -75,7 +75,7 @@ Block comment with slashes
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Block comment with asterisks
|
||||
|
@ -86,7 +86,7 @@ Block comment with asterisks
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Block comment (multiline)
|
||||
|
@ -103,7 +103,7 @@ Block comment (multiline)
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Block comment is not recursive
|
||||
|
@ -114,7 +114,7 @@ Block comment is not recursive
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(block_comment))
|
||||
(comment))
|
||||
|
||||
================================================================================
|
||||
Unterminated comment
|
||||
|
|
134
test/corpus/literals.txt
Normal file
134
test/corpus/literals.txt
Normal file
|
@ -0,0 +1,134 @@
|
|||
================================================================================
|
||||
Booelan literal
|
||||
================================================================================
|
||||
|
||||
foo = true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(boolean_literal)))
|
||||
|
||||
================================================================================
|
||||
Integer literal
|
||||
================================================================================
|
||||
|
||||
foo = 42
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(integer_literal)))
|
||||
|
||||
================================================================================
|
||||
String literal
|
||||
================================================================================
|
||||
|
||||
foo = "Hello World!"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal)))
|
||||
|
||||
================================================================================
|
||||
String literal special character escapes
|
||||
================================================================================
|
||||
|
||||
foo = "Hello\nWorld!"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(escape_sequence))))
|
||||
|
||||
================================================================================
|
||||
String literal octal
|
||||
================================================================================
|
||||
|
||||
foo = "Hello World\041"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(escape_sequence))))
|
||||
|
||||
================================================================================
|
||||
String literal hex
|
||||
================================================================================
|
||||
|
||||
foo = "Hello World\x21"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(escape_sequence))))
|
||||
|
||||
================================================================================
|
||||
String literal character escapes
|
||||
================================================================================
|
||||
|
||||
foo = "Hello\\\"World\""
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(escape_sequence)
|
||||
(escape_sequence)
|
||||
(escape_sequence))))
|
||||
|
||||
================================================================================
|
||||
Unterminated string literal
|
||||
================================================================================
|
||||
|
||||
foo = "
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(MISSING """))))
|
||||
|
||||
================================================================================
|
||||
String literal unterminated escape
|
||||
================================================================================
|
||||
|
||||
foo = "\"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(operator)
|
||||
(interpreted_string_literal
|
||||
(escape_sequence)
|
||||
(MISSING """))))
|
|
@ -17,12 +17,12 @@ foo = select(release_variable("RELEASE_TEST"), {
|
|||
(select_value
|
||||
(selection_type)
|
||||
(interpreted_string_literal))
|
||||
(select_cases
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(default_case
|
||||
(unset))))))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(default)
|
||||
(unset)))))
|
||||
|
||||
================================================================================
|
||||
Select (soong config variable)
|
||||
|
@ -44,13 +44,12 @@ foo = select(soong_config_variable("my_namespace", "my_var"), {
|
|||
(selection_type)
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_cases
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(unset))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))))))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(unset))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal)))))
|
||||
|
||||
================================================================================
|
||||
Select (no default)
|
||||
|
@ -73,19 +72,18 @@ foo = select(variant("arch"), {
|
|||
(select_value
|
||||
(selection_type)
|
||||
(interpreted_string_literal))
|
||||
(select_cases
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))))))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal)))))
|
||||
|
||||
================================================================================
|
||||
Select (no values)
|
||||
|
@ -102,8 +100,7 @@ foo = select(variant("VARIANT"), {})
|
|||
(select_expression
|
||||
(select_value
|
||||
(selection_type)
|
||||
(interpreted_string_literal))
|
||||
(select_cases))))
|
||||
(interpreted_string_literal)))))
|
||||
|
||||
================================================================================
|
||||
Select (default in wrong order)
|
||||
|
@ -127,22 +124,21 @@ foo = select(variant("VARIANT"), {
|
|||
(select_value
|
||||
(selection_type)
|
||||
(interpreted_string_literal))
|
||||
(select_cases
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(ERROR
|
||||
(default_case
|
||||
(unset)))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))))))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(default)
|
||||
(unset))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal)))))
|
||||
|
||||
================================================================================
|
||||
Select (no condition)
|
||||
|
@ -163,12 +159,12 @@ foo = select(variant(), {
|
|||
(select_value
|
||||
(selection_type)
|
||||
(MISSING raw_string_literal))
|
||||
(select_cases
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(unset))
|
||||
(default_case
|
||||
(interpreted_string_literal))))))
|
||||
(select_case
|
||||
(interpreted_string_literal)
|
||||
(unset))
|
||||
(select_case
|
||||
(default)
|
||||
(interpreted_string_literal)))))
|
||||
|
||||
================================================================================
|
||||
Select (invalid type)
|
||||
|
@ -189,7 +185,8 @@ foo = select(some_unknown_type("CONDITION"), {
|
|||
(identifier)
|
||||
(identifier)
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal))
|
||||
(interpreted_string_literal)
|
||||
(default))
|
||||
(interpreted_string_literal))
|
||||
(ERROR))
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
/* This is comment */
|
||||
/* <- comment
|
||||
^ comment
|
||||
^ comment
|
||||
*/
|
||||
/* This is a comment */
|
||||
// <- comment
|
||||
// ^ comment
|
||||
// ^ comment
|
||||
|
||||
// And another comment
|
||||
/* <- comment
|
||||
^ comment
|
||||
^ comment
|
||||
*/
|
||||
// <- comment
|
||||
// ^ comment
|
||||
// ^ comment
|
||||
|
|
|
@ -4,16 +4,16 @@ foo {}
|
|||
foo ()
|
||||
// <- function.call
|
||||
|
||||
foo {
|
||||
// <- function.call
|
||||
some_module {
|
||||
// ^ function.call
|
||||
field: 12,
|
||||
// <- variable.parameter
|
||||
another_field: 27,
|
||||
// <- variable.parameter
|
||||
}
|
||||
|
||||
foo (
|
||||
// <- function.call
|
||||
some_module (
|
||||
// ^ function.call
|
||||
field = 42,
|
||||
// <- variable.parameter
|
||||
done = false,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
foo {
|
||||
field: {
|
||||
// <- variable.parameter
|
||||
some_field: {
|
||||
// ^ variable.parameter
|
||||
key: 42,
|
||||
// <- property
|
||||
},
|
||||
|
|
|
@ -3,13 +3,24 @@ foo (
|
|||
bar = [
|
||||
//^ punctuation.bracket
|
||||
{
|
||||
// <- punctuation.bracket
|
||||
key: "value",
|
||||
// ^ punctuation.delimiter
|
||||
// ^ punctuation.delimiter
|
||||
another: {},
|
||||
// ^ punctuation.bracket
|
||||
// ^ punctuation.bracket
|
||||
},
|
||||
// <- punctuation.bracket
|
||||
]
|
||||
],
|
||||
// <- punctuation.bracket
|
||||
baz = {
|
||||
//^ punctuation.bracket
|
||||
key: [],
|
||||
// ^ punctuation.delimiter
|
||||
// ^ punctuation.bracket
|
||||
// ^ punctuation.bracket
|
||||
// ^ punctuation.delimiter
|
||||
},
|
||||
// <- punctuation.bracket
|
||||
)
|
||||
// <- punctuation.bracket
|
||||
|
|
22
test/indent/expressions.bp
Normal file
22
test/indent/expressions.bp
Normal file
|
@ -0,0 +1,22 @@
|
|||
foo = 1 + 2
|
||||
|
||||
foo = [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
]
|
||||
|
||||
foo = {
|
||||
foo: [
|
||||
"bar",
|
||||
],
|
||||
},
|
||||
|
||||
foo = {
|
||||
foo: [
|
||||
"bar",
|
||||
{
|
||||
key: "value",
|
||||
},
|
||||
],
|
||||
},
|
28
test/indent/select.bp
Normal file
28
test/indent/select.bp
Normal file
|
@ -0,0 +1,28 @@
|
|||
foo = select(variant("VARIANT"), {
|
||||
"x86": "my_x86",
|
||||
"x86_64": [
|
||||
"x86",
|
||||
"x64",
|
||||
],
|
||||
"arm": {
|
||||
some: "aarch",
|
||||
value: "aarch64",
|
||||
},
|
||||
default: 0,
|
||||
})
|
||||
|
||||
foo = select(
|
||||
variant("VARIANT"),
|
||||
{
|
||||
"x86": "my_x86",
|
||||
"x86_64": [
|
||||
"x86",
|
||||
"x64",
|
||||
],
|
||||
"arm": {
|
||||
some: "aarch",
|
||||
value: "aarch64",
|
||||
},
|
||||
default: 0,
|
||||
}
|
||||
)
|
47
test/indent_spec.lua
Normal file
47
test/indent_spec.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
package.path = package.path .. ";" .. vim.env.NVIM_TREESITTER .. "/?.lua"
|
||||
|
||||
local Runner = require("tests.indent.common").Runner
|
||||
|
||||
-- FIXME: path to root
|
||||
local runner = Runner:new(it, ".", {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
})
|
||||
|
||||
describe("indent Blueprint:", function()
|
||||
describe("whole file:", function()
|
||||
runner:whole_file("test/highlight/", {
|
||||
expected_failures = {
|
||||
-- NOTE: none for now
|
||||
},
|
||||
})
|
||||
runner:whole_file("test/indent/", {
|
||||
expected_failures = {
|
||||
-- NOTE: none for now
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
describe("new line:", function()
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 2, text = "foo = 42", indent = 0 }, "variable declaration")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 4, text = "0,", indent = 4 }, "list element")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 6, text = "]", indent = 0 }, "list closing delimiter")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 9, text = "key: 42", indent = 4 }, "map property")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 12, text = "key: 42", indent = 4 }, "map property, trailing")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 9, text = "}", indent = 0 }, "map closing delimiter")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 11, text = "]", indent = 4 }, "nested list closing delimiter")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 18, text = "key: 42", indent = 12 }, "nested map property")
|
||||
runner:new_line("test/indent/expressions.bp", { on_line = 19, text = "key: 42", indent = 12 }, "nested map property, trailing")
|
||||
|
||||
runner:new_line("test/indent/select.bp", { on_line = 1, text = '"case": "value"', indent = 4 }, "select case")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 1, text = 'default: "value"', indent = 4 }, "default case")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 11, text = '"case": "value"', indent = 4 }, "select case, trailing")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 11, text = 'default: "value"', indent = 4 }, "default case, trailing")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 16, text = '"case": "value"', indent = 8 }, "select case, alternate formatting")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 16, text = 'default: "value"', indent = 8 }, "default case, alternate formatting")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 26, text = '"case": "value"', indent = 8 }, "select case, trailing, alternate formattingg")
|
||||
runner:new_line("test/indent/select.bp", { on_line = 26, text = 'default: "value"', indent = 8 }, "default case, trailing, alternate formattingn")
|
||||
end)
|
||||
end)
|
Loading…
Reference in a new issue