Update tree-sitter version

pull/511/head
Patrick Förster 2021-03-20 14:12:59 +07:00
parent d113f32d34
commit e87bc36487
14 changed files with 512037 additions and 160855 deletions

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

@ -7,8 +7,9 @@
"src" "src"
], ],
"sources": [ "sources": [
"bindings/node/binding.cc",
"src/parser.c", "src/parser.c",
"src/binding.cc" # If your language uses an external scanner, add it here.
], ],
"cflags_c": [ "cflags_c": [
"-std=c99", "-std=c99",

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

@ -0,0 +1,40 @@
fn main() {
let src_dir = std::path::Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
// If your language uses an external scanner written in C,
// then include this block of code:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}

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

@ -327,7 +327,7 @@ module.exports = grammar({
citation: $ => citation: $ =>
seq( seq(
field('command', token(choice(...commands.citation))), field('command', choice(...commands.citation)),
optional( optional(
seq( seq(
field('prenote', $.bracket_group), field('prenote', $.bracket_group),
@ -341,7 +341,7 @@ module.exports = grammar({
package_include: $ => package_include: $ =>
seq( seq(
field('command', token(choice('\\usepackage', '\\RequirePackage'))), field('command', choice('\\usepackage', '\\RequirePackage')),
field('option', optional($.key_val_options)), field('option', optional($.key_val_options)),
'{', '{',
sepBy(field('path', $.word), ','), sepBy(field('path', $.word), ','),
@ -359,7 +359,7 @@ module.exports = grammar({
latex_include: $ => latex_include: $ =>
seq( seq(
field('command', token(choice('\\include', '\\subfileinclude'))), field('command', choice('\\include', '\\subfileinclude')),
'{', '{',
sepBy(field('path', $.word), ','), sepBy(field('path', $.word), ','),
'}' '}'
@ -367,7 +367,7 @@ module.exports = grammar({
latex_input: $ => latex_input: $ =>
seq( seq(
field('command', token(choice('\\input', '\\subfile'))), field('command', choice('\\input', '\\subfile')),
'{', '{',
sepBy(field('path', $.word), ','), sepBy(field('path', $.word), ','),
'}' '}'
@ -419,7 +419,7 @@ module.exports = grammar({
verbatim_include: $ => verbatim_include: $ =>
seq( seq(
field('command', token(choice('\\verbatiminput', '\\VerbatimInput'))), field('command', choice('\\verbatiminput', '\\VerbatimInput')),
'{', '{',
sepBy(field('path', $.word), ','), sepBy(field('path', $.word), ','),
'}' '}'
@ -429,15 +429,13 @@ module.exports = grammar({
seq( seq(
field( field(
'command', 'command',
token( choice(
choice( '\\import',
'\\import', '\\subimport',
'\\subimport', '\\inputfrom',
'\\inputfrom', '\\subimportfrom',
'\\subimportfrom', '\\includefrom',
'\\includefrom', '\\subincludefrom'
'\\subincludefrom'
)
) )
), ),
'{', '{',
@ -453,7 +451,7 @@ module.exports = grammar({
label_reference: $ => label_reference: $ =>
seq( seq(
field('command', token(choice(...commands.labelReference))), field('command', choice(...commands.labelReference)),
'{', '{',
sepBy(field('label', $.word), ','), sepBy(field('label', $.word), ','),
'}' '}'
@ -470,7 +468,7 @@ module.exports = grammar({
label_reference_range: $ => label_reference_range: $ =>
prec.right( prec.right(
seq( seq(
field('command', token(choice(...commands.labelRangeReference))), field('command', choice(...commands.labelRangeReference)),
'{', '{',
field('label1', $.word), field('label1', $.word),
'}', '}',
@ -492,9 +490,7 @@ module.exports = grammar({
seq( seq(
field( field(
'command', 'command',
token( choice('\\newcommand', '\\renewcommand', '\\DeclareRobustCommand')
choice('\\newcommand', '\\renewcommand', '\\DeclareRobustCommand')
)
), ),
field('argc', optional(seq('[', /\d/, ']'))), field('argc', optional(seq('[', /\d/, ']'))),
'{', '{',
@ -507,7 +503,7 @@ module.exports = grammar({
seq( seq(
field( field(
'command', 'command',
token(choice('\\DeclareMathOperator', '\\DeclareMathOperator*')) choice('\\DeclareMathOperator', '\\DeclareMathOperator*')
), ),
'{', '{',
field('name', $.generic_command_name), field('name', $.generic_command_name),
@ -528,7 +524,7 @@ module.exports = grammar({
glossary_entry_reference: $ => glossary_entry_reference: $ =>
seq( seq(
field('command', token(choice(...commands.glossaryEntryReference))), field('command', choice(...commands.glossaryEntryReference)),
field('option', optional($.key_val_options)), field('option', optional($.key_val_options)),
'{', '{',
field('name', $.word), field('name', $.word),
@ -548,7 +544,7 @@ module.exports = grammar({
acronym_reference: $ => acronym_reference: $ =>
seq( seq(
field('command', token(choice(...commands.acronymReference))), field('command', choice(...commands.acronymReference)),
field('option', optional($.key_val_options)), field('option', optional($.key_val_options)),
'{', '{',
field('name', $.word), field('name', $.word),
@ -557,7 +553,7 @@ module.exports = grammar({
theorem_definition: $ => theorem_definition: $ =>
prec.right( prec.right(
seq( seq(
field('command', token(choice('\\newtheorem', '\\declaretheorem'))), field('command', choice('\\newtheorem', '\\declaretheorem')),
'{', '{',
field('name', $.word), field('name', $.word),
'}', '}',
@ -581,7 +577,7 @@ module.exports = grammar({
seq( seq(
field( field(
'command', 'command',
token(choice('\\color', '\\colorbox', '\\textcolor', '\\pagecolor')) choice('\\color', '\\colorbox', '\\textcolor', '\\pagecolor')
), ),
'{', '{',
field('name', $.word), field('name', $.word),

@ -1,13 +0,0 @@
try {
module.exports = require("./build/Release/tree_sitter_latex_binding");
} catch (error) {
try {
module.exports = require("./build/Debug/tree_sitter_latex_binding");
} catch (_) {
throw error
}
}
try {
module.exports.nodeTypeInfo = require("./src/node-types.json");
} catch (_) {}

6
package-lock.json generated

@ -10,9 +10,9 @@
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==" "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
}, },
"tree-sitter-cli": { "tree-sitter-cli": {
"version": "0.17.3", "version": "0.19.4",
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.17.3.tgz", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.19.4.tgz",
"integrity": "sha512-AsQhjwRwWK5wtymwVc2H5E8/Q7yzMebSj7CQyeSg50k4h7m8HHwao1i/eKlh8aGTJ3IWbGjSwBAUZTSbzcSW6Q==", "integrity": "sha512-p2kxjuoQeauXBu5eE+j7c5BMCRXmc17EiAswnnWn3ieUlHXBkA0Z7vRnaCSElDR34MhZnSgqgzuuzQk0cDqCjw==",
"dev": true "dev": true
} }
} }

@ -2,7 +2,7 @@
"name": "tree-sitter-latex", "name": "tree-sitter-latex",
"version": "0.1.0", "version": "0.1.0",
"description": "Tree-sitter Grammar for LaTeX", "description": "Tree-sitter Grammar for LaTeX",
"main": "index.js", "main": "bindings/node",
"scripts": { "scripts": {
"build": "tree-sitter generate", "build": "tree-sitter generate",
"test": "tree-sitter test" "test": "tree-sitter test"
@ -26,6 +26,6 @@
"nan": "^2.14.2" "nan": "^2.14.2"
}, },
"devDependencies": { "devDependencies": {
"tree-sitter-cli": "^0.17.3" "tree-sitter-cli": "0.19.4"
} }
} }

1787
src/grammar.json vendored

File diff suppressed because it is too large Load Diff

4220
src/node-types.json vendored

File diff suppressed because it is too large Load Diff

666519
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -13,6 +13,8 @@ extern "C" {
#define ts_builtin_sym_end 0 #define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_ #ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol; typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId; typedef uint16_t TSFieldId;
@ -30,12 +32,10 @@ typedef struct {
uint16_t length; uint16_t length;
} TSFieldMapSlice; } TSFieldMapSlice;
typedef uint16_t TSStateId;
typedef struct { typedef struct {
bool visible : 1; bool visible;
bool named : 1; bool named;
bool supertype: 1; bool supertype;
} TSSymbolMetadata; } TSSymbolMetadata;
typedef struct TSLexer TSLexer; typedef struct TSLexer TSLexer;
@ -57,21 +57,21 @@ typedef enum {
TSParseActionTypeRecover, TSParseActionTypeRecover,
} TSParseActionType; } TSParseActionType;
typedef struct { typedef union {
union { struct {
struct { uint8_t type;
TSStateId state; TSStateId state;
bool extra : 1; bool extra;
bool repetition : 1; bool repetition;
} shift; } shift;
struct { struct {
TSSymbol symbol; uint8_t type;
int16_t dynamic_precedence; uint8_t child_count;
uint8_t child_count; TSSymbol symbol;
uint8_t production_id; int16_t dynamic_precedence;
} reduce; uint16_t production_id;
} params; } reduce;
TSParseActionType type : 4; uint8_t type;
} TSParseAction; } TSParseAction;
typedef struct { typedef struct {
@ -83,7 +83,7 @@ typedef union {
TSParseAction action; TSParseAction action;
struct { struct {
uint8_t count; uint8_t count;
bool reusable : 1; bool reusable;
} entry; } entry;
} TSParseActionEntry; } TSParseActionEntry;
@ -93,13 +93,24 @@ struct TSLanguage {
uint32_t alias_count; uint32_t alias_count;
uint32_t token_count; uint32_t token_count;
uint32_t external_token_count; uint32_t external_token_count;
const char **symbol_names; uint32_t state_count;
const TSSymbolMetadata *symbol_metadata; 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 *parse_table;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions; const TSParseActionEntry *parse_actions;
const TSLexMode *lex_modes; const char **symbol_names;
const char **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 TSSymbol *alias_sequences;
uint16_t max_alias_sequence_length; const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId); bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId); bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token; TSSymbol keyword_capture_token;
@ -112,16 +123,6 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *); unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned); void (*deserialize)(void *, const char *, unsigned);
} external_scanner; } external_scanner;
uint32_t field_count;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const char **field_names;
uint32_t large_state_count;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
uint32_t state_count;
}; };
/* /*
@ -170,66 +171,50 @@ struct TSLanguage {
#define ACTIONS(id) id #define ACTIONS(id) id
#define SHIFT(state_value) \ #define SHIFT(state_value) \
{ \ {{ \
{ \ .shift = { \
.params = { \ .type = TSParseActionTypeShift, \
.shift = { \ .state = state_value \
.state = state_value \ } \
} \ }}
}, \
.type = TSParseActionTypeShift \
} \
}
#define SHIFT_REPEAT(state_value) \ #define SHIFT_REPEAT(state_value) \
{ \ {{ \
{ \ .shift = { \
.params = { \ .type = TSParseActionTypeShift, \
.shift = { \ .state = state_value, \
.state = state_value, \ .repetition = true \
.repetition = true \
} \
}, \
.type = TSParseActionTypeShift \
} \ } \
} }}
#define RECOVER() \
{ \
{ .type = TSParseActionTypeRecover } \
}
#define SHIFT_EXTRA() \ #define SHIFT_EXTRA() \
{ \ {{ \
{ \ .shift = { \
.params = { \ .type = TSParseActionTypeShift, \
.shift = { \ .extra = true \
.extra = true \
} \
}, \
.type = TSParseActionTypeShift \
} \ } \
} }}
#define REDUCE(symbol_val, child_count_val, ...) \ #define REDUCE(symbol_val, child_count_val, ...) \
{ \ {{ \
{ \ .reduce = { \
.params = { \ .type = TSParseActionTypeReduce, \
.reduce = { \ .symbol = symbol_val, \
.symbol = symbol_val, \ .child_count = child_count_val, \
.child_count = child_count_val, \ __VA_ARGS__ \
__VA_ARGS__ \ }, \
}, \ }}
}, \
.type = TSParseActionTypeReduce \ #define RECOVER() \
} \ {{ \
} .type = TSParseActionTypeRecover \
}}
#define ACCEPT_INPUT() \
{ \ #define ACCEPT_INPUT() \
{ .type = TSParseActionTypeAccept } \ {{ \
} .type = TSParseActionTypeAccept \
}}
#ifdef __cplusplus #ifdef __cplusplus
} }