mirror of https://github.com/Wilfred/difftastic/
Add 'vendored_parsers/tree-sitter-racket/' from commit 'dc9c33451fefc2d84d226e55c828adc8a66f2e37'
git-subtree-dir: vendored_parsers/tree-sitter-racket git-subtree-mainline:pull/483/heada7f06471e1git-subtree-split:dc9c33451f
commit
62a5f20bf6
@ -0,0 +1,7 @@
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
@ -0,0 +1,3 @@
|
||||
Checks: '*, -modernize-use-trailing-return-type, -llvmlibc-*'
|
||||
HeaderFilterRegex: ''
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[{*.js,*.rkt,package.json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
name: Test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
|
||||
racket:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
- run: npm install
|
||||
- run: git clone https://github.com/racket/racket --depth 1
|
||||
- run: $(npm bin)/tree-sitter parse $(find racket -name '*.rkt' -type f -not -exec grep -q '#lang at-exp' {} \; -print) -qt
|
||||
@ -0,0 +1,8 @@
|
||||
node_modules/
|
||||
build/
|
||||
target/
|
||||
package-lock.json
|
||||
Cargo.lock
|
||||
test.rkt
|
||||
compile_commands.json
|
||||
.cache/
|
||||
@ -0,0 +1,22 @@
|
||||
# Contributing
|
||||
|
||||
Thank you to contribute `tree-sitter-racket`.
|
||||
|
||||
## Workflow
|
||||
|
||||
It's recommended to use [nix](https://nixos.org/) package manager, and run
|
||||
|
||||
```shell
|
||||
nix-shell
|
||||
npm install # if you haven't install node modules
|
||||
```
|
||||
|
||||
Then you can use `tree-sitter` command:
|
||||
|
||||
```shell
|
||||
tree-sitter generate
|
||||
tree-sitter test
|
||||
```
|
||||
|
||||
If you don't use nix, you should follow the [official setup](https://tree-sitter.github.io/tree-sitter/creating-parsers) to configure the dev environment.
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "tree-sitter-racket"
|
||||
description = "racket grammar for the tree-sitter parsing library"
|
||||
version = "0.0.1"
|
||||
keywords = ["incremental", "parsing", "racket"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-racket"
|
||||
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"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 6cdh
|
||||
|
||||
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.
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
# tree-sitter-racket
|
||||
|
||||
[](https://github.com/6cdh/tree-sitter-racket/actions/workflows/test.yml)
|
||||
|
||||
Racket grammar for tree-sitter.
|
||||
|
||||
This grammar only implements the Racket language with the default readtable.
|
||||
|
||||
## Status
|
||||
|
||||
It should recognize most grammar with the default readtable.
|
||||
|
||||
## Build and Try
|
||||
|
||||
You need
|
||||
|
||||
* nodejs
|
||||
* a C compiler
|
||||
* a C++11 compiler
|
||||
|
||||
then run
|
||||
|
||||
```shell
|
||||
npm install
|
||||
npx tree-sitter parse [filename]
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
See [nodes.md](./nodes.md) for all visible nodes.
|
||||
|
||||
## Reference
|
||||
|
||||
Racket
|
||||
|
||||
- [The Racket Reader](https://docs.racket-lang.org/reference/reader.html)
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_racket_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
"src/scanner.cc",
|
||||
# If your language uses an external scanner, add it here.
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_racket();
|
||||
|
||||
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_racket());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("racket").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_racket_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -0,0 +1,19 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_racket_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_racket_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -0,0 +1,25 @@
|
||||
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);
|
||||
c_config.compile("parser");
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
|
||||
let mut cpp_config = cc::Build::new();
|
||||
cpp_config.cpp(true);
|
||||
cpp_config.include(&src_dir);
|
||||
cpp_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
let scanner_path = src_dir.join("scanner.cc");
|
||||
cpp_config.file(&scanner_path);
|
||||
cpp_config.compile("scanner");
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
//! This crate provides racket 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_racket::language()).expect("Error loading racket 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_racket() -> 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_racket() }
|
||||
}
|
||||
|
||||
/// 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 racket language");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
===
|
||||
box
|
||||
===
|
||||
|
||||
#&17
|
||||
#&"str"
|
||||
#& ()
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(box
|
||||
(number))
|
||||
(box
|
||||
(string))
|
||||
(box
|
||||
(list)))
|
||||
@ -0,0 +1,23 @@
|
||||
===
|
||||
comment
|
||||
===
|
||||
;1
|
||||
; comment
|
||||
#| a |#
|
||||
#| #| a |# 1 |#
|
||||
#;1
|
||||
#!/bin/sh
|
||||
#! /bin/sh
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(comment)
|
||||
(comment)
|
||||
(block_comment)
|
||||
(block_comment
|
||||
(block_comment))
|
||||
(sexp_comment
|
||||
(number))
|
||||
(comment)
|
||||
(comment))
|
||||
@ -0,0 +1,20 @@
|
||||
===
|
||||
racket/racket
|
||||
===
|
||||
|
||||
|#%mzc:embed-me25| "10|" |abc|
|
||||
|abc|
|
||||
abc|abc| |abc|
|
||||
|
||||
#:|abc |
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(symbol)
|
||||
(string)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(keyword))
|
||||
@ -0,0 +1,22 @@
|
||||
===
|
||||
extension
|
||||
===
|
||||
|
||||
#lang racket
|
||||
#lang typed/racket
|
||||
#lang racket1001001
|
||||
#reader 123
|
||||
#!r6rs
|
||||
|
||||
---
|
||||
(program
|
||||
(extension
|
||||
(lang_name))
|
||||
(extension
|
||||
(lang_name))
|
||||
(extension
|
||||
(lang_name))
|
||||
(extension
|
||||
(number))
|
||||
(extension
|
||||
(lang_name)))
|
||||
@ -0,0 +1,25 @@
|
||||
===
|
||||
graph
|
||||
===
|
||||
|
||||
(#1=100 #1# #1#)
|
||||
#0= (1 . #0#)
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(list
|
||||
(graph
|
||||
(decimal)
|
||||
(number))
|
||||
(graph
|
||||
(decimal))
|
||||
(graph
|
||||
(decimal)))
|
||||
(graph
|
||||
(decimal)
|
||||
(list
|
||||
(number)
|
||||
(dot)
|
||||
(graph
|
||||
(decimal)))))
|
||||
@ -0,0 +1,39 @@
|
||||
===
|
||||
hash table
|
||||
===
|
||||
|
||||
#hash()
|
||||
#hasheq()
|
||||
#hash(("a" . 5))
|
||||
#hasheq(("a" . 5) ("b" . 7))
|
||||
#hasheqv(("a" . 5))
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(hash
|
||||
(list))
|
||||
(hash
|
||||
(list))
|
||||
(hash
|
||||
(list
|
||||
(list
|
||||
(string)
|
||||
(dot)
|
||||
(number))))
|
||||
(hash
|
||||
(list
|
||||
(list
|
||||
(string)
|
||||
(dot)
|
||||
(number))
|
||||
(list
|
||||
(string)
|
||||
(dot)
|
||||
(number))))
|
||||
(hash
|
||||
(list
|
||||
(list
|
||||
(string)
|
||||
(dot)
|
||||
(number)))))
|
||||
@ -0,0 +1,74 @@
|
||||
===
|
||||
list
|
||||
===
|
||||
|
||||
()
|
||||
(1 2 3)
|
||||
{1 2 3}
|
||||
[1 2 3]
|
||||
(1 (2) 3)
|
||||
(1 . 3)
|
||||
(1 . (3))
|
||||
(1 . 2 . 3)
|
||||
|
||||
---
|
||||
(program
|
||||
(list)
|
||||
(list
|
||||
(number)
|
||||
(number)
|
||||
(number))
|
||||
(list
|
||||
(number)
|
||||
(number)
|
||||
(number))
|
||||
(list
|
||||
(number)
|
||||
(number)
|
||||
(number))
|
||||
(list
|
||||
(number)
|
||||
(list
|
||||
(number))
|
||||
(number))
|
||||
(list
|
||||
(number)
|
||||
(dot)
|
||||
(number))
|
||||
(list
|
||||
(number)
|
||||
(dot)
|
||||
(list
|
||||
(number)))
|
||||
(list
|
||||
(number)
|
||||
(dot)
|
||||
(number)
|
||||
(dot)
|
||||
(number)))
|
||||
|
||||
===
|
||||
vector
|
||||
===
|
||||
|
||||
#(1 "apple" 3)
|
||||
#3("apple" "banana")
|
||||
#3()
|
||||
|
||||
---
|
||||
(program
|
||||
(vector
|
||||
(list
|
||||
(number)
|
||||
(string)
|
||||
(number)))
|
||||
(vector
|
||||
(decimal)
|
||||
(list
|
||||
(string)
|
||||
(string)))
|
||||
(vector
|
||||
(decimal)
|
||||
(list)))
|
||||
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
===
|
||||
quote
|
||||
===
|
||||
|
||||
'123
|
||||
`(1 ,2)
|
||||
#'123
|
||||
#`123
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(quote
|
||||
(number))
|
||||
(quasiquote
|
||||
(list
|
||||
(number)
|
||||
(unquote
|
||||
(number))))
|
||||
(syntax (number))
|
||||
(quasisyntax (number)))
|
||||
|
||||
===
|
||||
unquote
|
||||
===
|
||||
|
||||
,1
|
||||
,@1
|
||||
#,1
|
||||
#,@1
|
||||
|
||||
---
|
||||
(program
|
||||
(unquote (number))
|
||||
(unquote_splicing (number))
|
||||
(unsyntax (number))
|
||||
(unsyntax_splicing
|
||||
(number)))
|
||||
@ -0,0 +1,110 @@
|
||||
===
|
||||
boolean
|
||||
===
|
||||
|
||||
#t
|
||||
#f
|
||||
#true
|
||||
#false
|
||||
|
||||
---
|
||||
(program
|
||||
(boolean)
|
||||
(boolean)
|
||||
(boolean)
|
||||
(boolean))
|
||||
|
||||
===
|
||||
number
|
||||
===
|
||||
|
||||
-1
|
||||
1/2
|
||||
1.0
|
||||
1+2i
|
||||
1/2+3/4i
|
||||
1.0+3.0e7i
|
||||
2e5
|
||||
#i5
|
||||
#e2e5
|
||||
#x2e5
|
||||
#b101
|
||||
+inf.t
|
||||
-nan.t
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number))
|
||||
|
||||
===
|
||||
character
|
||||
===
|
||||
|
||||
#\newline
|
||||
#\n
|
||||
#\u3BB
|
||||
#\λ
|
||||
|
||||
---
|
||||
(program
|
||||
(character)
|
||||
(character)
|
||||
(character)
|
||||
(character))
|
||||
|
||||
===
|
||||
symbol
|
||||
===
|
||||
|
||||
Apple
|
||||
Ap#ple
|
||||
Ap ple
|
||||
Ap| |ple
|
||||
Ap\ ple
|
||||
#%Apple
|
||||
123app
|
||||
app123app123
|
||||
123app123
|
||||
中文
|
||||
|
||||
---
|
||||
(program
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol)
|
||||
(symbol))
|
||||
|
||||
===
|
||||
keyword
|
||||
===
|
||||
|
||||
#:apple
|
||||
#:###abc##123123
|
||||
#:123123
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(keyword)
|
||||
(keyword)
|
||||
(keyword))
|
||||
@ -0,0 +1,51 @@
|
||||
===
|
||||
string
|
||||
===
|
||||
|
||||
"Apple"
|
||||
"\x41pple"
|
||||
"\"Apple\""
|
||||
"\\"
|
||||
#"Apple"
|
||||
#<<EOF
|
||||
(define (fib n)
|
||||
(if (< n 2) 1
|
||||
(+ (fib (- n 1))
|
||||
(fib (- n 2)))))
|
||||
EOF
|
||||
#<<one two three
|
||||
one two three
|
||||
|
||||
|
||||
---
|
||||
(program
|
||||
(string)
|
||||
(string
|
||||
(escape_sequence))
|
||||
(string
|
||||
(escape_sequence)
|
||||
(escape_sequence))
|
||||
(string
|
||||
(escape_sequence))
|
||||
(byte_string)
|
||||
(here_string)
|
||||
(here_string))
|
||||
|
||||
|
||||
===
|
||||
regex
|
||||
===
|
||||
|
||||
#rx".*"
|
||||
#px"[\\s]*"
|
||||
#rx#".*"
|
||||
#px#"[\\s]*"
|
||||
|
||||
---
|
||||
(program
|
||||
(regex)
|
||||
(regex
|
||||
(escape_sequence))
|
||||
(regex)
|
||||
(regex
|
||||
(escape_sequence)))
|
||||
@ -0,0 +1,18 @@
|
||||
==========
|
||||
structure
|
||||
==========
|
||||
|
||||
#s(1 2)
|
||||
#s{"abc" 2}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(structure
|
||||
(list
|
||||
(number)
|
||||
(number)))
|
||||
(structure
|
||||
(list
|
||||
(string)
|
||||
(number))))
|
||||
@ -0,0 +1,423 @@
|
||||
const PREC = {
|
||||
first: $ => prec(100, $),
|
||||
last: $ => prec(-1, $),
|
||||
left: prec.left,
|
||||
right: prec.right,
|
||||
};
|
||||
|
||||
const LEAF = {
|
||||
// https://en.wikipedia.org/wiki/Unicode_character_property#Whitespace
|
||||
whitespace: /[ \t\n\v\f\r\u{0085}\u{00A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}]/u,
|
||||
newline: /[\r\n\u{85}\u{2028}\u{2029}]/,
|
||||
delimiter: /[ \t\n\v\f\r\u{0085}\u{00A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{FEFF}(){}",'`;\[\]]/u,
|
||||
non_delimiter: /[^ \t\n\v\f\r\u{0085}\u{00A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{FEFF}(){}",'`;\[\]]/u,
|
||||
|
||||
// first character of symbol
|
||||
symbol_start:
|
||||
choice(
|
||||
/[^# \t\n\v\f\r\u{0085}\u{00A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{FEFF}(){}",'`;\[\]\|\\]/u,
|
||||
"#%",
|
||||
/\|[^|]*\|/,
|
||||
/\\./),
|
||||
symbol_remain:
|
||||
choice(
|
||||
/[^ \t\n\v\f\r\u{0085}\u{00A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{FEFF}(){}",'`;\[\]\|\\]/u,
|
||||
/\|[^|]*\|/,
|
||||
/\\./),
|
||||
|
||||
any_char: /.|[\r\n\u{85}\u{2028}\u{2029}]/,
|
||||
};
|
||||
|
||||
function paren(tok) {
|
||||
return choice(
|
||||
seq("(", tok, ")"),
|
||||
seq("[", tok, "]"),
|
||||
seq("{", tok, "}"));
|
||||
}
|
||||
|
||||
module.exports = grammar({
|
||||
name: 'racket',
|
||||
|
||||
extras: _ => [],
|
||||
|
||||
externals: $ => [
|
||||
$._here_string_body,
|
||||
],
|
||||
|
||||
rules: {
|
||||
program: $ => repeat($._token),
|
||||
|
||||
_token: $ =>
|
||||
choice(
|
||||
token(repeat1(LEAF.whitespace)),
|
||||
$._all_comment,
|
||||
$.extension,
|
||||
$._datum),
|
||||
|
||||
_skip: $ => choice(token(repeat1(LEAF.whitespace)), $._all_comment),
|
||||
|
||||
dot: _ => ".",
|
||||
|
||||
// comment {{{
|
||||
|
||||
_all_comment: $ =>
|
||||
choice(
|
||||
$.comment,
|
||||
$.sexp_comment,
|
||||
$.block_comment),
|
||||
|
||||
comment: $ =>
|
||||
choice(
|
||||
token(
|
||||
seq(/;.*/)),
|
||||
$._line_comment),
|
||||
|
||||
block_comment: $ =>
|
||||
seq("#|",
|
||||
repeat(
|
||||
choice(
|
||||
PREC.first($.block_comment),
|
||||
LEAF.any_char)),
|
||||
PREC.first("|#")),
|
||||
|
||||
sexp_comment: $ =>
|
||||
seq("#;",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
_line_comment: _ =>
|
||||
token(
|
||||
seq(
|
||||
choice("#! ", "#!/"),
|
||||
repeat(seq(/.*/, "\\", LEAF.newline)),
|
||||
/.*/)),
|
||||
|
||||
// comment }}}
|
||||
|
||||
_datum: $ =>
|
||||
choice(
|
||||
$.boolean,
|
||||
$.string,
|
||||
$.here_string,
|
||||
$.byte_string,
|
||||
$.character,
|
||||
$.number,
|
||||
$.symbol,
|
||||
|
||||
$.keyword,
|
||||
$.regex,
|
||||
$.box,
|
||||
$.graph,
|
||||
$.structure,
|
||||
$.hash,
|
||||
$._abbrev,
|
||||
|
||||
$.list,
|
||||
$.vector),
|
||||
|
||||
boolean: _ => token(choice("#true", "#t", "#T", "#false", "#f", "#F")),
|
||||
|
||||
// string {{{
|
||||
|
||||
string: $ => $._real_string,
|
||||
|
||||
byte_string: $ =>
|
||||
seq("#", $._real_string),
|
||||
|
||||
here_string: $ =>
|
||||
seq("#<<", $._here_string_body),
|
||||
|
||||
regex: $ =>
|
||||
seq(
|
||||
token(choice("#rx", "#px", "#rx#", "#px#")),
|
||||
$._real_string),
|
||||
|
||||
_real_string: $ =>
|
||||
seq(
|
||||
'"',
|
||||
repeat(
|
||||
choice(
|
||||
$.escape_sequence,
|
||||
/[^"\\]+/)),
|
||||
'"'),
|
||||
|
||||
escape_sequence: _ =>
|
||||
token(
|
||||
choice(
|
||||
"\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\e",
|
||||
'\\"', "\\'", "\\\\",
|
||||
seq("\\", /[0-7]{1,3}/),
|
||||
seq("\\x", /[0-9a-fA-F]{1,2}/),
|
||||
seq("\\u", /[0-9a-fA-F]{1,4}/),
|
||||
seq("\\u", /[0-9a-fA-F]{4,4}/),
|
||||
seq("\\U", /[0-9a-fA-F]{1,8}/),
|
||||
seq("\\", LEAF.newline))),
|
||||
|
||||
// string }}}
|
||||
|
||||
number: _ =>
|
||||
token(
|
||||
choice(
|
||||
_number_base(2),
|
||||
_number_base(8),
|
||||
_number_base(10),
|
||||
_number_base(16))),
|
||||
|
||||
decimal: _ => /[0-9]+/,
|
||||
|
||||
character: _ =>
|
||||
token(
|
||||
seq(
|
||||
"#\\",
|
||||
choice(
|
||||
"nul", "null", "backspace",
|
||||
"tab", "newline", "linefeed",
|
||||
"vtab", "page", "return",
|
||||
"space", "rubout",
|
||||
/[0-7]{3,3}/, /u[0-9a-fA-F]{1,4}/, /U[0-9a-fA-F]{1,8}/,
|
||||
/./))),
|
||||
|
||||
symbol: _ =>
|
||||
PREC.last(
|
||||
PREC.right(
|
||||
token(
|
||||
choice(
|
||||
/#[cC][iIsS]/, // read-case-sensitive parameter
|
||||
seq(
|
||||
LEAF.symbol_start,
|
||||
repeat(LEAF.symbol_remain)))))),
|
||||
|
||||
keyword: _ =>
|
||||
token(
|
||||
seq(
|
||||
"#:",
|
||||
repeat1(LEAF.symbol_remain))),
|
||||
|
||||
box: $ =>
|
||||
seq(
|
||||
"#&",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
list: $ =>
|
||||
paren(
|
||||
repeat(
|
||||
choice(
|
||||
$._token,
|
||||
$.dot))),
|
||||
|
||||
vector: $ =>
|
||||
seq(
|
||||
choice("#", "#fl", "#fx"),
|
||||
optional($.decimal),
|
||||
$.list),
|
||||
|
||||
structure: $ =>
|
||||
seq(
|
||||
"#s",
|
||||
$.list),
|
||||
|
||||
hash: $ =>
|
||||
seq(
|
||||
choice("#hash", "#hasheq", "#hasheqv"),
|
||||
$.list),
|
||||
|
||||
graph: $ =>
|
||||
seq(
|
||||
"#",
|
||||
$.decimal,
|
||||
choice(
|
||||
"#",
|
||||
seq(
|
||||
"=",
|
||||
repeat($._skip),
|
||||
$._datum))),
|
||||
|
||||
_abbrev: $ =>
|
||||
choice(
|
||||
$.quote,
|
||||
$.quasiquote,
|
||||
$.syntax,
|
||||
$.quasisyntax,
|
||||
$.unquote,
|
||||
$.unquote_splicing,
|
||||
$.unsyntax,
|
||||
$.unsyntax_splicing),
|
||||
|
||||
quote: $ =>
|
||||
seq(
|
||||
"'",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
quasiquote: $ =>
|
||||
seq(
|
||||
"`",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
syntax: $ =>
|
||||
seq(
|
||||
"#'",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
quasisyntax: $ =>
|
||||
seq(
|
||||
"#`",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
unquote: $ =>
|
||||
seq(
|
||||
",",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
unquote_splicing: $ =>
|
||||
seq(
|
||||
",@",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
unsyntax: $ =>
|
||||
seq(
|
||||
"#,",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
unsyntax_splicing: $ =>
|
||||
seq(
|
||||
"#,@",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
|
||||
extension: $ =>
|
||||
choice(
|
||||
seq(
|
||||
"#reader",
|
||||
repeat($._skip),
|
||||
$._datum),
|
||||
seq(
|
||||
choice("#lang ", "#!"),
|
||||
$.lang_name)),
|
||||
|
||||
lang_name: _ => /[a-zA-Z0-9+_/-]+/,
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
// number {{{
|
||||
|
||||
function _number_base(n) {
|
||||
const number = _ =>
|
||||
seq(
|
||||
choice(
|
||||
seq(radix(), optional(exactness())),
|
||||
seq(optional(exactness()), radix()),
|
||||
),
|
||||
choice(
|
||||
// Inexact number pattern already contains exact pattern.
|
||||
// So we don't need to parse exact number explicitly
|
||||
inexact()));
|
||||
|
||||
const sign = _ => /[+-]/;
|
||||
|
||||
const digit = _ => {
|
||||
return {
|
||||
2: /[01]/,
|
||||
8: /[0-7]/,
|
||||
10: /[0-9]/,
|
||||
16: /[0-9a-fA-F]/,
|
||||
}[n];
|
||||
};
|
||||
|
||||
const radix = _ => {
|
||||
return {
|
||||
2: /#[bB]/,
|
||||
8: /#[oO]/,
|
||||
10: optional(/#[dD]/),
|
||||
16: /#[xX]/,
|
||||
}[n];
|
||||
};
|
||||
|
||||
const exactness = _ =>
|
||||
choice("#e", "#E", "#i", "#I");
|
||||
|
||||
const exp_mark = _ => /[sldeftSLDEFT]/;
|
||||
|
||||
const unsigned_integer = _ =>
|
||||
repeat1(digit());
|
||||
|
||||
const inexact = _ =>
|
||||
choice(
|
||||
inexact_real(),
|
||||
inexact_complex());
|
||||
|
||||
const inexact_real = _ =>
|
||||
choice(
|
||||
seq(
|
||||
optional(sign()),
|
||||
inexact_normal()),
|
||||
seq(
|
||||
sign(),
|
||||
inexact_special()));
|
||||
|
||||
const inexact_complex = _ =>
|
||||
choice(
|
||||
seq(
|
||||
optional(inexact_real()),
|
||||
sign(),
|
||||
inexact_unsigned(),
|
||||
/[iI]/),
|
||||
seq(
|
||||
inexact_real(),
|
||||
"@",
|
||||
inexact_real()));
|
||||
|
||||
const inexact_unsigned = _ =>
|
||||
choice(
|
||||
inexact_normal(),
|
||||
inexact_special());
|
||||
|
||||
const inexact_normal = _ =>
|
||||
seq(
|
||||
inexact_simple(),
|
||||
optional(
|
||||
seq(
|
||||
exp_mark(),
|
||||
optional(sign()),
|
||||
unsigned_integer())));
|
||||
|
||||
const inexact_special = _ =>
|
||||
choice(
|
||||
/[iI][nN][fF]\.0/,
|
||||
/[nN][aA][nN]\.0/,
|
||||
/[iI][nN][fF]\.[fFtT]/,
|
||||
/[nN][aA][nN]\.[fFtT]/,
|
||||
);
|
||||
|
||||
const inexact_simple = _ =>
|
||||
choice(
|
||||
seq(
|
||||
digits(),
|
||||
optional("."),
|
||||
repeat("#")),
|
||||
seq(
|
||||
optional(unsigned_integer()),
|
||||
".",
|
||||
digits()),
|
||||
seq(
|
||||
digits(),
|
||||
"/",
|
||||
digits()));
|
||||
|
||||
const digits = _ =>
|
||||
seq(
|
||||
unsigned_integer(),
|
||||
repeat("#"));
|
||||
|
||||
return token(number());
|
||||
}
|
||||
|
||||
// number }}}
|
||||
@ -0,0 +1,41 @@
|
||||
## Nodes
|
||||
|
||||
This page contains all visible nodes in yaml format.
|
||||
|
||||
```yml
|
||||
- comment # comments
|
||||
- block_comment
|
||||
- sexp_comment
|
||||
- extension # #lang or #reader
|
||||
- lang_name # language name in extension
|
||||
- dot # .
|
||||
|
||||
- boolean
|
||||
- string
|
||||
- escape_sequence # escape sequence in string
|
||||
- here_string
|
||||
- byte_string
|
||||
- character
|
||||
- number
|
||||
- symbol
|
||||
- decimal # [0-9]+ used for graph reference or vector length in literal
|
||||
|
||||
- keyword # for example, #:abc
|
||||
- regex
|
||||
- box
|
||||
- graph
|
||||
- structure
|
||||
- hash # hash table
|
||||
- quote # '
|
||||
- quasiquote # `
|
||||
- syntax # #'
|
||||
- quasisyntax # #`
|
||||
- unquote # ,
|
||||
- unquote_splicing # ,@
|
||||
- unsyntax # #,
|
||||
- unsyntax_splicing # #,@
|
||||
|
||||
- list
|
||||
- vector
|
||||
```
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "tree-sitter-racket",
|
||||
"version": "0.1.0",
|
||||
"description": "Tree-sitter grammar for Racket",
|
||||
"main": "bindings/node",
|
||||
"scripts": {
|
||||
"build": "npx tree-sitter generate",
|
||||
"test": "npx tree-sitter generate && npx tree-sitter test"
|
||||
},
|
||||
"author": "6cdh",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.6",
|
||||
"typescript": "^4.8.4",
|
||||
"typescript-language-server": "^2.1.0"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.racket",
|
||||
"file-types": [
|
||||
"rkt"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,31 @@
|
||||
(symbol) @local.reference
|
||||
|
||||
(list
|
||||
.
|
||||
(symbol) @reference._let
|
||||
.
|
||||
(list
|
||||
.
|
||||
(list
|
||||
.
|
||||
(symbol) @local.definition)+)
|
||||
(#match? @reference._let "^(let|let\\*|for|for\\*)$")) @local.scope
|
||||
|
||||
(list
|
||||
.
|
||||
(symbol) @reference._def
|
||||
.
|
||||
(list
|
||||
.
|
||||
(symbol)
|
||||
.
|
||||
(symbol)+ @local.definition)
|
||||
(#match? @reference._def "^(define|define/contract|define-syntax-rule)$")) @local.scope
|
||||
|
||||
(list
|
||||
.
|
||||
(symbol) @reference._def
|
||||
.
|
||||
(symbol) @local.definition
|
||||
(#match? @reference._def "^(lambda|λ)$")) @local.scope
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
(list
|
||||
.
|
||||
(symbol) @reference._define
|
||||
(#match? @reference._define "^(define|define/contract)$")
|
||||
.
|
||||
(list
|
||||
.
|
||||
(symbol) @name) @definition.function)
|
||||
|
||||
(list
|
||||
.
|
||||
(symbol) @reference.call)
|
||||
@ -0,0 +1,11 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
nodejs
|
||||
gcc
|
||||
];
|
||||
shellHook = ''
|
||||
PATH=./node_modules/.bin:$PATH
|
||||
'';
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,106 @@
|
||||
#include <string>
|
||||
|
||||
#include "tree_sitter/parser.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using std::u32string;
|
||||
|
||||
enum TokenType {
|
||||
HERE_STRING_BODY,
|
||||
};
|
||||
|
||||
class optional_str {
|
||||
bool valid;
|
||||
u32string str;
|
||||
|
||||
public:
|
||||
optional_str() : valid(true) {}
|
||||
|
||||
static optional_str empty() {
|
||||
optional_str emp;
|
||||
emp.valid = false;
|
||||
return emp;
|
||||
}
|
||||
|
||||
bool has_value() const { return valid; }
|
||||
|
||||
bool operator==(const optional_str &rhs) const {
|
||||
if (!this->valid) {
|
||||
return !rhs.valid;
|
||||
} else {
|
||||
return rhs.valid && this->str == rhs.str;
|
||||
}
|
||||
}
|
||||
|
||||
u32string *operator->() { return &this->str; }
|
||||
};
|
||||
|
||||
inline bool isnewline(int32_t c) {
|
||||
return c == '\n' || c == '\r' || c == 0x85 || c == 0x2028 || c == 0x2029;
|
||||
}
|
||||
|
||||
inline optional_str readline(TSLexer *lexer) {
|
||||
optional_str line;
|
||||
|
||||
while (!isnewline(lexer->lookahead)) {
|
||||
if (lexer->eof(lexer)) {
|
||||
return optional_str::empty();
|
||||
}
|
||||
line->push_back(lexer->lookahead);
|
||||
lexer->advance(lexer, false);
|
||||
}
|
||||
lexer->advance(lexer, false);
|
||||
return line;
|
||||
}
|
||||
|
||||
bool scan(TSLexer *lexer, const bool *valid_symbols) {
|
||||
if (!valid_symbols[HERE_STRING_BODY]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const optional_str terminator = readline(lexer);
|
||||
|
||||
if (!terminator.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const optional_str line = readline(lexer);
|
||||
if (!line.has_value()) {
|
||||
return false;
|
||||
}
|
||||
if (line == terminator) {
|
||||
lexer->result_symbol = HERE_STRING_BODY;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
void *tree_sitter_racket_external_scanner_create(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tree_sitter_racket_external_scanner_destroy(void *payload) {
|
||||
}
|
||||
|
||||
unsigned tree_sitter_racket_external_scanner_serialize(void *payload,
|
||||
char *buffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tree_sitter_racket_external_scanner_deserialize(void *payload,
|
||||
const char *buffer,
|
||||
unsigned length) {
|
||||
}
|
||||
|
||||
bool tree_sitter_racket_external_scanner_scan(void *payload,
|
||||
TSLexer *lexer,
|
||||
const bool *valid_symbols) {
|
||||
return scan(lexer, valid_symbols);
|
||||
}
|
||||
}
|
||||
@ -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_
|
||||
Loading…
Reference in New Issue