Initial commit

This commit is contained in:
TudbuT 2023-05-24 21:48:37 +02:00 committed by TudbuT
commit 6b6fe25262
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
14 changed files with 5490 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
Cargo.lock
node_modules
build
*.log
package-lock.json
/target/
.build/

26
Cargo.toml Normal file
View file

@ -0,0 +1,26 @@
[package]
name = "tree-sitter-SPL"
description = "SPL grammar for the tree-sitter parsing library"
version = "0.0.1"
keywords = ["incremental", "parsing", "SPL"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-SPL"
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.10"
[build-dependencies]
cc = "1.0"

19
binding.gyp Normal file
View file

@ -0,0 +1,19 @@
{
"targets": [
{
"target_name": "tree_sitter_SPL_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.
],
"cflags_c": [
"-std=c99",
]
}
]
}

28
bindings/node/binding.cc Normal file
View file

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_SPL();
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_SPL());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("SPL").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_SPL_binding, Init)
} // namespace

19
bindings/node/index.js Normal file
View file

@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_SPL_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_SPL_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

40
bindings/rust/build.rs Normal file
View file

@ -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());
*/
}

52
bindings/rust/lib.rs Normal file
View file

@ -0,0 +1,52 @@
//! This crate provides SPL 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_SPL::language()).expect("Error loading SPL 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_SPL() -> 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_SPL() }
}
/// 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 SPL language");
}
}

117
grammar.js Normal file
View file

@ -0,0 +1,117 @@
module.exports = grammar({
name: 'SPL',
rules: {
source_file: $ => repeat($._statement),
_statement: $ => seq(
choice(
$.string,
$.function_definition,
$.type_definition,
$.with_expr,
$.array,
$.if,
$.while,
$.catch,
$.use,
$.include,
$.def,
$.number,
$.expression,
seq(
repeat('&'),
$.call
),
),
optional(';'),
$._spacing,
),
function_definition: $ => choice($.func, $.block),
func: $ => seq(
'func', $._spacing,
$.identifier, $._spacing,
$.block,
),
block: $ => seq(
'{', $._spacing, repeat(seq(/[^ \n\r\t|]+/, $._spacing)), '|',
repeat($._statement),
'}',
),
identifier: $ => /[^ \n\r\t:;&{}"']+/,
call: $ => seq(
choice(
seq(
optional($.call),
':',
$.identifier,
),
$.identifier,
),
),
number: $ => /\d+(\.\d+)?/,
string: $ => seq('"', repeat(choice(/\\./, /./)), '"'),
expression: $ => seq('<{', $._spacing, repeat($._statement), '}'),
with_expr: $ => seq(
'with', $._spacing,
repeat($.identifier),
';',
),
array: $ => seq('[', $._spacing, repeat($._statement), ']'),
operation: $ => /[+\-*\/%&]/,
variable: $ => choice(
seq('def', $._spacing, $.identifier),
seq('=', $.identifier),
),
type_definition: $ => seq(
'construct', $._spacing,
$.call, $._spacing,
optional(seq('namespace', $._spacing)),
'{', $._spacing,
repeat(seq($.identifier, $._spacing)),
optional(seq(
';',
repeat(seq($.identifier, $.block, $._spacing)),
)),
'}',
),
_spacing: $ => /[ \n\r\t]+/,
if: $ => seq(
'if', $._spacing,
'{', $._spacing,
repeat($._statement),
'}',
),
while: $ => seq(
'while', $._spacing,
'{', $._spacing,
repeat($._statement),
'}', $._spacing,
'{', $._spacing,
repeat($._statement),
'}',
),
catch: $ => seq(
'catch', $._spacing,
'{', $._spacing,
repeat($._statement),
'}', $._spacing,
'{', $._spacing,
repeat($._statement),
'}',
),
include: $ => seq(
'include', $.identifier, $._spacing,
'in', $.identifier,
),
use: $ => seq(
'use', $._spacing,
$.call,
),
def: $ => seq(
'def', $._spacing,
$.identifier,
),
},
});

35
package.json Normal file
View file

@ -0,0 +1,35 @@
{
"name": "tree-sitter-spl",
"version": "1.0.0",
"description": "",
"main": "bindings/node",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tudbut/tree-sitter-spl.git"
},
"author": "TudbuT",
"license": "MIT",
"bugs": {
"url": "https://github.com/tudbut/tree-sitter-spl/issues"
},
"homepage": "https://github.com/tudbut/tree-sitter-spl#readme",
"dependencies": {
"nan": "^2.17.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
{
"scope": "source.spl",
"injection-regex": "spl",
"file-types": [
"spl",
"sbl"
]
}
]
}

