mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 05:43:53 +01:00
add experimental tree-sitter grammar
This commit is contained in:
parent
0a9eea2045
commit
c8431cab93
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
**/target/
|
||||
**/Cargo.lock
|
||||
tree-sitter-mers/log.html
|
||||
tree-sitter-mers/package-lock.json
|
||||
tree-sitter-mers/node_modules
|
||||
|
26
tree-sitter-mers/Cargo.toml
Normal file
26
tree-sitter-mers/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "tree-sitter-mers"
|
||||
description = "mers grammar for the tree-sitter parsing library"
|
||||
version = "0.0.1"
|
||||
keywords = ["incremental", "parsing", "mers"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-mers"
|
||||
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
tree-sitter-mers/binding.gyp
Normal file
19
tree-sitter-mers/binding.gyp
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_mers_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
tree-sitter-mers/bindings/node/binding.cc
Normal file
28
tree-sitter-mers/bindings/node/binding.cc
Normal file
@ -0,0 +1,28 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_mers();
|
||||
|
||||
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_mers());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("mers").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_mers_binding, Init)
|
||||
|
||||
} // namespace
|
19
tree-sitter-mers/bindings/node/index.js
Normal file
19
tree-sitter-mers/bindings/node/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_mers_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_mers_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
40
tree-sitter-mers/bindings/rust/build.rs
Normal file
40
tree-sitter-mers/bindings/rust/build.rs
Normal 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
tree-sitter-mers/bindings/rust/lib.rs
Normal file
52
tree-sitter-mers/bindings/rust/lib.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! This crate provides mers 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_mers::language()).expect("Error loading mers 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_mers() -> 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_mers() }
|
||||
}
|
||||
|
||||
/// 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 mers language");
|
||||
}
|
||||
}
|
113
tree-sitter-mers/grammar.js
Normal file
113
tree-sitter-mers/grammar.js
Normal file
@ -0,0 +1,113 @@
|
||||
module.exports = grammar({
|
||||
name: 'mers',
|
||||
rules: {
|
||||
source_file: $ => repeat($.definition),
|
||||
definition: $ => choice(
|
||||
$.init,
|
||||
$.assign,
|
||||
$.if,
|
||||
$.func,
|
||||
$.block,
|
||||
$.tuple,
|
||||
$.chain,
|
||||
$.string,
|
||||
$.number,
|
||||
$.variable,
|
||||
),
|
||||
definition_in_chain: $ => choice(
|
||||
$.block,
|
||||
$.tuple,
|
||||
$.string,
|
||||
$.number,
|
||||
$.variable,
|
||||
),
|
||||
definition_initable: $ => choice(
|
||||
$.variable,
|
||||
$.tuple,
|
||||
),
|
||||
definition_assignable: $ => choice(
|
||||
$.variable,
|
||||
$.tuple,
|
||||
$.block,
|
||||
$.string,
|
||||
$.number,
|
||||
),
|
||||
|
||||
block: $ => seq(
|
||||
$.block_start,
|
||||
repeat($.definition),
|
||||
$.block_end
|
||||
),
|
||||
block_start: $ => '{',
|
||||
block_end: $ => '}',
|
||||
|
||||
if: $ => prec.left(seq(
|
||||
$.if_if,
|
||||
$.definition,
|
||||
$.definition,
|
||||
optional(seq(
|
||||
$.if_else,
|
||||
$.definition
|
||||
))
|
||||
)),
|
||||
if_if: $ => 'if',
|
||||
if_else: $ => 'else',
|
||||
|
||||
func: $ => seq(
|
||||
$.func_arg,
|
||||
$.func_arrow,
|
||||
$.func_body
|
||||
),
|
||||
func_arg: $ => $.definition_assignable,
|
||||
func_arrow: $ => '->',
|
||||
func_body: $ => $.definition,
|
||||
|
||||
init: $ => seq(
|
||||
$.init_to,
|
||||
$.init_colonequals,
|
||||
$.init_source,
|
||||
),
|
||||
init_to: $ => $.definition_initable,
|
||||
init_colonequals: $ => ':=',
|
||||
init_source: $ => $.definition,
|
||||
|
||||
assign: $ => seq(
|
||||
$.assign_to,
|
||||
$.assign_equals,
|
||||
$.assign_source,
|
||||
),
|
||||
assign_to: $ => $.definition_assignable,
|
||||
assign_equals: $ => '=',
|
||||
assign_source: $ => $.definition,
|
||||
|
||||
tuple: $ => seq(
|
||||
$.tuple_start,
|
||||
repeat(seq(
|
||||
$.definition,
|
||||
$.tuple_separator
|
||||
)),
|
||||
$.tuple_end
|
||||
),
|
||||
tuple_start: $ => '(',
|
||||
tuple_end: $ => ')',
|
||||
tuple_separator: $ => /(,\s*)|\s+/,
|
||||
|
||||
chain: $ => seq(
|
||||
$.chain_dot,
|
||||
$.definition_in_chain,
|
||||
),
|
||||
chain_dot: $ => '.',
|
||||
|
||||
number: $ => /[\+-]?(\d+)|(\d+\.\d+)/,
|
||||
|
||||
variable: $ => /&?[^\s:=\.\{\}\[\]\(\)\d"]+/,
|
||||
|
||||
string: $ => seq(
|
||||
'"',
|
||||
$.string_content,
|
||||
'"'
|
||||
),
|
||||
string_content: $ => /([^\\"]|[\\.])+/,
|
||||
|
||||
}
|
||||
})
|
18
tree-sitter-mers/package.json
Normal file
18
tree-sitter-mers/package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "tree-sitter-mers",
|
||||
"version": "1.0.0",
|
||||
"description": "tree-sitter syntax highlighting for mers",
|
||||
"main": "bindings/node",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"nan": "^2.18.0"
|
||||
},
|
||||
"tree-sitter": [{
|
||||
"scope": "source.mers",
|
||||
"file-types": ["mers"]
|
||||
}]
|
||||
}
|
14
tree-sitter-mers/queries/highlights.scm
Normal file
14
tree-sitter-mers/queries/highlights.scm
Normal file
@ -0,0 +1,14 @@
|
||||
(string) @string
|
||||
(variable) @variable
|
||||
(number) @number
|
||||
(chain_dot) @punctuation.delimeter
|
||||
|
||||
(if_if) @keyword.control.conditional
|
||||
(if_else) @keyword.control.conditional
|
||||
|
||||
(func_arrow) @function
|
||||
|
||||
(block_start) @punctuation.bracket
|
||||
(block_end) @punctuation.bracket
|
||||
(tuple_start) @punctuation.bracket
|
||||
(tuple_end) @punctuation.bracket
|
384
tree-sitter-mers/src/grammar.json
Normal file
384
tree-sitter-mers/src/grammar.json
Normal file
@ -0,0 +1,384 @@
|
||||
{
|
||||
"name": "mers",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
}
|
||||
},
|
||||
"definition": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "init"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assign"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "if"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "func"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "chain"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "number"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
}
|
||||
]
|
||||
},
|
||||
"definition_in_chain": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "number"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
}
|
||||
]
|
||||
},
|
||||
"definition_initable": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple"
|
||||
}
|
||||
]
|
||||
},
|
||||
"definition_assignable": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "number"
|
||||
}
|
||||
]
|
||||
},
|
||||
"block": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block_start"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block_end"
|
||||
}
|
||||
]
|
||||
},
|
||||
"block_start": {
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
"block_end": {
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
},
|
||||
"if": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "if_if"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "if_else"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"if_if": {
|
||||
"type": "STRING",
|
||||
"value": "if"
|
||||
},
|
||||
"if_else": {
|
||||
"type": "STRING",
|
||||
"value": "else"
|
||||
},
|
||||
"func": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "func_arg"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "func_arrow"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "func_body"
|
||||
}
|
||||
]
|
||||
},
|
||||
"func_arg": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition_assignable"
|
||||
},
|
||||
"func_arrow": {
|
||||
"type": "STRING",
|
||||
"value": "->"
|
||||
},
|
||||
"func_body": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
"init": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "init_to"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "init_colonequals"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "init_source"
|
||||
}
|
||||
]
|
||||
},
|
||||
"init_to": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition_initable"
|
||||
},
|
||||
"init_colonequals": {
|
||||
"type": "STRING",
|
||||
"value": ":="
|
||||
},
|
||||
"init_source": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
"assign": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assign_to"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assign_equals"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assign_source"
|
||||
}
|
||||
]
|
||||
},
|
||||
"assign_to": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition_assignable"
|
||||
},
|
||||
"assign_equals": {
|
||||
"type": "STRING",
|
||||
"value": "="
|
||||
},
|
||||
"assign_source": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
"tuple": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple_start"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple_separator"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple_end"
|
||||
}
|
||||
]
|
||||
},
|
||||
"tuple_start": {
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
"tuple_end": {
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
},
|
||||
"tuple_separator": {
|
||||
"type": "PATTERN",
|
||||
"value": "(,\\s*)|\\s+"
|
||||
},
|
||||
"chain": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "chain_dot"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition_in_chain"
|
||||
}
|
||||
]
|
||||
},
|
||||
"chain_dot": {
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
"number": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\+-]?(\\d+)|(\\d+\\.\\d+)"
|
||||
},
|
||||
"variable": {
|
||||
"type": "PATTERN",
|
||||
"value": "&?[^\\s:=\\.\\{\\}\\[\\]\\(\\)\\d\"]+"
|
||||
},
|
||||
"string": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string_content"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
}
|
||||
]
|
||||
},
|
||||
"string_content": {
|
||||
"type": "PATTERN",
|
||||
"value": "([^\\\\\"]|[\\\\.])+"
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
"precedences": [],
|
||||
"externals": [],
|
||||
"inline": [],
|
||||
"supertypes": []
|
||||
}
|
||||
|
475
tree-sitter-mers/src/node-types.json
Normal file
475
tree-sitter-mers/src/node-types.json
Normal file
@ -0,0 +1,475 @@
|
||||
[
|
||||
{
|
||||
"type": "assign",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "assign_equals",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "assign_source",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "assign_to",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "assign_source",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "assign_to",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition_assignable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "block",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block_end",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_start",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chain",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "chain_dot",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "definition_in_chain",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "assign",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "chain",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "func",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "init",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "definition_assignable",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "definition_in_chain",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "definition_initable",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "tuple",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "func",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "func_arg",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "func_arrow",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "func_body",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "func_arg",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition_assignable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "func_body",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_else",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_if",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "init",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "init_colonequals",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "init_source",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "init_to",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "init_source",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "init_to",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition_initable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "string_content",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "tuple",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_end",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_separator",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_start",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "\"",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "assign_equals",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_end",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_start",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "chain_dot",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "func_arrow",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_else",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_if",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "init_colonequals",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_content",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_end",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_separator",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_start",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
3215
tree-sitter-mers/src/parser.c
Normal file
3215
tree-sitter-mers/src/parser.c
Normal file
File diff suppressed because it is too large
Load Diff
224
tree-sitter-mers/src/tree_sitter/parser.h
Normal file
224
tree-sitter-mers/src/tree_sitter/parser.h
Normal 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_
|
8
tree-sitter-mers/test.mers
Normal file
8
tree-sitter-mers/test.mers
Normal file
@ -0,0 +1,8 @@
|
||||
(my_arg, some_flag) -> {
|
||||
x := "test"
|
||||
if some_flag {
|
||||
my_arg.println
|
||||
} else {
|
||||
x.println
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user