mirror of https://github.com/Wilfred/difftastic/
Unvendor tree-sitter-elisp
parent
5b28c34eea
commit
4ea2b23203
@ -1 +0,0 @@
|
||||
../tree-sitter-elisp/queries/highlights.scm
|
||||
@ -0,0 +1,74 @@
|
||||
;; Source: https://github.com/Wilfred/tree-sitter-elisp/blob/main/queries/highlights.scm
|
||||
|
||||
;; Special forms
|
||||
[
|
||||
"and"
|
||||
"catch"
|
||||
"cond"
|
||||
"condition-case"
|
||||
"defconst"
|
||||
"defvar"
|
||||
"function"
|
||||
"if"
|
||||
"interactive"
|
||||
"lambda"
|
||||
"let"
|
||||
"let*"
|
||||
"or"
|
||||
"prog1"
|
||||
"prog2"
|
||||
"progn"
|
||||
"quote"
|
||||
"save-current-buffer"
|
||||
"save-excursion"
|
||||
"save-restriction"
|
||||
"setq"
|
||||
"setq-default"
|
||||
"unwind-protect"
|
||||
"while"
|
||||
] @keyword
|
||||
|
||||
;; Function definitions
|
||||
[
|
||||
"defun"
|
||||
"defsubst"
|
||||
] @keyword
|
||||
(function_definition name: (symbol) @function)
|
||||
(function_definition parameters: (list (symbol) @variable.parameter))
|
||||
(function_definition docstring: (string) @comment)
|
||||
|
||||
;; Highlight macro definitions the same way as function definitions.
|
||||
"defmacro" @keyword
|
||||
(macro_definition name: (symbol) @function)
|
||||
(macro_definition parameters: (list (symbol) @variable.parameter))
|
||||
(macro_definition docstring: (string) @comment)
|
||||
|
||||
(comment) @comment
|
||||
|
||||
(integer) @number
|
||||
(float) @number
|
||||
(char) @number
|
||||
|
||||
(string) @string
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"#["
|
||||
"["
|
||||
"]"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
"`"
|
||||
"#'"
|
||||
"'"
|
||||
","
|
||||
",@"
|
||||
] @operator
|
||||
|
||||
;; Highlight nil and t as constants, unlike other symbols
|
||||
[
|
||||
"nil"
|
||||
"t"
|
||||
] @constant.builtin
|
||||
@ -1 +0,0 @@
|
||||
tree-sitter-elisp/src
|
||||
@ -1,26 +0,0 @@
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [15.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm run build --if-present
|
||||
- run: npm test
|
||||
@ -1,3 +0,0 @@
|
||||
node_modules
|
||||
build
|
||||
target
|
||||
@ -1,43 +0,0 @@
|
||||
# v1.3 (unreleased)
|
||||
|
||||
Don't error on quoted forms that look like function definitions (such
|
||||
as `'(defun foo)`).
|
||||
|
||||
# v1.2
|
||||
|
||||
Added some basic syntax highlighting support ("queries" in tree-sitter
|
||||
terms).
|
||||
|
||||
Function definitions are now handled separately from other
|
||||
s-expressions. Added highlighting and tags table queries for function
|
||||
definitions.
|
||||
|
||||
Macros are also handled separately to other s-expressions. They are
|
||||
treated the same as functions for highlighting and tags tables.
|
||||
|
||||
Special forms are now parsed and highlighted separately from
|
||||
s-expressions.
|
||||
|
||||
Added highlighting for `nil` and `t`.
|
||||
|
||||
# v1.1
|
||||
|
||||
Added support for more special read syntax.
|
||||
|
||||
Added support for bytecode literals.
|
||||
|
||||
Linefeed characters (commonly used as section delimiters) are now treated
|
||||
as whitespace rather than parse errors.
|
||||
|
||||
Fixed handling of string literals with newline escaping:
|
||||
|
||||
```
|
||||
"foo\
|
||||
bar"
|
||||
```
|
||||
|
||||
Fixed handling escaped characters and non-ASCII character in symbols.
|
||||
|
||||
# v1.0
|
||||
|
||||
Initial release.
|
||||
@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "tree-sitter-elisp"
|
||||
description = "elisp grammar for the tree-sitter parsing library"
|
||||
version = "1.3.0"
|
||||
keywords = ["incremental", "parsing", "elisp"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-elisp"
|
||||
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"
|
||||
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Wilfred Hughes
|
||||
|
||||
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.
|
||||
@ -1,88 +0,0 @@
|
||||
# Tree-sitter Grammar for Emacs Lisp
|
||||
|
||||
A simple tree-sitter grammar for elisp.
|
||||
|
||||
Syntax supported:
|
||||
|
||||
* Atoms (integers, floats, strings, characters, symbols)
|
||||
* Lists (normal syntax `(a b)` and dotted `(a . b)`)
|
||||
* Vectors
|
||||
* Quoting and unquoting (`'`, `#'`, `` ` ``, `,`, `,@`)
|
||||
* Some special read syntax (`$#`, `##`, `#("foo" 1 2 x)`)
|
||||
* Bytecode literals (`#[1 2 3 4]`)
|
||||
* Special forms (`let` etc)
|
||||
* Comments
|
||||
|
||||
Currently unsupported:
|
||||
|
||||
* Autoload cookies
|
||||
* Definitions (e.g. `defun`, `defvar`, `defmacro`)
|
||||
|
||||
## Limitations
|
||||
|
||||
Elisp is a lisp-2 with user-defined macros. A simple parser cannot
|
||||
detect if e.g. `(foo (let ...))` is a function call with a `let`
|
||||
expression argument, or a macro call where `let` means something else.
|
||||
|
||||
Currently tree-sitter-elisp treats everything as an s-expression. This
|
||||
is accurate, but makes this package less useful for generating a
|
||||
summary of file contents, or for syntax highlighting.
|
||||
|
||||
Emacs itself has more information that it can use. Emacs will
|
||||
highlight macro calls based on which macros are defined in the current
|
||||
instance. Some elisp packages also offer custom highlighting logic,
|
||||
such as `dash-fontify-mode` in
|
||||
[dash.el](https://github.com/magnars/dash.el).
|
||||
|
||||
## Developing
|
||||
|
||||
Check out the repo, then use `npm` to install dependencies.
|
||||
|
||||
```
|
||||
$ npm install
|
||||
```
|
||||
|
||||
You can then parse your favourite elisp files.
|
||||
|
||||
```
|
||||
$ npm run parse ~/.emacs.d/init.el
|
||||
```
|
||||
|
||||
The grammar itself is in
|
||||
[grammar.js](https://github.com/Wilfred/tree-sitter-elisp/blob/main/grammar.js). You'll
|
||||
need to regenerate the code after editing the grammar.
|
||||
|
||||
```
|
||||
$ npm run generate
|
||||
```
|
||||
|
||||
This project also contains a few tests.
|
||||
|
||||
```
|
||||
$ npm test
|
||||
```
|
||||
|
||||
You can also run this parser against your `.emacs.d` to confirm it can
|
||||
parse everything.
|
||||
|
||||
```
|
||||
$ npm run parse -- '/home/wilfred/.emacs.d/**/*.el' --quiet --stat
|
||||
```
|
||||
|
||||
## Why?
|
||||
|
||||
The best place to read and write elisp is of course Emacs.
|
||||
|
||||
However, there is a growing ecosystem of tools built on top of
|
||||
tree-sitter, such as GitHub. This project should allow them to support
|
||||
emacs lisp too.
|
||||
|
||||
## Related Projects
|
||||
|
||||
[tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure)
|
||||
is another tree-sitter package for the lisp family. It's a useful
|
||||
project to compare with, and [has notes discussing lisp-specific
|
||||
challenges](https://github.com/sogaiu/tree-sitter-clojure/blob/master/doc/scope.md).
|
||||
|
||||
[language-emacs-lisp](https://github.com/Alhadis/language-emacs-lisp)
|
||||
is a textmate grammar for elisp that's used for Atom and GitHub.
|
||||
@ -1,19 +0,0 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_elisp_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",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_elisp();
|
||||
|
||||
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_elisp());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("elisp").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_elisp_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -1,19 +0,0 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_elisp_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== "MODULE_NOT_FOUND") {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_elisp_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== "MODULE_NOT_FOUND") {
|
||||
throw error2;
|
||||
}
|
||||
throw error1;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -1,40 +0,0 @@
|
||||
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());
|
||||
*/
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
//! This crate provides elisp 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_elisp::language()).expect("Error loading elisp 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_elisp() -> 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_elisp() }
|
||||
}
|
||||
|
||||
/// 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 elisp language");
|
||||
}
|
||||
}
|
||||
@ -1,191 +0,0 @@
|
||||
const COMMENT = token(/;.*/);
|
||||
|
||||
const STRING = token(
|
||||
seq('"', repeat(choice(/[^"\\]/, seq("\\", /(.|\n)/))), '"')
|
||||
);
|
||||
|
||||
// Symbols can contain any character when escaped:
|
||||
// https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Type.html
|
||||
// Most characters do not need escaping, but space and parentheses
|
||||
// certainly do.
|
||||
//
|
||||
// Symbols also cannot start with ?.
|
||||
const SYMBOL = token(
|
||||
/([^?# \n\s\f()\[\]'`,\\";]|\\.)([^# \n\s\f()\[\]'`,\\";]|\\.)*/
|
||||
);
|
||||
|
||||
const ESCAPED_READER_SYMBOL = token(/\\(`|'|,)/);
|
||||
const INTERNED_EMPTY_STRING = token("##");
|
||||
|
||||
const INTEGER_BASE10 = token(/[+-]?[0-9]+\.?/);
|
||||
const INTEGER_WITH_BASE = token(/#([box]|[0-9][0-9]?r)[0-9a-zA-Z]/);
|
||||
|
||||
const FLOAT_WITH_DEC_POINT = token(/[+-]?[0-9]*\.[0-9]+/);
|
||||
const FLOAT_WITH_EXPONENT = token(/[+-]?[0-9]+[eE][0-9]+/);
|
||||
const FLOAT_WITH_BOTH = token(/[+-]?[0-9]*\.[0-9]+[eE][0-9]+/);
|
||||
const FLOAT_INF = token(/-?1.0[eE]\+INF/);
|
||||
const FLOAT_NAN = token(/-?0.0[eE]\+NaN/);
|
||||
|
||||
const CHAR = token(/\?(\\.|.)/);
|
||||
const UNICODE_NAME_CHAR = token(/\?\\N\{[^}]+\}/);
|
||||
const LOWER_CODE_POINT_CHAR = token(/\?\\u[0-9a-fA-F]{4}/);
|
||||
const UPPER_CODE_POINT_CHAR = token(/\?\\U[0-9a-fA-F]{8}/);
|
||||
const HEX_CHAR = token(/\?\\x[0-9a-fA-F]+/);
|
||||
const OCTAL_CHAR = token(/\?\\[0-7]{1,3}/);
|
||||
|
||||
// E.g. ?\C-o or ?\^o or ?\C-\S-o
|
||||
const KEY_CHAR = token(/\?(\\(([CMSHsA]-)|\^))+(\\;|.)/);
|
||||
// E.g. ?\M-\123
|
||||
const META_OCTAL_CHAR = token(/\?\\M-\\[0-9]{1,3}/);
|
||||
|
||||
// https://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Read-Syntax.html
|
||||
const BYTE_COMPILED_FILE_NAME = token("#$");
|
||||
|
||||
module.exports = grammar({
|
||||
name: "elisp",
|
||||
|
||||
extras: ($) => [/(\s|\f)/, $.comment],
|
||||
|
||||
rules: {
|
||||
source_file: ($) => repeat($._sexp),
|
||||
|
||||
_sexp: ($) =>
|
||||
choice(
|
||||
$.special_form,
|
||||
$.function_definition,
|
||||
$.macro_definition,
|
||||
$.list,
|
||||
$.vector,
|
||||
$.hash_table,
|
||||
$.bytecode,
|
||||
$.string_text_properties,
|
||||
$._atom,
|
||||
$.quote,
|
||||
$.unquote_splice,
|
||||
$.unquote
|
||||
),
|
||||
|
||||
special_form: ($) =>
|
||||
seq(
|
||||
"(",
|
||||
choice(
|
||||
"and",
|
||||
"catch",
|
||||
"cond",
|
||||
"condition-case",
|
||||
"defconst",
|
||||
"defvar",
|
||||
"function",
|
||||
"if",
|
||||
"interactive",
|
||||
"lambda",
|
||||
"let",
|
||||
"let*",
|
||||
"or",
|
||||
"prog1",
|
||||
"prog2",
|
||||
"progn",
|
||||
"quote",
|
||||
"save-current-buffer",
|
||||
"save-excursion",
|
||||
"save-restriction",
|
||||
"setq",
|
||||
"setq-default",
|
||||
"unwind-protect",
|
||||
"while"
|
||||
),
|
||||
repeat($._sexp),
|
||||
")"
|
||||
),
|
||||
|
||||
function_definition: ($) =>
|
||||
prec(
|
||||
1,
|
||||
seq(
|
||||
"(",
|
||||
choice("defun", "defsubst"),
|
||||
field("name", $.symbol),
|
||||
optional(field("parameters", $._sexp)),
|
||||
optional(field("docstring", $.string)),
|
||||
repeat($._sexp),
|
||||
")"
|
||||
)
|
||||
),
|
||||
|
||||
macro_definition: ($) =>
|
||||
prec(
|
||||
1,
|
||||
seq(
|
||||
"(",
|
||||
"defmacro",
|
||||
field("name", $.symbol),
|
||||
optional(field("parameters", $._sexp)),
|
||||
optional(field("docstring", $.string)),
|
||||
repeat($._sexp),
|
||||
")"
|
||||
)
|
||||
),
|
||||
|
||||
_atom: ($) =>
|
||||
choice(
|
||||
$.float,
|
||||
$.integer,
|
||||
$.char,
|
||||
$.string,
|
||||
$.byte_compiled_file_name,
|
||||
$.symbol
|
||||
),
|
||||
float: ($) =>
|
||||
choice(
|
||||
FLOAT_WITH_DEC_POINT,
|
||||
FLOAT_WITH_EXPONENT,
|
||||
FLOAT_WITH_BOTH,
|
||||
FLOAT_INF,
|
||||
FLOAT_NAN
|
||||
),
|
||||
integer: ($) => choice(INTEGER_BASE10, INTEGER_WITH_BASE),
|
||||
char: ($) =>
|
||||
choice(
|
||||
CHAR,
|
||||
UNICODE_NAME_CHAR,
|
||||
LOWER_CODE_POINT_CHAR,
|
||||
UPPER_CODE_POINT_CHAR,
|
||||
HEX_CHAR,
|
||||
OCTAL_CHAR,
|
||||
KEY_CHAR,
|
||||
META_OCTAL_CHAR
|
||||
),
|
||||
string: ($) => STRING,
|
||||
byte_compiled_file_name: ($) => BYTE_COMPILED_FILE_NAME,
|
||||
symbol: ($) =>
|
||||
choice(
|
||||
// Match nil and t separately so we can highlight them.
|
||||
"nil",
|
||||
"t",
|
||||
// We need to define these as separate tokens so we can handle
|
||||
// e.g '(defun) as a sexp. Without these, we just try
|
||||
// function_definition and produce a parse failure.
|
||||
"defun",
|
||||
"defsubst",
|
||||
"defmacro",
|
||||
ESCAPED_READER_SYMBOL,
|
||||
SYMBOL,
|
||||
INTERNED_EMPTY_STRING
|
||||
),
|
||||
|
||||
quote: ($) => seq(choice("#'", "'", "`"), $._sexp),
|
||||
unquote_splice: ($) => seq(",@", $._sexp),
|
||||
unquote: ($) => seq(",", $._sexp),
|
||||
|
||||
dot: ($) => token("."),
|
||||
list: ($) => seq("(", choice(repeat($._sexp)), ")"),
|
||||
vector: ($) => seq("[", repeat($._sexp), "]"),
|
||||
bytecode: ($) => seq("#[", repeat($._sexp), "]"),
|
||||
|
||||
string_text_properties: ($) => seq("#(", $.string, repeat($._sexp), ")"),
|
||||
|
||||
hash_table: ($) => seq("#s(hash-table", repeat($._sexp), ")"),
|
||||
|
||||
comment: ($) => COMMENT,
|
||||
},
|
||||
});
|
||||
@ -1,46 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-elisp",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nan": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
|
||||
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ=="
|
||||
},
|
||||
"node_modules/tree-sitter-cli": {
|
||||
"version": "0.20.0",
|
||||
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.0.tgz",
|
||||
"integrity": "sha512-4D1qapWbJXZ5rrSUGM5rcw5Vuq/smzn9KbiFRhlON6KeuuXjra+KAtDYVrDgAoLIG4ku+jbEEGrJxCptUGi3dg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"tree-sitter": "cli.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
|
||||
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ=="
|
||||
},
|
||||
"tree-sitter-cli": {
|
||||
"version": "0.20.0",
|
||||
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.0.tgz",
|
||||
"integrity": "sha512-4D1qapWbJXZ5rrSUGM5rcw5Vuq/smzn9KbiFRhlON6KeuuXjra+KAtDYVrDgAoLIG4ku+jbEEGrJxCptUGi3dg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-elisp",
|
||||
"version": "1.3.0",
|
||||
"description": "tree-sitter grammar for Emacs Lisp",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"lexer"
|
||||
],
|
||||
"scripts": {
|
||||
"generate": "tree-sitter generate",
|
||||
"highlight": "tree-sitter highlight",
|
||||
"parse": "tree-sitter parse",
|
||||
"test": "tree-sitter test"
|
||||
},
|
||||
"author": "Wilfred Hughes <me@wilfred.me.uk>",
|
||||
"repository": "https://github.com/Wilfred/tree-sitter-elisp",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.0"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.emacs.lisp",
|
||||
"file-types": [
|
||||
"el"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
;; Special forms
|
||||
[
|
||||
"and"
|
||||
"catch"
|
||||
"cond"
|
||||
"condition-case"
|
||||
"defconst"
|
||||
"defvar"
|
||||
"function"
|
||||
"if"
|
||||
"interactive"
|
||||
"lambda"
|
||||
"let"
|
||||
"let*"
|
||||
"or"
|
||||
"prog1"
|
||||
"prog2"
|
||||
"progn"
|
||||
"quote"
|
||||
"save-current-buffer"
|
||||
"save-excursion"
|
||||
"save-restriction"
|
||||
"setq"
|
||||
"setq-default"
|
||||
"unwind-protect"
|
||||
"while"
|
||||
] @keyword
|
||||
|
||||
;; Function definitions
|
||||
[
|
||||
"defun"
|
||||
"defsubst"
|
||||
] @keyword
|
||||
(function_definition name: (symbol) @function)
|
||||
(function_definition parameters: (list (symbol) @variable.parameter))
|
||||
(function_definition docstring: (string) @comment)
|
||||
|
||||
;; Highlight macro definitions the same way as function definitions.
|
||||
"defmacro" @keyword
|
||||
(macro_definition name: (symbol) @function)
|
||||
(macro_definition parameters: (list (symbol) @variable.parameter))
|
||||
(macro_definition docstring: (string) @comment)
|
||||
|
||||
(comment) @comment
|
||||
|
||||
(integer) @number
|
||||
(float) @number
|
||||
(char) @number
|
||||
|
||||
(string) @string
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"#["
|
||||
"["
|
||||
"]"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
"`"
|
||||
"#'"
|
||||
"'"
|
||||
","
|
||||
",@"
|
||||
] @operator
|
||||
|
||||
;; Highlight nil and t as constants, unlike other symbols
|
||||
[
|
||||
"nil"
|
||||
"t"
|
||||
] @constant.builtin
|
||||
@ -1,5 +0,0 @@
|
||||
;; defun/defsubst
|
||||
(function_definition name: (symbol) @name) @definition.function
|
||||
|
||||
;; Treat macros as function definitions for the sake of TAGS.
|
||||
(macro_definition name: (symbol) @name) @definition.function
|
||||
@ -1,765 +0,0 @@
|
||||
{
|
||||
"name": "elisp",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
"_sexp": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "special_form"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "macro_definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "list"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "vector"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "hash_table"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "bytecode"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string_text_properties"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_atom"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "quote"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "unquote_splice"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "unquote"
|
||||
}
|
||||
]
|
||||
},
|
||||
"special_form": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "and"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "catch"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "cond"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "condition-case"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defconst"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defvar"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "function"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "interactive"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "lambda"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "let"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "let*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "or"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "prog1"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "prog2"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "progn"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "quote"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "save-current-buffer"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "save-excursion"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "save-restriction"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "setq"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "setq-default"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "unwind-protect"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "while"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function_definition": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defun"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defsubst"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "symbol"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "parameters",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "docstring",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"macro_definition": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defmacro"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "symbol"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "parameters",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "docstring",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"_atom": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "float"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "integer"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "char"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "byte_compiled_file_name"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "symbol"
|
||||
}
|
||||
]
|
||||
},
|
||||
"float": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[+-]?[0-9]*\\.[0-9]+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[+-]?[0-9]+[eE][0-9]+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[+-]?[0-9]*\\.[0-9]+[eE][0-9]+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "-?1.0[eE]\\+INF"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "-?0.0[eE]\\+NaN"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"integer": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[+-]?[0-9]+\\.?"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "#([box]|[0-9][0-9]?r)[0-9a-zA-Z]"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"char": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?(\\\\.|.)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\N\\{[^}]+\\}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\u[0-9a-fA-F]{4}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\U[0-9a-fA-F]{8}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\x[0-9a-fA-F]+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\[0-7]{1,3}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?(\\\\(([CMSHsA]-)|\\^))+(\\\\;|.)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\?\\\\M-\\\\[0-9]{1,3}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"string": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\"\\\\]"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\\"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "(.|\\n)"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"byte_compiled_file_name": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "#$"
|
||||
}
|
||||
},
|
||||
"symbol": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "nil"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "t"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defun"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defsubst"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defmacro"
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\\\(`|'|,)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "([^?# \\n\\s\\f()\\[\\]'`,\\\\\";]|\\\\.)([^# \\n\\s\\f()\\[\\]'`,\\\\\";]|\\\\.)*"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "##"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"quote": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#'"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "'"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "`"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"unquote_splice": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ",@"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"unquote": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"dot": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
}
|
||||
},
|
||||
"list": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"vector": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bytecode": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#["
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"string_text_properties": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#("
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"hash_table": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#s(hash-table"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sexp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"comment": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": ";.*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "(\\s|\\f)"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "comment"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
"precedences": [],
|
||||
"externals": [],
|
||||
"inline": [],
|
||||
"supertypes": []
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,223 +0,0 @@
|
||||
#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;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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_
|
||||
@ -1,14 +0,0 @@
|
||||
================================================================================
|
||||
Bytecode literals
|
||||
================================================================================
|
||||
|
||||
#[1 2 3 4]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(bytecode
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)))
|
||||
@ -1,42 +0,0 @@
|
||||
================================================================================
|
||||
Characters
|
||||
================================================================================
|
||||
|
||||
?x
|
||||
?\\
|
||||
?\(
|
||||
|
||||
?\C-i
|
||||
?\M-i
|
||||
?\M-\151
|
||||
?\M-\C-i
|
||||
?\^i
|
||||
?\C-\M-\S-\H-\s-\A-i
|
||||
?\C-\;
|
||||
|
||||
?\N{SNOWMAN}
|
||||
?\N{U+61}
|
||||
?\u0061
|
||||
?\U00000061
|
||||
?\x61
|
||||
?\141
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char))
|
||||
@ -1,20 +0,0 @@
|
||||
================================================================================
|
||||
Escaped symbols
|
||||
================================================================================
|
||||
|
||||
\x\y
|
||||
\'
|
||||
\`
|
||||
\,
|
||||
\+1
|
||||
\(
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol))
|
||||
@ -1,16 +0,0 @@
|
||||
================================================================================
|
||||
Float literals
|
||||
================================================================================
|
||||
|
||||
1.0
|
||||
-.1
|
||||
3E5
|
||||
1.0e+INF
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(float)
|
||||
(float)
|
||||
(float)
|
||||
(float))
|
||||
@ -1,54 +0,0 @@
|
||||
================================================================================
|
||||
Function definition
|
||||
================================================================================
|
||||
|
||||
(defun foo (x &optional y)
|
||||
"stuff"
|
||||
x)
|
||||
(defsubst bar () nil)
|
||||
|
||||
(defun no-args nil 123)
|
||||
|
||||
`(defun ,x () ,@body)
|
||||
|
||||
'(defun 1)
|
||||
'(defun)
|
||||
'(defun foo)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(symbol)
|
||||
(list
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol))
|
||||
(string)
|
||||
(symbol))
|
||||
(function_definition
|
||||
(symbol)
|
||||
(list)
|
||||
(symbol))
|
||||
(function_definition
|
||||
(symbol)
|
||||
(symbol)
|
||||
(integer))
|
||||
(quote
|
||||
(list
|
||||
(symbol)
|
||||
(unquote
|
||||
(symbol))
|
||||
(list)
|
||||
(unquote_splice
|
||||
(symbol))))
|
||||
(quote
|
||||
(list
|
||||
(symbol)
|
||||
(integer)))
|
||||
(quote
|
||||
(list
|
||||
(symbol)))
|
||||
(quote
|
||||
(function_definition
|
||||
(symbol))))
|
||||
@ -1,11 +0,0 @@
|
||||
================================================================================
|
||||
Hash table read syntax
|
||||
================================================================================
|
||||
|
||||
#s(hash-table 0)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(hash_table
|
||||
(integer)))
|
||||
@ -1,24 +0,0 @@
|
||||
================================================================================
|
||||
Integer literals
|
||||
================================================================================
|
||||
|
||||
1
|
||||
-1.
|
||||
+1234
|
||||
|
||||
#x2603
|
||||
#o23003
|
||||
#b101010
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer)
|
||||
(integer))
|
||||
@ -1,25 +0,0 @@
|
||||
================================================================================
|
||||
Lists
|
||||
================================================================================
|
||||
|
||||
()
|
||||
(foo (bar))
|
||||
(1 2 . nil)
|
||||
(foo .)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(list)
|
||||
(list
|
||||
(symbol)
|
||||
(list
|
||||
(symbol)))
|
||||
(list
|
||||
(integer)
|
||||
(integer)
|
||||
(symbol)
|
||||
(symbol))
|
||||
(list
|
||||
(symbol)
|
||||
(symbol)))
|
||||
@ -1,19 +0,0 @@
|
||||
================================================================================
|
||||
Macro definition
|
||||
================================================================================
|
||||
|
||||
(defmacro foo (x &optional y)
|
||||
"stuff"
|
||||
x)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(macro_definition
|
||||
(symbol)
|
||||
(list
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol))
|
||||
(string)
|
||||
(symbol)))
|
||||
@ -1,14 +0,0 @@
|
||||
================================================================================
|
||||
Multiple characters without spaces (regression test)
|
||||
================================================================================
|
||||
|
||||
?a?a
|
||||
?a?\]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(char)
|
||||
(char)
|
||||
(char)
|
||||
(char))
|
||||
@ -1,22 +0,0 @@
|
||||
================================================================================
|
||||
Quotes
|
||||
================================================================================
|
||||
|
||||
'foo
|
||||
#'bar
|
||||
'(x ,y ,@z)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(quote
|
||||
(symbol))
|
||||
(quote
|
||||
(symbol))
|
||||
(quote
|
||||
(list
|
||||
(symbol)
|
||||
(unquote
|
||||
(symbol))
|
||||
(unquote_splice
|
||||
(symbol)))))
|
||||
@ -1,17 +0,0 @@
|
||||
================================================================================
|
||||
Special forms
|
||||
================================================================================
|
||||
|
||||
(if x 1 2)
|
||||
(while x y)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(special_form
|
||||
(symbol)
|
||||
(integer)
|
||||
(integer))
|
||||
(special_form
|
||||
(symbol)
|
||||
(symbol)))
|
||||
@ -1,10 +0,0 @@
|
||||
================================================================================
|
||||
Special read syntax
|
||||
================================================================================
|
||||
|
||||
#$
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(byte_compiled_file_name))
|
||||
@ -1,11 +0,0 @@
|
||||
================================================================================
|
||||
String after symbol (regression test)
|
||||
================================================================================
|
||||
|
||||
foo"bar"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(symbol)
|
||||
(string))
|
||||
@ -1,16 +0,0 @@
|
||||
================================================================================
|
||||
String text properties
|
||||
================================================================================
|
||||
|
||||
#("foo" 0 1 (x y))
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(string_text_properties
|
||||
(string)
|
||||
(integer)
|
||||
(integer)
|
||||
(list
|
||||
(symbol)
|
||||
(symbol))))
|
||||
@ -1,27 +0,0 @@
|
||||
================================================================================
|
||||
String literals
|
||||
================================================================================
|
||||
|
||||
""
|
||||
"simple"
|
||||
"\""
|
||||
"\\"
|
||||
"\\ foo \\"
|
||||
|
||||
"
|
||||
multiline
|
||||
"
|
||||
|
||||
"\
|
||||
foo"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(string)
|
||||
(string)
|
||||
(string)
|
||||
(string)
|
||||
(string)
|
||||
(string)
|
||||
(string))
|
||||
@ -1,56 +0,0 @@
|
||||
================================================================================
|
||||
Symbols
|
||||
================================================================================
|
||||
|
||||
foo-bar
|
||||
foo/bar
|
||||
foo?
|
||||
=
|
||||
~
|
||||
$
|
||||
>
|
||||
λ
|
||||
:foo
|
||||
foo!
|
||||
foo|bar
|
||||
foo.bar
|
||||
foo@bar
|
||||
foo{bar}
|
||||
%
|
||||
&optional
|
||||
&&
|
||||
_
|
||||
##
|
||||
.foo
|
||||
foo-★
|
||||
1+
|
||||
\1
|
||||
nil
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol))
|
||||
@ -1,7 +0,0 @@
|
||||
(defun foo (x)
|
||||
;; ^ keyword
|
||||
;; ^ function
|
||||
;; ^ variable.parameter
|
||||
"stuff"
|
||||
;; ^ comment
|
||||
x)
|
||||
Loading…
Reference in New Issue