Add .config/helix/.chezmoiignore
Add .config/helix/.gitignore Add .config/helix/runtime/grammars/.gitkeep Add .config/helix/runtime/grammars/astro.so Add .config/helix/runtime/grammars/awk.so Add .config/helix/runtime/grammars/bash.so Add .config/helix/runtime/grammars/bass.so Add .config/helix/runtime/grammars/beancount.so Add .config/helix/runtime/grammars/bibtex.so Add .config/helix/runtime/grammars/bicep.so Add .config/helix/runtime/grammars/blueprint.so Add .config/helix/runtime/grammars/c-sharp.so Add .config/helix/runtime/grammars/c.so Add .config/helix/runtime/grammars/capnp.so Add .config/helix/runtime/grammars/clojure.so Add .config/helix/runtime/grammars/cmake.so Add .config/helix/runtime/grammars/comment.so Add .config/helix/runtime/grammars/cpon.so Add .config/helix/runtime/grammars/cpp.so Add .config/helix/runtime/grammars/css.so Add .config/helix/runtime/grammars/cue.so Add .config/helix/runtime/grammars/d.so Add .config/helix/runtime/grammars/dart.so Add .config/helix/runtime/grammars/devicetree.so Add .config/helix/runtime/grammars/dhall.so Add .config/helix/runtime/grammars/diff.so Add .config/helix/runtime/grammars/dockerfile.so Add .config/helix/runtime/grammars/dot.so Add .config/helix/runtime/grammars/dtd.so Add .config/helix/runtime/grammars/edoc.so Add .config/helix/runtime/grammars/eex.so Add .config/helix/runtime/grammars/elixir.so Add .config/helix/runtime/grammars/elm.so Add .config/helix/runtime/grammars/elvish.so Add .config/helix/runtime/grammars/embedded-template.so Add .config/helix/runtime/grammars/erlang.so Add .config/helix/runtime/grammars/esdl.so Add .config/helix/runtime/grammars/fish.so Add .config/helix/runtime/grammars/forth.so Add .config/helix/runtime/grammars/fortran.so Add .config/helix/runtime/grammars/fsharp.so Add .config/helix/runtime/grammars/gdscript.so Add .config/helix/runtime/grammars/git-commit.so Add .config/helix/runtime/grammars/git-config.so Add .config/helix/runtime/grammars/git-rebase.so Add .config/helix/runtime/grammars/gitattributes.so Add .config/helix/runtime/grammars/gitignore.so Add .config/helix/runtime/grammars/gleam.so Add .config/helix/runtime/grammars/glsl.so Add .config/helix/runtime/grammars/go.so Add .config/helix/runtime/grammars/godot-resource.so Add .config/helix/runtime/grammars/gomod.so Add .config/helix/runtime/grammars/gotmpl.so Add .config/helix/runtime/grammars/gowork.so Add .config/helix/runtime/grammars/graphql.so Add .config/helix/runtime/grammars/hare.so Add .config/helix/runtime/grammars/haskell-persistent.so Add .config/helix/runtime/grammars/haskell.so Add .config/helix/runtime/grammars/hcl.so Add .config/helix/runtime/grammars/heex.so Add .config/helix/runtime/grammars/hosts.so Add .config/helix/runtime/grammars/html.so Add .config/helix/runtime/grammars/hurl.so Add .config/helix/runtime/grammars/iex.so Add .config/helix/runtime/grammars/ini.so Add .config/helix/runtime/grammars/java.so Add .config/helix/runtime/grammars/javascript.so Add .config/helix/runtime/grammars/jinja2.so Add .config/helix/runtime/grammars/jsdoc.so Add .config/helix/runtime/grammars/json.so Add .config/helix/runtime/grammars/jsonnet.so Add .config/helix/runtime/grammars/julia.so Add .config/helix/runtime/grammars/just.so Add .config/helix/runtime/grammars/kdl.so Add .config/helix/runtime/grammars/kotlin.so Add .config/helix/runtime/grammars/latex.so Add .config/helix/runtime/grammars/lean.so Add .config/helix/runtime/grammars/ledger.so Add .config/helix/runtime/grammars/llvm-mir.so Add .config/helix/runtime/grammars/llvm.so Add .config/helix/runtime/grammars/lua.so Add .config/helix/runtime/grammars/make.so Add .config/helix/runtime/grammars/markdoc.so Add .config/helix/runtime/grammars/markdown.so Add .config/helix/runtime/grammars/markdown_inline.so Add .config/helix/runtime/grammars/matlab.so Add .config/helix/runtime/grammars/mermaid.so Add .config/helix/runtime/grammars/meson.so Add .config/helix/runtime/grammars/nasm.so Add .config/helix/runtime/grammars/nickel.so Add .config/helix/runtime/grammars/nim.so Add .config/helix/runtime/grammars/nix.so Add .config/helix/runtime/grammars/nu.so Add .config/helix/runtime/grammars/ocaml-interface.so Add .config/helix/runtime/grammars/ocaml.so Add .config/helix/runtime/grammars/odin.so Add .config/helix/runtime/grammars/opencl.so Add .config/helix/runtime/grammars/openscad.so Add .config/helix/runtime/grammars/org.so Add .config/helix/runtime/grammars/pascal.so Add .config/helix/runtime/grammars/passwd.so Add .config/helix/runtime/grammars/pem.so Add .config/helix/runtime/grammars/perl.so Add .config/helix/runtime/grammars/php.so Add .config/helix/runtime/grammars/po.so Add .config/helix/runtime/grammars/pod.so Add .config/helix/runtime/grammars/ponylang.so Add .config/helix/runtime/grammars/prisma.so Add .config/helix/runtime/grammars/protobuf.so Add .config/helix/runtime/grammars/prql.so Add .config/helix/runtime/grammars/python.so Add .config/helix/runtime/grammars/qmljs.so Add .config/helix/runtime/grammars/r.so Add .config/helix/runtime/grammars/regex.so Add .config/helix/runtime/grammars/rego.so Add .config/helix/runtime/grammars/rescript.so Add .config/helix/runtime/grammars/robot.so Add .config/helix/runtime/grammars/rst.so Add .config/helix/runtime/grammars/ruby.so Add .config/helix/runtime/grammars/rust.so Add .config/helix/runtime/grammars/scala.so Add .config/helix/runtime/grammars/scheme.so Add .config/helix/runtime/grammars/scss.so Add .config/helix/runtime/grammars/slint.so Add .config/helix/runtime/grammars/smithy.so Add .config/helix/runtime/grammars/sml.so Add .config/helix/runtime/grammars/solidity.so Add .config/helix/runtime/grammars/sources/astro/Cargo.toml Add .config/helix/runtime/grammars/sources/astro/README.md Add .config/helix/runtime/grammars/sources/astro/binding.gyp Add .config/helix/runtime/grammars/sources/astro/bindings/node/binding.cc Add .config/helix/runtime/grammars/sources/astro/bindings/node/index.js Add .config/helix/runtime/grammars/sources/astro/bindings/rust/build.rs Add .config/helix/runtime/grammars/sources/astro/bindings/rust/lib.rs Add .config/helix/runtime/grammars/sources/astro/.gitignore Add .config/helix/runtime/grammars/sources/astro/flake.lock Add .config/helix/runtime/grammars/sources/astro/flake.nix Add .config/helix/runtime/grammars/sources/astro/grammar.js Add .config/helix/runtime/grammars/sources/astro/package-lock.json Add .config/helix/runtime/grammars/sources/astro/package.json Add .config/helix/runtime/grammars/sources/astro/queries/highlights.scm Add .config/helix/runtime/grammars/sources/astro/queries/injections.scm Add .config/helix/runtime/grammars/sources/astro/src/grammar.json Add .config/helix/runtime/grammars/sources/astro/src/node-types.json Add .config/helix/runtime/grammars/sources/astro/src/parser.c Add .config/helix/runtime/grammars/sources/astro/src/scanner.cc Add .config/helix/runtime/grammars/sources/astro/src/tag.h Add .config/helix/runtime/grammars/sources/astro/src/tree_sitter/parser.h Add .config/helix/runtime/grammars/sources/astro/test.astro Add .config/helix/runtime/grammars/sources/astro/test2.astro Add .config/helix/runtime/grammars/sources/astro/test3.astro Add .config/helix/runtime/grammars/sources/astro/test4.astro Add .config/helix/runtime/grammars/sources/astro/test5.astro Add .config/helix/runtime/grammars/sources/astro/test6.astro Add .config/helix/runtime/grammars/sources/awk/Cargo.toml Add .config/helix/runtime/grammars/sources/awk/LICENSE Add .config/helix/runtime/grammars/sources/awk/README.md Add .config/helix/runtime/grammars/sources/awk/binding.gyp Add .config/helix/runtime/grammars/sources/awk/bindings/node/binding.cc Add .config/helix/runtime/grammars/sources/awk/bindings/node/index.js Add .config/helix/runtime/grammars/sources/awk/bindings/rust/build.rs Add .config/helix/runtime/grammars/sources/awk/bindings/rust/lib.rs Add .config/helix/runtime/grammars/sources/awk/.github/workflows/tests.yml Add .config/helix/runtime/grammars/sources/awk/.gitignore Add .config/helix/runtime/grammars/sources/awk/.npmignore Add .config/helix/runtime/grammars/sources/awk/.prettierrc Add .config/helix/runtime/grammars/sources/awk/.vscode/launch.json Add .config/helix/runtime/grammars/sources/awk/examples/example.awk Add .config/helix/runtime/grammars/sources/awk/grammar.d.ts Add .config/helix/runtime/grammars/sources/awk/grammar.js Add .config/helix/runtime/grammars/sources/awk/jsconfig.json Add .config/helix/runtime/grammars/sources/awk/package.json Add .config/helix/runtime/grammars/sources/awk/queries/highlights.scm Add .config/helix/runtime/grammars/sources/awk/scripts/update_highlights_version.sh Add .config/helix/runtime/grammars/sources/awk/scripts/generate_types.js Add .config/helix/runtime/grammars/sources/awk/scripts/generate_types_watch.js Add .config/helix/runtime/grammars/sources/awk/src/grammar.json Add .config/helix/runtime/grammars/sources/awk/src/node-types.json Add .config/helix/runtime/grammars/sources/awk/src/parser.c Add .config/helix/runtime/grammars/sources/awk/src/scanner.c Add .config/helix/runtime/grammars/sources/awk/src/tree_sitter/parser.h Add .config/helix/runtime/grammars/sources/awk/test/corpus/crlf.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/expression.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/function.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/pattern.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/program.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/statement.txt Add .config/helix/runtime/grammars/sources/awk/yarn.lock Add .config/helix/runtime/grammars/sources/bash/Cargo.toml Add .config/helix/runtime/grammars/sources/bash/LICENSE Add .config/helix/runtime/grammars/sources/bash/.gitattributes Add .config/helix/runtime/grammars/sources/bash/.github/workflows/ci.yml Add .config/helix/runtime/grammars/sources/bash/.gitignore Add .config/helix/runtime/grammars/sources/bash/.gitmodules Add .config/helix/runtime/grammars/sources/bash/.npmignore Add .config/helix/runtime/grammars/sources/bash/.travis.yml Remove .config/helix/runtime
This commit is contained in:
26
dot_config/helix/runtime/grammars/sources/awk/Cargo.toml
Normal file
26
dot_config/helix/runtime/grammars/sources/awk/Cargo.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "tree-sitter-awk"
|
||||
description = "awk grammar for the tree-sitter parsing library"
|
||||
version = "0.0.1"
|
||||
keywords = ["incremental", "parsing", "awk"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-awk"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = [
|
||||
"bindings/rust/*",
|
||||
"grammar.js",
|
||||
"queries/*",
|
||||
"src/*",
|
||||
]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "~0.20.0"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
21
dot_config/helix/runtime/grammars/sources/awk/LICENSE
Normal file
21
dot_config/helix/runtime/grammars/sources/awk/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 Stanislav Chernov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
35
dot_config/helix/runtime/grammars/sources/awk/README.md
Normal file
35
dot_config/helix/runtime/grammars/sources/awk/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
tree-sitter-awk
|
||||
================
|
||||
|
||||
[](https://github.com/Beaglefoot/tree-sitter-awk/actions/workflows/tests.yml)
|
||||
[](https://www.npmjs.com/package/tree-sitter-awk)
|
||||
|
||||
GNU AWK grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
||||
|
||||
|
||||
### Development
|
||||
|
||||
Install the dependencies:
|
||||
|
||||
yarn
|
||||
|
||||
Although grammar is basically a JS file you can still benefit from types (references, go to implementation, renames...).
|
||||
|
||||
To build types in watch mode:
|
||||
|
||||
yarn types:watch
|
||||
|
||||
Test:
|
||||
|
||||
yarn test
|
||||
|
||||
To ease generating test results create a fragment code in some file and run:
|
||||
|
||||
npx tree-sitter parse <your_file> | yarn -s trim
|
||||
|
||||
You can simplify process further by piping result into `xclip` or alike.
|
||||
|
||||
### References
|
||||
|
||||
* [GAWK Man page](https://www.man7.org/linux/man-pages/man1/gawk.1.html)
|
||||
* [Original Bison grammar](http://git.savannah.gnu.org/cgit/gawk.git/tree/awkgram.y)
|
20
dot_config/helix/runtime/grammars/sources/awk/binding.gyp
Normal file
20
dot_config/helix/runtime/grammars/sources/awk/binding.gyp
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_awk_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
# If your language uses an external scanner, add it here.
|
||||
"src/scanner.c"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_awk();
|
||||
|
||||
namespace {
|
||||
|
||||
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_awk());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("awk").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_awk_binding, Init)
|
||||
|
||||
} // namespace
|
@@ -0,0 +1,19 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_awk_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_awk_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
@@ -0,0 +1,40 @@
|
||||
fn main() {
|
||||
let src_dir = std::path::Path::new("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config.include(&src_dir);
|
||||
c_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
.flag_if_supported("-Wno-trigraphs");
|
||||
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,52 @@
|
||||
//! This crate provides awk language 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:
|
||||
//!
|
||||
//! ```
|
||||
//! let code = "";
|
||||
//! let mut parser = tree_sitter::Parser::new();
|
||||
//! parser.set_language(tree_sitter_awk::language()).expect("Error loading awk grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_awk() -> 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_awk() }
|
||||
}
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
///
|
||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||
|
||||
// Uncomment these to include any queries that this grammar contains
|
||||
|
||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(super::language())
|
||||
.expect("Error loading awk language");
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
name: tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
cache: yarn
|
||||
|
||||
- run: yarn install --frozen-lockfile
|
||||
|
||||
- run: yarn test
|
@@ -0,0 +1,9 @@
|
||||
node_modules/
|
||||
build/
|
||||
|
||||
*.log
|
||||
|
||||
temp
|
||||
temp.awk
|
||||
log.html
|
||||
tree-sitter-awk.wasm
|
13
dot_config/helix/runtime/grammars/sources/awk/dot_npmignore
Normal file
13
dot_config/helix/runtime/grammars/sources/awk/dot_npmignore
Normal file
@@ -0,0 +1,13 @@
|
||||
.github/
|
||||
.vscode/
|
||||
examples/
|
||||
scripts/
|
||||
build/
|
||||
test/
|
||||
node_modules/
|
||||
|
||||
*.log
|
||||
|
||||
temp
|
||||
temp.awk
|
||||
log.html
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": true,
|
||||
"printWidth": 100,
|
||||
"arrowParens": "avoid"
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "pwa-node",
|
||||
"request": "launch",
|
||||
"name": "generate_types",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/scripts/generate_types.js",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/**/*.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
@include "somelib"
|
||||
|
||||
function do_stuff(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function x::sum(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
do_stuff("hi", 42);
|
||||
|
||||
arr[1] = "some_value";
|
||||
|
||||
for (i in arr) delete arr[i];
|
||||
|
||||
"cal" | getline line;
|
||||
|
||||
printf("%s", line);
|
||||
close("cal");
|
||||
}
|
||||
|
||||
/[a-z]/ {
|
||||
# Here goes comment
|
||||
split($0, arr, ",");
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
END {
|
||||
for (x = 1; x <= 12; x++) {
|
||||
print tolower($x) > "/dev/stderr"
|
||||
|
||||
if (x == 9)
|
||||
break;
|
||||
else if (x == 5)
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(x) {
|
||||
case 1:
|
||||
case 2:
|
||||
default:
|
||||
typeof(x);
|
||||
}
|
||||
|
||||
exit 1;
|
||||
}
|
115
dot_config/helix/runtime/grammars/sources/awk/grammar.d.ts
vendored
Normal file
115
dot_config/helix/runtime/grammars/sources/awk/grammar.d.ts
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
declare interface IExternals {
|
||||
concatenating_space: ($: IExternals) => any;
|
||||
_if_else_separator: ($: IExternals) => any;
|
||||
_ambiguous_comment: ($: IExternals) => any;
|
||||
_no_space: ($: IExternals) => any;
|
||||
}
|
||||
|
||||
declare interface IRules {
|
||||
program: ($: IRules & IExternals) => any;
|
||||
rule: ($: IRules & IExternals) => any;
|
||||
pattern: ($: IRules & IExternals) => any;
|
||||
range_pattern: ($: IRules & IExternals) => any;
|
||||
_special_pattern: ($: IRules & IExternals) => any;
|
||||
directive: ($: IRules & IExternals) => any;
|
||||
_statement: ($: IRules & IExternals) => any;
|
||||
_statement_separated: ($: IRules & IExternals) => any;
|
||||
_control_statement: ($: IRules & IExternals) => any;
|
||||
if_statement: ($: IRules & IExternals) => any;
|
||||
else_clause: ($: IRules & IExternals) => any;
|
||||
while_statement: ($: IRules & IExternals) => any;
|
||||
do_while_statement: ($: IRules & IExternals) => any;
|
||||
for_statement: ($: IRules & IExternals) => any;
|
||||
for_in_statement: ($: IRules & IExternals) => any;
|
||||
break_statement: ($: IRules & IExternals) => any;
|
||||
continue_statement: ($: IRules & IExternals) => any;
|
||||
delete_statement: ($: IRules & IExternals) => any;
|
||||
exit_statement: ($: IRules & IExternals) => any;
|
||||
return_statement: ($: IRules & IExternals) => any;
|
||||
switch_statement: ($: IRules & IExternals) => any;
|
||||
switch_body: ($: IRules & IExternals) => any;
|
||||
switch_case: ($: IRules & IExternals) => any;
|
||||
switch_default: ($: IRules & IExternals) => any;
|
||||
_io_statement: ($: IRules & IExternals) => any;
|
||||
_getline_exp: ($: IRules & IExternals) => any;
|
||||
getline_input: ($: IRules & IExternals) => any;
|
||||
getline_file: ($: IRules & IExternals) => any;
|
||||
next_statement: ($: IRules & IExternals) => any;
|
||||
nextfile_statement: ($: IRules & IExternals) => any;
|
||||
_print_args: ($: IRules & IExternals) => any;
|
||||
print_statement: ($: IRules & IExternals) => any;
|
||||
printf_statement: ($: IRules & IExternals) => any;
|
||||
redirected_io_statement: ($: IRules & IExternals) => any;
|
||||
piped_io_statement: ($: IRules & IExternals) => any;
|
||||
block: ($: IRules & IExternals) => any;
|
||||
_block_content: ($: IRules & IExternals) => any;
|
||||
_exp: ($: IRules & IExternals) => any;
|
||||
ternary_exp: ($: IRules & IExternals) => any;
|
||||
binary_exp: ($: IRules & IExternals) => any;
|
||||
unary_exp: ($: IRules & IExternals) => any;
|
||||
update_exp: ($: IRules & IExternals) => any;
|
||||
assignment_exp: ($: IRules & IExternals) => any;
|
||||
piped_io_exp: ($: IRules & IExternals) => any;
|
||||
string_concat: ($: IRules & IExternals) => any;
|
||||
field_ref: ($: IRules & IExternals) => any;
|
||||
array_ref: ($: IRules & IExternals) => any;
|
||||
exp_list: ($: IRules & IExternals) => any;
|
||||
regex: ($: IRules & IExternals) => any;
|
||||
regex_pattern: ($: IRules & IExternals) => any;
|
||||
regex_flags: ($: IRules & IExternals) => any;
|
||||
regex_constant: ($: IRules & IExternals) => any;
|
||||
grouping: ($: IRules & IExternals) => any;
|
||||
_primitive: ($: IRules & IExternals) => any;
|
||||
identifier: ($: IRules & IExternals) => any;
|
||||
namespace: ($: IRules & IExternals) => any;
|
||||
ns_qualified_name: ($: IRules & IExternals) => any;
|
||||
number: ($: IRules & IExternals) => any;
|
||||
string: ($: IRules & IExternals) => any;
|
||||
escape_sequence: ($: IRules & IExternals) => any;
|
||||
func_def: ($: IRules & IExternals) => any;
|
||||
param_list: ($: IRules & IExternals) => any;
|
||||
func_call: ($: IRules & IExternals) => any;
|
||||
indirect_func_call: ($: IRules & IExternals) => any;
|
||||
args: ($: IRules & IExternals) => any;
|
||||
comment: ($: IRules & IExternals) => any;
|
||||
}
|
||||
|
||||
|
||||
declare interface IGrammar {
|
||||
name: string;
|
||||
extras?: ($: IRules & IExternals) => any;
|
||||
inline?: ($: IRules & IExternals) => any;
|
||||
conflicts?: ($: IRules & IExternals) => any;
|
||||
externals?: ($: IExternals) => any;
|
||||
word?: ($: IRules & IExternals) => any;
|
||||
supertypes?: ($: IRules & IExternals) => any;
|
||||
precedences?: ($: IRules & IExternals) => any;
|
||||
rules: IRules;
|
||||
}
|
||||
|
||||
declare function grammar(g: IGrammar): any;
|
||||
|
||||
declare type TRule = (($: IRules & IExternals) => any) | string | RegExp;
|
||||
|
||||
declare interface IPrecFunc {
|
||||
(rule: TRule): TRule;
|
||||
(val: number | string, rule: TRule): TRule;
|
||||
}
|
||||
|
||||
declare interface ITokenFunc {
|
||||
(rule: TRule): TRule;
|
||||
}
|
||||
|
||||
declare function seq(...rules: TRule[]): TRule;
|
||||
declare function choice(...rules: TRule[]): TRule;
|
||||
declare function repeat(rule: TRule): TRule;
|
||||
declare function repeat1(rule: TRule): TRule;
|
||||
declare function optional(rule: TRule): TRule;
|
||||
declare function alias(rule: TRule, name: TRule): TRule;
|
||||
declare function field(name: string, rule: TRule): TRule;
|
||||
declare const prec: IPrecFunc & {
|
||||
left: IPrecFunc;
|
||||
right: IPrecFunc;
|
||||
dynamic: (val: number, rule: TRule) => TRule;
|
||||
};
|
||||
declare const token: ITokenFunc & { immediate: ITokenFunc }
|
398
dot_config/helix/runtime/grammars/sources/awk/grammar.js
Normal file
398
dot_config/helix/runtime/grammars/sources/awk/grammar.js
Normal file
@@ -0,0 +1,398 @@
|
||||
module.exports = grammar({
|
||||
name: 'awk',
|
||||
|
||||
extras: $ => [$.comment, /[\s\t]/, '\\\n', '\\\r\n'],
|
||||
|
||||
externals: $ => [$.concatenating_space, $._if_else_separator, $._ambiguous_comment, $._no_space],
|
||||
|
||||
precedences: $ => [
|
||||
[
|
||||
$.getline_file,
|
||||
$.getline_input,
|
||||
$.grouping,
|
||||
$.field_ref,
|
||||
$.func_call,
|
||||
$.update_exp,
|
||||
'binary_exponent',
|
||||
'binary_times',
|
||||
'binary_plus',
|
||||
$.string_concat,
|
||||
$.unary_exp,
|
||||
$.piped_io_exp,
|
||||
'binary_relation',
|
||||
'binary_match',
|
||||
'binary_in',
|
||||
'binary_and',
|
||||
'binary_or',
|
||||
$.ternary_exp,
|
||||
$.exp_list,
|
||||
$.range_pattern,
|
||||
$._statement,
|
||||
],
|
||||
[$.func_call, $._exp],
|
||||
[$.update_exp, $._exp],
|
||||
[$.if_statement, $._statement_separated],
|
||||
[$.else_clause, $._statement_separated],
|
||||
[$.print_statement, $.printf_statement, $.grouping],
|
||||
[$._print_args, $.grouping, $.piped_io_exp, 'binary_relation'],
|
||||
[$.for_in_statement, $._exp],
|
||||
[$._exp, $.string_concat, $.assignment_exp],
|
||||
],
|
||||
|
||||
conflicts: $ => [],
|
||||
|
||||
word: $ => $.identifier,
|
||||
|
||||
rules: {
|
||||
program: $ => repeat(choice($.rule, $.func_def, $.directive)),
|
||||
|
||||
rule: $ =>
|
||||
prec.right(choice(seq($.pattern, optional($.block)), seq(optional($.pattern), $.block))),
|
||||
|
||||
pattern: $ => prec.right(choice($._exp, $.range_pattern, $._special_pattern)),
|
||||
|
||||
range_pattern: $ => seq(field('start', $._exp), ',', field('stop', $._exp)),
|
||||
|
||||
_special_pattern: $ => choice('BEGIN', 'END', 'BEGINFILE', 'ENDFILE'),
|
||||
|
||||
directive: $ => seq(choice('@include', '@load', '@namespace'), $.string),
|
||||
|
||||
_statement: $ =>
|
||||
prec.left(
|
||||
choice(
|
||||
seq($._statement_separated, $._statement),
|
||||
$._statement_separated,
|
||||
$._control_statement,
|
||||
$._io_statement,
|
||||
$._exp
|
||||
)
|
||||
),
|
||||
|
||||
_statement_separated: $ => prec.right(seq($._statement, choice(';', '\n', '\r\n'))),
|
||||
|
||||
_control_statement: $ =>
|
||||
choice(
|
||||
$.if_statement,
|
||||
$.while_statement,
|
||||
$.do_while_statement,
|
||||
$.for_statement,
|
||||
$.for_in_statement,
|
||||
$.break_statement,
|
||||
$.continue_statement,
|
||||
$.delete_statement,
|
||||
$.exit_statement,
|
||||
$.return_statement,
|
||||
$.switch_statement
|
||||
),
|
||||
|
||||
if_statement: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
'if',
|
||||
field('condition', seq('(', $._exp, ')')),
|
||||
choice($.block, $._statement, ';'),
|
||||
optional(seq($._if_else_separator, $.else_clause))
|
||||
)
|
||||
),
|
||||
|
||||
else_clause: $ => seq('else', choice($.block, $._statement)),
|
||||
|
||||
while_statement: $ =>
|
||||
prec.right(
|
||||
seq('while', field('condition', seq('(', $._exp, ')')), choice($.block, $._statement))
|
||||
),
|
||||
|
||||
do_while_statement: $ =>
|
||||
prec.right(
|
||||
seq('do', choice($.block, $._statement), 'while', field('condition', seq('(', $._exp, ')')))
|
||||
),
|
||||
|
||||
for_statement: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
'for',
|
||||
'(',
|
||||
field('initializer', optional($._exp)),
|
||||
';',
|
||||
field('condition', optional($._exp)),
|
||||
';',
|
||||
field('advancement', optional($._exp)),
|
||||
')',
|
||||
choice($.block, $._statement)
|
||||
)
|
||||
),
|
||||
|
||||
for_in_statement: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
'for',
|
||||
'(',
|
||||
field('left', choice($.identifier, $.ns_qualified_name)),
|
||||
'in',
|
||||
field('right', choice($.identifier, $.array_ref, $.ns_qualified_name)),
|
||||
')',
|
||||
choice($.block, $._statement)
|
||||
)
|
||||
),
|
||||
|
||||
break_statement: $ => 'break',
|
||||
|
||||
continue_statement: $ => 'continue',
|
||||
|
||||
delete_statement: $ => seq('delete', choice($.identifier, $.array_ref, $.ns_qualified_name)),
|
||||
|
||||
exit_statement: $ => prec.right(seq('exit', optional($._exp))),
|
||||
|
||||
return_statement: $ => prec.right(seq('return', optional($._exp))),
|
||||
|
||||
switch_statement: $ => seq('switch', '(', $._exp, ')', $.switch_body),
|
||||
|
||||
switch_body: $ => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
|
||||
|
||||
switch_case: $ =>
|
||||
seq('case', field('value', choice($._primitive, $.regex)), ':', optional($._statement)),
|
||||
|
||||
switch_default: $ => seq('default', ':', $._statement),
|
||||
|
||||
_io_statement: $ =>
|
||||
choice(
|
||||
$.next_statement,
|
||||
$.nextfile_statement,
|
||||
$.print_statement,
|
||||
$.printf_statement,
|
||||
$.redirected_io_statement,
|
||||
$.piped_io_statement
|
||||
),
|
||||
|
||||
// Although it's referenced as statement in manual it acts as an expression
|
||||
_getline_exp: $ => choice($.getline_input, $.getline_file),
|
||||
|
||||
getline_input: $ =>
|
||||
prec.right(seq('getline', optional(choice($.identifier, $.ns_qualified_name)))),
|
||||
|
||||
getline_file: $ =>
|
||||
seq(
|
||||
'getline',
|
||||
optional(choice($.identifier, $.ns_qualified_name)),
|
||||
'<',
|
||||
field('filename', $._exp)
|
||||
),
|
||||
|
||||
next_statement: $ => 'next',
|
||||
|
||||
nextfile_statement: $ => 'nextfile',
|
||||
|
||||
_print_args: $ => prec.right(choice($._exp, $.exp_list)),
|
||||
|
||||
print_statement: $ =>
|
||||
prec.right(
|
||||
seq('print', optional(choice($._print_args, seq(token.immediate('('), $._print_args, ')'))))
|
||||
),
|
||||
|
||||
printf_statement: $ => seq('printf', choice($._print_args, seq('(', $._print_args, ')'))),
|
||||
|
||||
redirected_io_statement: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
choice($.print_statement, $.printf_statement),
|
||||
choice('>', '>>'),
|
||||
field('filename', $._exp)
|
||||
)
|
||||
),
|
||||
|
||||
piped_io_statement: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
choice($.print_statement, $.printf_statement),
|
||||
choice('|', '|&'),
|
||||
field('command', $._exp)
|
||||
)
|
||||
),
|
||||
|
||||
block: $ => seq('{', repeat($._block_content), '}'),
|
||||
|
||||
_block_content: $ => prec.left(choice($.block, $._statement)),
|
||||
|
||||
_exp: $ =>
|
||||
choice(
|
||||
$.identifier,
|
||||
$.ns_qualified_name,
|
||||
$.ternary_exp,
|
||||
$.binary_exp,
|
||||
$.unary_exp,
|
||||
$.update_exp,
|
||||
$.assignment_exp,
|
||||
$.field_ref,
|
||||
$.func_call,
|
||||
$.indirect_func_call,
|
||||
$._primitive,
|
||||
$.array_ref,
|
||||
$.regex,
|
||||
$.regex_constant,
|
||||
$.grouping,
|
||||
$.piped_io_exp,
|
||||
$.string_concat,
|
||||
$._getline_exp
|
||||
),
|
||||
|
||||
ternary_exp: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
field('condition', $._exp),
|
||||
'?',
|
||||
field('consequence', $._exp),
|
||||
':',
|
||||
field('alternative', $._exp)
|
||||
)
|
||||
),
|
||||
|
||||
binary_exp: $ =>
|
||||
choice(
|
||||
...[
|
||||
['^', 'binary_exponent'],
|
||||
['**', 'binary_exponent'],
|
||||
['*', 'binary_times'],
|
||||
['/', 'binary_times'],
|
||||
['%', 'binary_times'],
|
||||
['+', 'binary_plus'],
|
||||
['-', 'binary_plus'],
|
||||
['<', 'binary_relation'],
|
||||
['>', 'binary_relation'],
|
||||
['<=', 'binary_relation'],
|
||||
['>=', 'binary_relation'],
|
||||
['==', 'binary_relation'],
|
||||
['!=', 'binary_relation'],
|
||||
['~', 'binary_match'],
|
||||
['!~', 'binary_match'],
|
||||
['in', 'binary_in'],
|
||||
['&&', 'binary_and'],
|
||||
['||', 'binary_or'],
|
||||
].map(([op, precedence]) =>
|
||||
prec.left(
|
||||
precedence,
|
||||
seq(field('left', $._exp), field('operator', op), field('right', $._exp))
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
unary_exp: $ =>
|
||||
choice(...['!', '+', '-'].map(op => seq(field('operator', op), field('argument', $._exp)))),
|
||||
|
||||
update_exp: $ => {
|
||||
const refs = choice($.identifier, $.field_ref, $.array_ref, $.ns_qualified_name);
|
||||
|
||||
return prec.left(
|
||||
choice(
|
||||
seq(field('argument', refs), field('operator', choice('++', '--'))),
|
||||
seq(field('operator', choice('++', '--')), field('argument', refs))
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
assignment_exp: $ =>
|
||||
prec.right(
|
||||
seq(
|
||||
field('left', choice($.identifier, $.array_ref, $.field_ref, $.ns_qualified_name)),
|
||||
choice('=', '+=', '-=', '*=', '/=', '%=', '^='),
|
||||
field('right', $._exp)
|
||||
)
|
||||
),
|
||||
|
||||
piped_io_exp: $ => seq(field('command', $._exp), choice('|', '|&'), $.getline_input),
|
||||
|
||||
string_concat: $ => {
|
||||
const applicable_exp = choice(
|
||||
$.identifier,
|
||||
$.ns_qualified_name,
|
||||
$.ternary_exp,
|
||||
$.binary_exp,
|
||||
$.unary_exp,
|
||||
$.field_ref,
|
||||
$.func_call,
|
||||
$._primitive,
|
||||
$.array_ref,
|
||||
$.grouping,
|
||||
$.string_concat
|
||||
);
|
||||
|
||||
return prec.left(
|
||||
seq(field('left', applicable_exp), $.concatenating_space, field('right', applicable_exp))
|
||||
);
|
||||
},
|
||||
|
||||
field_ref: $ => seq('$', $._exp),
|
||||
|
||||
array_ref: $ =>
|
||||
seq(
|
||||
choice($.identifier, $.array_ref, $.ns_qualified_name),
|
||||
'[',
|
||||
field('index', choice($._exp, $.exp_list)),
|
||||
']'
|
||||
),
|
||||
|
||||
exp_list: $ => seq(repeat1(seq($._exp, ',')), $._exp),
|
||||
|
||||
regex: $ =>
|
||||
seq(
|
||||
'/',
|
||||
field('pattern', $.regex_pattern),
|
||||
token.immediate('/'),
|
||||
optional(field('flags', $.regex_flags))
|
||||
),
|
||||
|
||||
regex_pattern: $ => {
|
||||
const char = /[^/\\\[\n\r]/;
|
||||
const char_escaped = seq('\\', /./);
|
||||
const char_list = seq('[', repeat1(choice(char_escaped, /[^\]]/)), ']');
|
||||
|
||||
return token.immediate(repeat(choice(char, char_escaped, char_list)));
|
||||
},
|
||||
|
||||
regex_flags: $ => token.immediate(/[a-z]+/),
|
||||
|
||||
regex_constant: $ => seq('@', $.regex),
|
||||
|
||||
grouping: $ => seq('(', $._exp, ')'),
|
||||
|
||||
_primitive: $ => choice($.number, $.string),
|
||||
|
||||
identifier: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
|
||||
|
||||
namespace: $ => alias($.identifier, 'namespace'),
|
||||
|
||||
ns_qualified_name: $ => seq($.namespace, token.immediate('::'), $._no_space, $.identifier),
|
||||
|
||||
number: $ => /[\d.]+/,
|
||||
|
||||
string: $ => seq('"', repeat(choice(/[^"\\]+/, $.escape_sequence, $._ambiguous_comment)), '"'),
|
||||
|
||||
escape_sequence: $ =>
|
||||
token.immediate(seq('\\', choice('"', /[\\abfnrtv]/, /x[0-9a-fA-F]{1,2}/, /[0-7]{1,3}/))),
|
||||
|
||||
func_def: $ =>
|
||||
seq(
|
||||
choice('function', 'func'),
|
||||
field('name', choice($.identifier, $.ns_qualified_name)),
|
||||
'(',
|
||||
optional($.param_list),
|
||||
')',
|
||||
$.block
|
||||
),
|
||||
|
||||
param_list: $ => seq($.identifier, repeat(seq(',', $.identifier))),
|
||||
|
||||
func_call: $ =>
|
||||
seq(
|
||||
field('name', choice($.identifier, $.ns_qualified_name)),
|
||||
token.immediate('('),
|
||||
optional($.args),
|
||||
')'
|
||||
),
|
||||
|
||||
indirect_func_call: $ => seq('@', $.func_call),
|
||||
|
||||
args: $ => seq($._exp, repeat(seq(',', $._exp))),
|
||||
|
||||
comment: $ => seq('#', /.*/),
|
||||
},
|
||||
});
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"files": ["grammar.js", "grammar.d.ts"],
|
||||
"exclude": ["node_modules/"],
|
||||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
"strictNullChecks": true,
|
||||
}
|
||||
}
|
44
dot_config/helix/runtime/grammars/sources/awk/package.json
Normal file
44
dot_config/helix/runtime/grammars/sources/awk/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "tree-sitter-awk",
|
||||
"version": "0.5.1",
|
||||
"author": "Beaglefoot <ch-e-st@yandex.ru>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"awk",
|
||||
"gawk"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Beaglefoot/tree-sitter-awk.git"
|
||||
},
|
||||
"scripts": {
|
||||
"generate": "tree-sitter generate",
|
||||
"build": "yarn generate && node-gyp build",
|
||||
"build:wasm": "tree-sitter build-wasm",
|
||||
"parse": "tree-sitter parse",
|
||||
"types": "node scripts/generate_types.js",
|
||||
"types:watch": "node scripts/generate_types_watch.js",
|
||||
"trim": "sed ' s/ \\[.*\\]//; s/\\w\\+:// '",
|
||||
"test": "tree-sitter test",
|
||||
"version": "./scripts/update_highlights_version.sh",
|
||||
"prepublishOnly": "yarn build:wasm"
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": "2.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "2.3.2",
|
||||
"tree-sitter-cli": "0.20.6"
|
||||
},
|
||||
"main": "bindings/node",
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.awk",
|
||||
"file-types": [
|
||||
"awk",
|
||||
"gawk"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
; tree-sitter-awk v0.5.1
|
||||
|
||||
; https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries
|
||||
|
||||
; Order matters
|
||||
|
||||
(ns_qualified_name (namespace) @namespace)
|
||||
(ns_qualified_name "::" @operator)
|
||||
|
||||
(func_def name: (_ (identifier) @function) @function)
|
||||
(func_call name: (_ (identifier) @function) @function)
|
||||
|
||||
[
|
||||
(identifier)
|
||||
(field_ref)
|
||||
] @variable
|
||||
(field_ref (_) @variable)
|
||||
|
||||
(string) @string
|
||||
(number) @number
|
||||
(regex) @regexp
|
||||
(comment) @comment
|
||||
|
||||
[
|
||||
"function"
|
||||
"func"
|
||||
"print"
|
||||
"printf"
|
||||
"if"
|
||||
"else"
|
||||
"do"
|
||||
"while"
|
||||
"for"
|
||||
"in"
|
||||
"delete"
|
||||
"return"
|
||||
"exit"
|
||||
"switch"
|
||||
"case"
|
||||
"default"
|
||||
(break_statement)
|
||||
(continue_statement)
|
||||
(next_statement)
|
||||
(nextfile_statement)
|
||||
(getline_input)
|
||||
(getline_file)
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"@include"
|
||||
"@load"
|
||||
"@namespace"
|
||||
(pattern)
|
||||
] @namespace
|
||||
|
||||
(binary_exp [
|
||||
"^"
|
||||
"**"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"+"
|
||||
"-"
|
||||
"<"
|
||||
">"
|
||||
"<="
|
||||
">="
|
||||
"=="
|
||||
"!="
|
||||
"~"
|
||||
"!~"
|
||||
"in"
|
||||
"&&"
|
||||
"||"
|
||||
] @operator)
|
||||
|
||||
(unary_exp [
|
||||
"!"
|
||||
"+"
|
||||
"-"
|
||||
] @operator)
|
||||
|
||||
(assignment_exp [
|
||||
"="
|
||||
"+="
|
||||
"-="
|
||||
"*="
|
||||
"/="
|
||||
"%="
|
||||
"^="
|
||||
] @operator)
|
||||
|
||||
(ternary_exp [
|
||||
"?"
|
||||
":"
|
||||
] @operator)
|
||||
|
||||
(update_exp [
|
||||
"++"
|
||||
"--"
|
||||
] @operator)
|
||||
|
||||
(redirected_io_statement [
|
||||
">"
|
||||
">>"
|
||||
] @operator)
|
||||
|
||||
(piped_io_statement [
|
||||
"|"
|
||||
"|&"
|
||||
] @operator)
|
||||
|
||||
[
|
||||
";"
|
||||
","
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @operator
|
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Intended for usage with `npm version` command and `version` stage
|
||||
|
||||
sed -i " s/\(; tree-sitter-awk v\)[0-9]\.[0-9]\.[0-9]/\1$(npm pkg get version | tr -d \")/ " queries/highlights.scm
|
||||
|
||||
git add queries/highlights.scm
|
@@ -0,0 +1,105 @@
|
||||
// Generate types for grammar.js
|
||||
// Allows autocomplete, go to implementation and navigation to symbol
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
function writeTypes() {
|
||||
console.log('Generating types...');
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
const source = fs.readFileSync('grammar.js', 'utf8');
|
||||
const writer = fs.createWriteStream('grammar.d.ts', 'utf8');
|
||||
|
||||
function grammar(g) {
|
||||
// Externals
|
||||
writer.write('declare interface IExternals {\n');
|
||||
|
||||
const m = g?.externals?.toString()?.match(/\(?\$\)? => \[([\s\S]*)\]/);
|
||||
|
||||
if (m?.[1]) {
|
||||
const extRules = m[1]
|
||||
.replace(/[\s\n]/g, '')
|
||||
.replace(/\$\./g, '')
|
||||
.split(',')
|
||||
.filter(Boolean);
|
||||
|
||||
for (const r of extRules) {
|
||||
writer.write(` ${r}: ($: IExternals) => any;\n`);
|
||||
}
|
||||
}
|
||||
|
||||
writer.write('}\n\n');
|
||||
|
||||
// Rules
|
||||
writer.write('declare interface IRules {\n');
|
||||
|
||||
for (const k in g.rules) {
|
||||
writer.write(` ${k}: ($: IRules & IExternals) => any;\n`);
|
||||
}
|
||||
|
||||
writer.write('}\n\n');
|
||||
}
|
||||
|
||||
try {
|
||||
eval(source);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const furtherDefinitions = `
|
||||
declare interface IGrammar {
|
||||
name: string;
|
||||
extras?: ($: IRules & IExternals) => any;
|
||||
inline?: ($: IRules & IExternals) => any;
|
||||
conflicts?: ($: IRules & IExternals) => any;
|
||||
externals?: ($: IExternals) => any;
|
||||
word?: ($: IRules & IExternals) => any;
|
||||
supertypes?: ($: IRules & IExternals) => any;
|
||||
precedences?: ($: IRules & IExternals) => any;
|
||||
rules: IRules;
|
||||
}
|
||||
|
||||
declare function grammar(g: IGrammar): any;
|
||||
|
||||
declare type TRule = (($: IRules & IExternals) => any) | string | RegExp;
|
||||
|
||||
declare interface IPrecFunc {
|
||||
(rule: TRule): TRule;
|
||||
(val: number | string, rule: TRule): TRule;
|
||||
}
|
||||
|
||||
declare interface ITokenFunc {
|
||||
(rule: TRule): TRule;
|
||||
}
|
||||
|
||||
declare function seq(...rules: TRule[]): TRule;
|
||||
declare function choice(...rules: TRule[]): TRule;
|
||||
declare function repeat(rule: TRule): TRule;
|
||||
declare function repeat1(rule: TRule): TRule;
|
||||
declare function optional(rule: TRule): TRule;
|
||||
declare function alias(rule: TRule, name: TRule): TRule;
|
||||
declare function field(name: string, rule: TRule): TRule;
|
||||
declare const prec: IPrecFunc & {
|
||||
left: IPrecFunc;
|
||||
right: IPrecFunc;
|
||||
dynamic: (val: number, rule: TRule) => TRule;
|
||||
};
|
||||
declare const token: ITokenFunc & { immediate: ITokenFunc }
|
||||
`;
|
||||
|
||||
writer.write(furtherDefinitions);
|
||||
writer.close();
|
||||
|
||||
const endTime = performance.now() - startTime;
|
||||
console.log(`Done: ${endTime.toFixed(3)}s`);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
writeTypes();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
writeTypes,
|
||||
};
|
@@ -0,0 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const { writeTypes } = require('./generate_types.js');
|
||||
|
||||
if (!fs.existsSync('grammar.d.ts')) writeTypes();
|
||||
|
||||
fs.watchFile('grammar.js', writeTypes);
|
3057
dot_config/helix/runtime/grammars/sources/awk/src/grammar.json
Normal file
3057
dot_config/helix/runtime/grammars/sources/awk/src/grammar.json
Normal file
File diff suppressed because it is too large
Load Diff
5234
dot_config/helix/runtime/grammars/sources/awk/src/node-types.json
Normal file
5234
dot_config/helix/runtime/grammars/sources/awk/src/node-types.json
Normal file
File diff suppressed because it is too large
Load Diff
96425
dot_config/helix/runtime/grammars/sources/awk/src/parser.c
Normal file
96425
dot_config/helix/runtime/grammars/sources/awk/src/parser.c
Normal file
File diff suppressed because it is too large
Load Diff
252
dot_config/helix/runtime/grammars/sources/awk/src/scanner.c
Normal file
252
dot_config/helix/runtime/grammars/sources/awk/src/scanner.c
Normal file
@@ -0,0 +1,252 @@
|
||||
#include <tree_sitter/parser.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
enum TokenType
|
||||
{
|
||||
CONCATENATING_SPACE,
|
||||
_IF_ELSE_SEPARATOR,
|
||||
_AMBIGUOUS_COMMENT,
|
||||
_NO_SPACE
|
||||
};
|
||||
|
||||
void tsawk_debug(TSLexer *lexer)
|
||||
{
|
||||
if (lexer->lookahead == '\r')
|
||||
{
|
||||
printf("column: %3" PRIu32 " | sym: '%c' | lookahead: '\\r' | skipped: %s\n",
|
||||
lexer->get_column(lexer),
|
||||
lexer->result_symbol,
|
||||
lexer->is_at_included_range_start(lexer) ? "true" : "false");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '\n')
|
||||
{
|
||||
printf("column: %3" PRIu32 " | sym: '%c' | lookahead: '\\n' | skipped: %s\n",
|
||||
lexer->get_column(lexer),
|
||||
lexer->result_symbol,
|
||||
lexer->is_at_included_range_start(lexer) ? "true" : "false");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("column: %3" PRIu32 " | sym: '%c' | lookahead: '%c' | skipped: %s\n",
|
||||
lexer->get_column(lexer),
|
||||
lexer->result_symbol,
|
||||
lexer->lookahead,
|
||||
lexer->is_at_included_range_start(lexer) ? "true" : "false");
|
||||
}
|
||||
|
||||
bool tsawk_next_chars_eq(TSLexer *lexer, char *word)
|
||||
{
|
||||
for (int i = 0; i < strlen(word); i++)
|
||||
{
|
||||
if (lexer->lookahead != word[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
lexer->advance(lexer, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tsawk_is_whitespace(int32_t c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
bool tsawk_is_line_continuation(TSLexer *lexer)
|
||||
{
|
||||
if (lexer->lookahead == '\\')
|
||||
{
|
||||
lexer->advance(lexer, true);
|
||||
|
||||
if (lexer->lookahead == '\r')
|
||||
lexer->advance(lexer, true);
|
||||
|
||||
if (lexer->lookahead == '\n')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tsawk_is_statement_terminator(int32_t c)
|
||||
{
|
||||
return c == '\n' || c == ';';
|
||||
}
|
||||
|
||||
bool tsawk_skip_whitespace(TSLexer *lexer, bool skip_newlines, bool capture)
|
||||
{
|
||||
bool skipped = false;
|
||||
|
||||
while (tsawk_is_whitespace(lexer->lookahead) || tsawk_is_line_continuation(lexer) || lexer->lookahead == '\r' || (skip_newlines && lexer->lookahead == '\n'))
|
||||
{
|
||||
lexer->advance(lexer, !capture);
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
||||
void tsawk_skip_comment(TSLexer *lexer)
|
||||
{
|
||||
if (lexer->lookahead != '#')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (lexer->lookahead != '\n')
|
||||
{
|
||||
lexer->advance(lexer, true);
|
||||
}
|
||||
|
||||
lexer->advance(lexer, false);
|
||||
|
||||
tsawk_skip_whitespace(lexer, true, false);
|
||||
|
||||
if (lexer->lookahead == '#')
|
||||
{
|
||||
tsawk_skip_comment(lexer);
|
||||
}
|
||||
}
|
||||
|
||||
bool tsawk_is_if_else_separator(TSLexer *lexer)
|
||||
{
|
||||
while (tsawk_is_whitespace(lexer->lookahead) || tsawk_is_statement_terminator(lexer->lookahead) || lexer->lookahead == '\r')
|
||||
{
|
||||
lexer->advance(lexer, true);
|
||||
}
|
||||
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
if (lexer->lookahead == '#')
|
||||
{
|
||||
tsawk_skip_comment(lexer);
|
||||
tsawk_skip_whitespace(lexer, false, false);
|
||||
}
|
||||
|
||||
return tsawk_next_chars_eq(lexer, "else");
|
||||
}
|
||||
|
||||
bool tsawk_is_concatenating_space(TSLexer *lexer)
|
||||
{
|
||||
bool had_whitespace = tsawk_skip_whitespace(lexer, false, true);
|
||||
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
switch (lexer->lookahead)
|
||||
{
|
||||
case '^':
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
case '+':
|
||||
case '-':
|
||||
case '<':
|
||||
case '>':
|
||||
case '=':
|
||||
case '!':
|
||||
case '~':
|
||||
case '&':
|
||||
case '|':
|
||||
case ',':
|
||||
case '?':
|
||||
case ':':
|
||||
case ')':
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
case '#':
|
||||
case ';':
|
||||
case '\n':
|
||||
return false;
|
||||
case '(':
|
||||
return had_whitespace;
|
||||
case 'i':
|
||||
lexer->advance(lexer, true);
|
||||
|
||||
if (lexer->lookahead == 'n' || lexer->lookahead == 'f')
|
||||
{
|
||||
lexer->advance(lexer, true);
|
||||
return lexer->lookahead != ' ';
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void *tree_sitter_awk_external_scanner_create()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tree_sitter_awk_external_scanner_destroy(void *payload)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned tree_sitter_awk_external_scanner_serialize(void *payload, char *state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tree_sitter_awk_external_scanner_deserialize(void *payload, const char *state, unsigned length)
|
||||
{
|
||||
}
|
||||
|
||||
bool tree_sitter_awk_external_scanner_scan(void *payload, TSLexer *lexer,
|
||||
const bool *valid_symbols)
|
||||
{
|
||||
bool statement_terminator_was_found = false;
|
||||
|
||||
if (valid_symbols[_AMBIGUOUS_COMMENT])
|
||||
{
|
||||
if (lexer->lookahead == '#')
|
||||
{
|
||||
lexer->advance(lexer, false);
|
||||
lexer->mark_end(lexer);
|
||||
lexer->result_symbol = _AMBIGUOUS_COMMENT;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_symbols[_NO_SPACE])
|
||||
{
|
||||
if (!tsawk_is_whitespace(lexer->lookahead))
|
||||
{
|
||||
lexer->result_symbol = _NO_SPACE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_symbols[_IF_ELSE_SEPARATOR])
|
||||
{
|
||||
tsawk_skip_whitespace(lexer, false, false);
|
||||
|
||||
// Comment ends with '\n' which also terminates statement
|
||||
if (tsawk_is_statement_terminator(lexer->lookahead) || lexer->lookahead == '#')
|
||||
{
|
||||
statement_terminator_was_found = true;
|
||||
}
|
||||
|
||||
if (tsawk_is_if_else_separator(lexer))
|
||||
{
|
||||
lexer->result_symbol = _IF_ELSE_SEPARATOR;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_symbols[CONCATENATING_SPACE] && !statement_terminator_was_found)
|
||||
{
|
||||
if (tsawk_is_concatenating_space(lexer))
|
||||
{
|
||||
lexer->result_symbol = CONCATENATING_SPACE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@@ -0,0 +1,224 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#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 TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const char * const *symbol_names;
|
||||
const char * const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
const TSStateId *primary_state_ids;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
@@ -0,0 +1,84 @@
|
||||
====================================
|
||||
If-else with CRLF line end
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) {}
|
||||
else 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(block)
|
||||
(else_clause
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
Line continuation (CRLF)
|
||||
====================================
|
||||
|
||||
\
|
||||
BEGIN {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern)
|
||||
(block)))
|
||||
|
||||
|
||||
=========================================
|
||||
If-else statement with statements (CRLF)
|
||||
=========================================
|
||||
|
||||
{
|
||||
if (1) 1; else 2
|
||||
|
||||
if (1) 1;
|
||||
else 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(number)
|
||||
(else_clause
|
||||
(number)))
|
||||
(if_statement
|
||||
(number)
|
||||
(number)
|
||||
(else_clause
|
||||
(number))))))
|
||||
|
||||
=========================================
|
||||
String concatenation line continuation (CRLF)
|
||||
=========================================
|
||||
|
||||
{
|
||||
a \
|
||||
b
|
||||
a \
|
||||
&& b
|
||||
}
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(identifier)
|
||||
(concatenating_space)
|
||||
(identifier))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier)))))
|
@@ -0,0 +1,800 @@
|
||||
====================================
|
||||
Identifier valid chars
|
||||
====================================
|
||||
|
||||
{
|
||||
My_name_1
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(identifier))))
|
||||
|
||||
====================================
|
||||
Identifier cannot start with num
|
||||
====================================
|
||||
|
||||
{
|
||||
1_my_name = 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(number)
|
||||
(concatenating_space)
|
||||
(identifier))
|
||||
(ERROR
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
Identifier can be prepended with NS
|
||||
====================================
|
||||
|
||||
{
|
||||
main::x
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(ns_qualified_name
|
||||
(namespace)
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Cannot have multiple NS for identifier
|
||||
====================================
|
||||
|
||||
{
|
||||
awk::main::x
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(ns_qualified_name
|
||||
(namespace)
|
||||
(identifier))
|
||||
(ERROR)
|
||||
(concatenating_space)
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Cannot have spaces around ::
|
||||
====================================
|
||||
|
||||
{
|
||||
main ::x
|
||||
main:: x
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(identifier)
|
||||
(ERROR)
|
||||
(concatenating_space)
|
||||
(identifier))
|
||||
(ERROR
|
||||
(namespace))
|
||||
(identifier))))
|
||||
|
||||
====================================
|
||||
Conditional expression
|
||||
====================================
|
||||
|
||||
{
|
||||
x ? 1 : "nope"
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(ternary_exp
|
||||
(identifier)
|
||||
(number)
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Arithmetic operators
|
||||
====================================
|
||||
|
||||
{
|
||||
a ^ 2;
|
||||
a ** 2;
|
||||
2 * 2;
|
||||
16 / 4;
|
||||
20 % 3;
|
||||
x + y;
|
||||
x - y;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Relational operators
|
||||
====================================
|
||||
|
||||
{
|
||||
"a" > "b";
|
||||
x < y;
|
||||
1 >= 2;
|
||||
1.2 <= 2.2;
|
||||
a == b;
|
||||
a != "yes";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(string)
|
||||
(string))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier))
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Match operators
|
||||
====================================
|
||||
|
||||
{
|
||||
x ~ /[a-z]/;
|
||||
x !~ /[a-z]/;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(regex
|
||||
(regex_pattern)))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(regex
|
||||
(regex_pattern))))))
|
||||
|
||||
====================================
|
||||
Array membership
|
||||
====================================
|
||||
|
||||
{
|
||||
x in arr;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Logical operators
|
||||
====================================
|
||||
|
||||
{
|
||||
x > 1 && x < 5;
|
||||
x > 1 || x < -1;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number)))
|
||||
(binary_exp
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(unary_exp
|
||||
(number)))))))
|
||||
|
||||
====================================
|
||||
Unary and logical negation
|
||||
====================================
|
||||
|
||||
{
|
||||
+x;
|
||||
-x;
|
||||
!x;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(unary_exp
|
||||
(identifier))
|
||||
(unary_exp
|
||||
(identifier))
|
||||
(unary_exp
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Increment/Decrement
|
||||
====================================
|
||||
|
||||
{
|
||||
x++;
|
||||
++x;
|
||||
x--;
|
||||
--x;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(update_exp
|
||||
(identifier))
|
||||
(update_exp
|
||||
(identifier))
|
||||
(update_exp
|
||||
(identifier))
|
||||
(update_exp
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Assignment
|
||||
====================================
|
||||
|
||||
{
|
||||
x = 1;
|
||||
x += 2
|
||||
x -= 2;
|
||||
x *= 2;
|
||||
x /= 2;
|
||||
x %= 2;
|
||||
x ^= 2;
|
||||
arr[i] = 1;
|
||||
arr[1] = 1;
|
||||
arr["a"] = 1;
|
||||
$9 = 1;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(array_ref
|
||||
(identifier)
|
||||
(identifier))
|
||||
(number))
|
||||
(assignment_exp
|
||||
(array_ref
|
||||
(identifier)
|
||||
(number))
|
||||
(number))
|
||||
(assignment_exp
|
||||
(array_ref
|
||||
(identifier)
|
||||
(string))
|
||||
(number))
|
||||
(assignment_exp
|
||||
(field_ref
|
||||
(number))
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
Field reference
|
||||
====================================
|
||||
|
||||
{
|
||||
$0;
|
||||
$i;
|
||||
$(1 + 1);
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(field_ref
|
||||
(number))
|
||||
(field_ref
|
||||
(identifier))
|
||||
(field_ref
|
||||
(grouping
|
||||
(binary_exp
|
||||
(number)
|
||||
(number)))))))
|
||||
|
||||
====================================
|
||||
Regex
|
||||
====================================
|
||||
|
||||
{
|
||||
/^abc$/;
|
||||
/abc/g;
|
||||
/abc/gi;
|
||||
/[a-z]/;
|
||||
/[^a-z]/;
|
||||
/\/\[\]/;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(regex
|
||||
(regex_pattern))
|
||||
(regex
|
||||
(regex_pattern)
|
||||
(regex_flags))
|
||||
(regex
|
||||
(regex_pattern)
|
||||
(regex_flags))
|
||||
(regex
|
||||
(regex_pattern))
|
||||
(regex
|
||||
(regex_pattern))
|
||||
(regex
|
||||
(regex_pattern)))))
|
||||
|
||||
====================================
|
||||
Regex constant
|
||||
====================================
|
||||
|
||||
{
|
||||
regex = @/[a-z]/
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(regex_constant
|
||||
(regex
|
||||
(regex_pattern)))))))
|
||||
|
||||
====================================
|
||||
Number
|
||||
====================================
|
||||
|
||||
{
|
||||
42;
|
||||
4.2;
|
||||
.2;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(number)
|
||||
(number)
|
||||
(number))))
|
||||
|
||||
====================================
|
||||
String
|
||||
====================================
|
||||
|
||||
{
|
||||
"abc";
|
||||
"\t\n";
|
||||
"\x0a";
|
||||
"\054";
|
||||
"\"";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string)
|
||||
(string
|
||||
(escape_sequence)
|
||||
(escape_sequence))
|
||||
(string
|
||||
(escape_sequence))
|
||||
(string
|
||||
(escape_sequence))
|
||||
(string
|
||||
(escape_sequence)))))
|
||||
|
||||
====================================
|
||||
String with comment sign
|
||||
====================================
|
||||
|
||||
{
|
||||
a = "#"
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Grouping expression
|
||||
====================================
|
||||
|
||||
{
|
||||
(1 + x) * 5;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(binary_exp
|
||||
(grouping
|
||||
(binary_exp
|
||||
(number)
|
||||
(identifier)))
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
String concatenation
|
||||
====================================
|
||||
|
||||
{
|
||||
"abc" 12
|
||||
a = 1 2
|
||||
f() "hi"
|
||||
42"num"
|
||||
c = a + b 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(number))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(number)
|
||||
(concatenating_space)
|
||||
(number)))
|
||||
(string_concat
|
||||
(func_call
|
||||
(identifier))
|
||||
(concatenating_space)
|
||||
(string))
|
||||
(string_concat
|
||||
(number)
|
||||
(concatenating_space)
|
||||
(string))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier))
|
||||
(concatenating_space)
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
String concatenation multiple
|
||||
====================================
|
||||
|
||||
{
|
||||
sh = "a" var "b";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(identifier))
|
||||
(concatenating_space)
|
||||
(string))))))
|
||||
|
||||
====================================
|
||||
String concatenation in if statement
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) a = "0" a;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(identifier)))))))
|
||||
|
||||
====================================
|
||||
String concatenation inline comment
|
||||
====================================
|
||||
|
||||
{
|
||||
a = "a" 2 # Comment
|
||||
b = 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(number)))
|
||||
(comment)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
String concatenation with grouping
|
||||
====================================
|
||||
|
||||
{
|
||||
a = "a" ("b")
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(grouping
|
||||
(string)))))))
|
||||
|
||||
====================================
|
||||
String concatenation line continuation
|
||||
====================================
|
||||
|
||||
{
|
||||
a \
|
||||
b
|
||||
a \
|
||||
&& b
|
||||
}
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(string_concat
|
||||
(identifier)
|
||||
(concatenating_space)
|
||||
(identifier))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Getline statement no var
|
||||
====================================
|
||||
|
||||
{
|
||||
getline
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(getline_input))))
|
||||
|
||||
====================================
|
||||
Getline statement with var
|
||||
====================================
|
||||
|
||||
{
|
||||
getline var;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(getline_input
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Getline statement from file
|
||||
====================================
|
||||
|
||||
{
|
||||
was_read = getline < "file.csv";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(getline_file
|
||||
(string))))))
|
||||
|
||||
====================================
|
||||
Getline statement from file into var
|
||||
====================================
|
||||
|
||||
{
|
||||
getline var < "file.csv";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(getline_file
|
||||
(identifier)
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Getline piped
|
||||
====================================
|
||||
|
||||
{
|
||||
line_was_read = ("cal" | getline var);
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(grouping
|
||||
(piped_io_exp
|
||||
(string)
|
||||
(getline_input
|
||||
(identifier))))))))
|
||||
|
||||
====================================
|
||||
Getline coprocess piped
|
||||
====================================
|
||||
|
||||
{
|
||||
line_was_read = ("cal" |& getline var);
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(grouping
|
||||
(piped_io_exp
|
||||
(string)
|
||||
(getline_input
|
||||
(identifier))))))))
|
@@ -0,0 +1,168 @@
|
||||
====================================
|
||||
Definition with zero args
|
||||
====================================
|
||||
|
||||
function greet() {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Definition with single arg
|
||||
====================================
|
||||
|
||||
function greet(who) {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(param_list
|
||||
(identifier))
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Definition with multiple arg
|
||||
====================================
|
||||
|
||||
function greet(who, and_who) {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(param_list
|
||||
(identifier)
|
||||
(identifier))
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Definition with func keyword
|
||||
====================================
|
||||
|
||||
func f() {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Wrong definition with trailing comma
|
||||
====================================
|
||||
|
||||
function greet(who,) {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(param_list
|
||||
(identifier))
|
||||
(ERROR)
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Call with zero arguments
|
||||
====================================
|
||||
|
||||
greet()
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(func_call
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Call with single argument
|
||||
====================================
|
||||
|
||||
greet(a)
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(func_call
|
||||
(identifier)
|
||||
(args
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
Call with multiple arguments
|
||||
====================================
|
||||
|
||||
greet("you", 42)
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(func_call
|
||||
(identifier)
|
||||
(args
|
||||
(string)
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
Wrong call with trailing comma
|
||||
====================================
|
||||
|
||||
greet(1,)
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(func_call
|
||||
(identifier)
|
||||
(args
|
||||
(number))
|
||||
(ERROR)))))
|
||||
|
||||
====================================
|
||||
Indirect function call
|
||||
====================================
|
||||
|
||||
@f()
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(indirect_func_call
|
||||
(func_call
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
Cannot have NS amont parameters
|
||||
====================================
|
||||
|
||||
function fn(main::x) {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(func_def
|
||||
(identifier)
|
||||
(param_list
|
||||
(identifier))
|
||||
(ERROR
|
||||
(identifier))
|
||||
(block)))
|
@@ -0,0 +1,75 @@
|
||||
====================================
|
||||
Special pattern
|
||||
====================================
|
||||
|
||||
BEGIN {}
|
||||
BEGINFILE {}
|
||||
END {}
|
||||
ENDFILE {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern)
|
||||
(block))
|
||||
(rule
|
||||
(pattern)
|
||||
(block))
|
||||
(rule
|
||||
(pattern)
|
||||
(block))
|
||||
(rule
|
||||
(pattern)
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Regex pattern
|
||||
====================================
|
||||
|
||||
/[a-z]/
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(regex
|
||||
(regex_pattern)))))
|
||||
|
||||
====================================
|
||||
Range pattern
|
||||
====================================
|
||||
|
||||
NR == 1, NR == 2
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(range_pattern
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
Logical operator pattern
|
||||
====================================
|
||||
|
||||
/[a-z]/ && NR > 5
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(binary_exp
|
||||
(regex
|
||||
(regex_pattern))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))))))
|
@@ -0,0 +1,77 @@
|
||||
====================================
|
||||
Empty pattern
|
||||
====================================
|
||||
|
||||
{}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block)))
|
||||
|
||||
====================================
|
||||
Empty block
|
||||
====================================
|
||||
|
||||
NR == 1
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
Block of block and statement
|
||||
====================================
|
||||
|
||||
{
|
||||
a
|
||||
{}
|
||||
a
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(identifier)
|
||||
(block)
|
||||
(identifier))))
|
||||
|
||||
====================================
|
||||
Directives
|
||||
====================================
|
||||
|
||||
@include "file1"
|
||||
@load "file2"
|
||||
@namespace "ns"
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(directive
|
||||
(string))
|
||||
(directive
|
||||
(string))
|
||||
(directive
|
||||
(string)))
|
||||
|
||||
====================================
|
||||
Line continuation
|
||||
====================================
|
||||
|
||||
\
|
||||
BEGIN {}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(pattern)
|
||||
(block)))
|
@@ -0,0 +1,746 @@
|
||||
====================================
|
||||
If statement block body
|
||||
====================================
|
||||
|
||||
{ if (x) {} }
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(block)))))
|
||||
|
||||
====================================
|
||||
If statement followed by newline
|
||||
====================================
|
||||
|
||||
{ if (x) {}
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(block)))))
|
||||
|
||||
====================================
|
||||
If statement statement body
|
||||
====================================
|
||||
|
||||
{ if (x) print x; }
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(print_statement
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
If statement no body
|
||||
====================================
|
||||
|
||||
{ if (x) ; }
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
If statement statement follow up
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) a = 1;
|
||||
a = 2;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
If statement followed by comment
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) a = "a" 2 # Comment
|
||||
b = 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(string_concat
|
||||
(string)
|
||||
(concatenating_space)
|
||||
(number))))
|
||||
(comment)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
If-else statement with blocks
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) {}
|
||||
else {}
|
||||
|
||||
if (1) {} else 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(block)
|
||||
(else_clause
|
||||
(block)))
|
||||
(if_statement
|
||||
(number)
|
||||
(block)
|
||||
(else_clause
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
If-else statement with statements
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) 1; else 2
|
||||
|
||||
if (1) 1;
|
||||
else 2
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(number)
|
||||
(else_clause
|
||||
(number)))
|
||||
(if_statement
|
||||
(number)
|
||||
(number)
|
||||
(else_clause
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
If-else with statement on newline
|
||||
====================================
|
||||
|
||||
{
|
||||
if (a)
|
||||
print 1;
|
||||
else if (b)
|
||||
print 2;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(print_statement
|
||||
(number))
|
||||
(else_clause
|
||||
(if_statement
|
||||
(identifier)
|
||||
(print_statement
|
||||
(number))))))))
|
||||
|
||||
====================================
|
||||
If-else separated by comment
|
||||
====================================
|
||||
|
||||
{
|
||||
if (a) a = 2;
|
||||
# Comment
|
||||
else a = 3;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(comment)
|
||||
(else_clause
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))))))
|
||||
|
||||
====================================
|
||||
If-else separated by multiline comment
|
||||
====================================
|
||||
|
||||
{
|
||||
if (a) a = 2;
|
||||
|
||||
# Comment
|
||||
|
||||
# Comment
|
||||
else a = 3;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(identifier)
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(comment)
|
||||
(comment)
|
||||
(else_clause
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number)))))))
|
||||
|
||||
====================================
|
||||
If-else-if statement
|
||||
====================================
|
||||
|
||||
{
|
||||
if (1) {}
|
||||
else if (2) {}
|
||||
|
||||
print;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(if_statement
|
||||
(number)
|
||||
(block)
|
||||
(else_clause
|
||||
(if_statement
|
||||
(number)
|
||||
(block))))
|
||||
(print_statement))))
|
||||
|
||||
====================================
|
||||
While statement statement body
|
||||
====================================
|
||||
|
||||
{
|
||||
while (1) print abc;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(while_statement
|
||||
(number)
|
||||
(print_statement
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
While statement block body
|
||||
====================================
|
||||
|
||||
{
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(while_statement
|
||||
(number)
|
||||
(block)))))
|
||||
|
||||
====================================
|
||||
Do-while statement block body
|
||||
====================================
|
||||
|
||||
{
|
||||
do {}
|
||||
while (1)
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(do_while_statement
|
||||
(block)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
Do-while statement statement body
|
||||
====================================
|
||||
|
||||
{
|
||||
do print
|
||||
while (1)
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(do_while_statement
|
||||
(print_statement)
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
For statement block body
|
||||
====================================
|
||||
|
||||
{
|
||||
for (x = 1; x <= 10; x++) {}
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(for_statement
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(update_exp
|
||||
(identifier))
|
||||
(block)))))
|
||||
|
||||
====================================
|
||||
For statement statement body
|
||||
====================================
|
||||
|
||||
{
|
||||
for (x = 1; x <= 10; x++) print x;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(for_statement
|
||||
(assignment_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(number))
|
||||
(update_exp
|
||||
(identifier))
|
||||
(print_statement
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
For-in statement statement body
|
||||
====================================
|
||||
|
||||
{
|
||||
for (x in arr) print x, arr[x];
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(for_in_statement
|
||||
(identifier)
|
||||
(identifier)
|
||||
(print_statement
|
||||
(exp_list
|
||||
(identifier)
|
||||
(array_ref
|
||||
(identifier)
|
||||
(identifier))))))))
|
||||
|
||||
====================================
|
||||
For-in statement block body
|
||||
====================================
|
||||
|
||||
{
|
||||
for (x in arr) {}
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(for_in_statement
|
||||
(identifier)
|
||||
(identifier)
|
||||
(block)))))
|
||||
|
||||
====================================
|
||||
For-in statement array reference
|
||||
====================================
|
||||
|
||||
{
|
||||
for (i in arr[t]) print i
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(for_in_statement
|
||||
(identifier)
|
||||
(array_ref
|
||||
(identifier)
|
||||
(identifier))
|
||||
(print_statement
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
Delete statement
|
||||
====================================
|
||||
|
||||
{
|
||||
delete arr[i];
|
||||
delete arr;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(delete_statement
|
||||
(array_ref
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(delete_statement
|
||||
(identifier)))))
|
||||
|
||||
====================================
|
||||
Exit statement
|
||||
====================================
|
||||
|
||||
{
|
||||
exit 1;
|
||||
exit 1 + 1;
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(exit_statement
|
||||
(number))
|
||||
(exit_statement
|
||||
(binary_exp
|
||||
(number)
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
Return statement no value
|
||||
====================================
|
||||
|
||||
{ return }
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(return_statement))))
|
||||
|
||||
====================================
|
||||
Return statement with value
|
||||
====================================
|
||||
|
||||
{ return 1; }
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(return_statement
|
||||
(number)))))
|
||||
|
||||
====================================
|
||||
Switch statement
|
||||
====================================
|
||||
|
||||
{
|
||||
switch(x) {
|
||||
case 1:
|
||||
case 2:
|
||||
case /[a-z]/:
|
||||
print x;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(switch_statement
|
||||
(identifier)
|
||||
(switch_body
|
||||
(switch_case
|
||||
(number))
|
||||
(switch_case
|
||||
(number))
|
||||
(switch_case
|
||||
(regex
|
||||
(regex_pattern))
|
||||
(print_statement
|
||||
(identifier))
|
||||
(break_statement))
|
||||
(switch_default
|
||||
(func_call
|
||||
(identifier))
|
||||
(break_statement)))))))
|
||||
|
||||
====================================
|
||||
Print statement
|
||||
====================================
|
||||
|
||||
{
|
||||
print "abc";
|
||||
print "abc", "a";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(print_statement
|
||||
(string))
|
||||
(print_statement
|
||||
(exp_list
|
||||
(string)
|
||||
(string))))))
|
||||
|
||||
====================================
|
||||
Print statement output redirection
|
||||
====================================
|
||||
|
||||
{
|
||||
print "abc" > "file";
|
||||
print "abc" >> "file";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(redirected_io_statement
|
||||
(print_statement
|
||||
(string))
|
||||
(string))
|
||||
(redirected_io_statement
|
||||
(print_statement
|
||||
(string))
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Print piped
|
||||
====================================
|
||||
|
||||
{
|
||||
print "abc" | "cat";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(piped_io_statement
|
||||
(print_statement
|
||||
(string))
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Print with grouping and string concat
|
||||
====================================
|
||||
|
||||
{
|
||||
print (a) b
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(print_statement
|
||||
(string_concat
|
||||
(grouping
|
||||
(identifier))
|
||||
(concatenating_space)
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
Print binary expression
|
||||
====================================
|
||||
|
||||
{
|
||||
print a + b
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(print_statement
|
||||
(binary_exp
|
||||
(identifier)
|
||||
(identifier))))))
|
||||
|
||||
====================================
|
||||
Printf statement
|
||||
====================================
|
||||
|
||||
{
|
||||
printf "%d", 42;
|
||||
printf("%d", 42);
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(printf_statement
|
||||
(exp_list
|
||||
(string)
|
||||
(number)))
|
||||
(printf_statement
|
||||
(exp_list
|
||||
(string)
|
||||
(number))))))
|
||||
|
||||
====================================
|
||||
Printf statement with getline
|
||||
====================================
|
||||
|
||||
{
|
||||
printf("cal" | getline);
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(printf_statement
|
||||
(piped_io_exp
|
||||
(string)
|
||||
(getline_input))))))
|
||||
|
||||
====================================
|
||||
Printf statement output redirection
|
||||
====================================
|
||||
|
||||
{
|
||||
printf "abc" > "file";
|
||||
printf("abc") >> "file";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(redirected_io_statement
|
||||
(printf_statement
|
||||
(string))
|
||||
(string))
|
||||
(redirected_io_statement
|
||||
(printf_statement
|
||||
(string))
|
||||
(string)))))
|
||||
|
||||
====================================
|
||||
Printf piped
|
||||
====================================
|
||||
|
||||
{
|
||||
printf("%s", "abc") | "cat";
|
||||
}
|
||||
|
||||
------------------------------------
|
||||
|
||||
(program
|
||||
(rule
|
||||
(block
|
||||
(piped_io_statement
|
||||
(printf_statement
|
||||
(exp_list
|
||||
(string)
|
||||
(string)))
|
||||
(string)))))
|
18
dot_config/helix/runtime/grammars/sources/awk/yarn.lock
Normal file
18
dot_config/helix/runtime/grammars/sources/awk/yarn.lock
Normal file
@@ -0,0 +1,18 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
nan@2.14.2:
|
||||
version "2.14.2"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
|
||||
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
|
||||
|
||||
prettier@2.3.2:
|
||||
version "2.3.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
|
||||
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
|
||||
|
||||
tree-sitter-cli@0.20.6:
|
||||
version "0.20.6"
|
||||
resolved "https://registry.yarnpkg.com/tree-sitter-cli/-/tree-sitter-cli-0.20.6.tgz#2a7202190d7bd64e112b451f94573dbe40a04f04"
|
||||
integrity sha512-tjbAeuGSMhco/EnsThjWkQbDIYMDmdkWsTPsa/NJAW7bjaki9P7oM9TkLxfdlnm4LXd1wR5wVSM2/RTLtZbm6A==
|
Reference in New Issue
Block a user