15
queries/highlights.scm Normal file
View file

@ -0,0 +1,15 @@
[
"construct" "namespace"
"func"
"def"
"with"
"while"
"if"
"catch"
"include" "in"
"use"
] @keyword
(number) @number
(string) @string
(call (call) @function (identifier) @property)

699
src/grammar.json Normal file
View file

@ -0,0 +1,699 @@
{
"name": "SPL",
"rules": {
"source_file": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
"_statement": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "function_definition"
},
{
"type": "SYMBOL",
"name": "type_definition"
},
{
"type": "SYMBOL",
"name": "with_expr"
},
{
"type": "SYMBOL",
"name": "array"
},
{
"type": "SYMBOL",
"name": "if"
},
{
"type": "SYMBOL",
"name": "while"
},
{
"type": "SYMBOL",
"name": "catch"
},
{
"type": "SYMBOL",
"name": "use"
},
{
"type": "SYMBOL",
"name": "include"
},
{
"type": "SYMBOL",
"name": "def"
},
{
"type": "SYMBOL",
"name": "number"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": "&"
}
},
{
"type": "SYMBOL",
"name": "call"
}
]
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
},
"function_definition": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "func"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"func": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "func"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"block": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^ \\n\\r\\t|]+"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
}
},
{
"type": "STRING",
"value": "|"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"identifier": {
"type": "PATTERN",
"value": "[^ \\n\\r\\t:;&{}\"']+"
},
"call": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "call"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
},
"number": {
"type": "PATTERN",
"value": "\\d+(\\.\\d+)?"
},
"string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\\\."
},
{
"type": "PATTERN",
"value": "."
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"with_expr": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "with"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ";"
}
]
},
"array": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "]"
}
]
},
"operation": {
"type": "PATTERN",
"value": "[+\\-*\\/%&]"
},
"variable": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "def"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
},
"type_definition": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "construct"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "call"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "namespace"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"_spacing": {
"type": "PATTERN",
"value": "[ \\n\\r\\t]+"
},
"if": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"while": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "while"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"catch": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "catch"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_statement"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"include": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "include"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
"use": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "use"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "call"
}
]
},
"def": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "def"
},
{
"type": "SYMBOL",
"name": "_spacing"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
"extras": [
{
"type": "PATTERN",
"value": "\\s"
}
],
"conflicts": [],
"precedences": [],
"externals": [],
"inline": [],
"supertypes": []
}

712
src/node-types.json Normal file
View file

@ -0,0 +1,712 @@
[
{
"type": "array",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "block",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "call",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "call",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "catch",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "def",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "expression",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "func",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "function_definition",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "func",
"named": true
}
]
}
},
{
"type": "if",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "include",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "source_file",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "string",
"named": true,
"fields": {}
},
{
"type": "type_definition",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "use",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "call",
"named": true
}
]
}
},
{
"type": "while",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "call",
"named": true
},
{
"type": "catch",
"named": true
},
{
"type": "def",
"named": true
},
{
"type": "expression",
"named": true
},
{
"type": "function_definition",
"named": true
},
{
"type": "if",
"named": true
},
{
"type": "include",
"named": true
},
{
"type": "number",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "type_definition",
"named": true
},
{
"type": "use",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "with_expr",
"named": true
}
]
}
},
{
"type": "with_expr",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "\"",
"named": false
},
{
"type": "&",
"named": false
},
{
"type": ":",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<{",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "catch",
"named": false
},
{
"type": "construct",
"named": false
},
{
"type": "def",
"named": false
},
{
"type": "func",
"named": false
},
{
"type": "identifier",
"named": true
},
{
"type": "if",
"named": false
},
{
"type": "in",
"named": false
},
{
"type": "include",
"named": false
},
{
"type": "namespace",
"named": false
},
{
"type": "number",
"named": true
},
{
"type": "use",
"named": false
},
{
"type": "while",
"named": false
},
{
"type": "with",
"named": false
},
{
"type": "{",
"named": false
},
{
"type": "|",
"named": false
},
{
"type": "}",
"named": false
}
]

3497
src/parser.c Normal file

File diff suppressed because it is too large Load diff

224
src/tree_sitter/parser.h Normal file
View file

@ -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_