Detailed changes
@@ -1202,7 +1202,7 @@ dependencies = [
"smallvec",
"smol",
"tiny-skia",
- "tree-sitter 0.17.1",
+ "tree-sitter",
"usvg",
]
@@ -2704,19 +2704,9 @@ dependencies = [
[[package]]
name = "tree-sitter"
-version = "0.17.1"
+version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d18dcb776d3affaba6db04d11d645946d34a69b3172e588af96ce9fecd20faac"
-dependencies = [
- "cc",
- "regex",
-]
-
-[[package]]
-name = "tree-sitter"
-version = "0.19.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1f41201fed3db3b520405a9c01c61773a250d4c3f43e9861c14b2bb232c981ab"
+checksum = "ad726ec26496bf4c083fff0f43d4eb3a2ad1bba305323af5ff91383c0b6ecac0"
dependencies = [
"cc",
"regex",
@@ -2729,7 +2719,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784f7ef9cdbd4c895dc2d4bb785e95b4a5364a602eec803681db83d1927ddf15"
dependencies = [
"cc",
- "tree-sitter 0.19.3",
+ "tree-sitter",
]
[[package]]
@@ -3007,7 +2997,7 @@ dependencies = [
"smallvec",
"smol",
"tempdir",
- "tree-sitter 0.19.3",
+ "tree-sitter",
"tree-sitter-rust",
"unindent",
]
@@ -26,7 +26,7 @@ serde_json = "1.0.64"
smallvec = {version = "1.6", features = ["union"]}
smol = "1.2"
tiny-skia = "0.5"
-tree-sitter = "0.17"
+tree-sitter = "0.19"
usvg = "0.14"
[build-dependencies]
@@ -0,0 +1,26 @@
+[package]
+name = "tree-sitter-context-predicate"
+description = "context-predicate grammar for the tree-sitter parsing library"
+version = "0.0.1"
+keywords = ["incremental", "parsing", "context-predicate"]
+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.19.3"
+
+[build-dependencies]
+cc = "1.0"
@@ -8,7 +8,7 @@
],
"sources": [
"src/parser.c",
- "src/binding.cc"
+ "bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99",
@@ -0,0 +1,19 @@
+try {
+ module.exports = require("../../build/Release/tree_sitter_context_predicate_binding");
+} catch (error1) {
+ if (error1.code !== 'MODULE_NOT_FOUND') {
+ throw error1;
+ }
+ try {
+ module.exports = require("../../build/Debug/tree_sitter_context_predicate_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 context_predicate 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_context_predicate::language()).expect("Error loading context_predicate 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_context_predicate() -> 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_context_predicate() }
+}
+
+/// 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 context_predicate language");
+ }
+}
@@ -1,13 +0,0 @@
-try {
- module.exports = require("./build/Release/tree_sitter_context_predicate_binding");
-} catch (error) {
- try {
- module.exports = require("./build/Debug/tree_sitter_context_predicate_binding");
- } catch (_) {
- throw error
- }
-}
-
-try {
- module.exports.nodeTypeInfo = require("./src/node-types.json");
-} catch (_) { }
@@ -9,7 +9,7 @@
"nan": "^2.14.0"
},
"devDependencies": {
- "tree-sitter-cli": "^0.18.3"
+ "tree-sitter-cli": "^0.19.5"
}
},
"node_modules/nan": {
@@ -18,9 +18,9 @@
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
},
"node_modules/tree-sitter-cli": {
- "version": "0.18.3",
- "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.18.3.tgz",
- "integrity": "sha512-ntN8Siljy7dlazb4cSYtZCfibaNppIy6RIr/XGt44GW1hAy/yuTLtKVi4kqYlImB4/7H0AjktcSlQRmI8zLNng==",
+ "version": "0.19.5",
+ "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.19.5.tgz",
+ "integrity": "sha512-kRzKrUAwpDN9AjA3b0tPBwT1hd8N2oQvvvHup2OEsX6mdsSMLmAvR+NSqK9fe05JrRbVvG8mbteNUQsxlMQohQ==",
"dev": true,
"hasInstallScript": true,
"bin": {
@@ -35,9 +35,9 @@
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
},
"tree-sitter-cli": {
- "version": "0.18.3",
- "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.18.3.tgz",
- "integrity": "sha512-ntN8Siljy7dlazb4cSYtZCfibaNppIy6RIr/XGt44GW1hAy/yuTLtKVi4kqYlImB4/7H0AjktcSlQRmI8zLNng==",
+ "version": "0.19.5",
+ "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.19.5.tgz",
+ "integrity": "sha512-kRzKrUAwpDN9AjA3b0tPBwT1hd8N2oQvvvHup2OEsX6mdsSMLmAvR+NSqK9fe05JrRbVvG8mbteNUQsxlMQohQ==",
"dev": true
}
}
@@ -1,8 +1,8 @@
{
"name": "tree-sitter-context-predicate",
- "main": "index.js",
+ "main": "bindings/node",
"devDependencies": {
- "tree-sitter-cli": "^0.18.3"
+ "tree-sitter-cli": "^0.19.5"
},
"dependencies": {
"nan": "^2.14.0"
@@ -5,7 +5,7 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
-#define LANGUAGE_VERSION 12
+#define LANGUAGE_VERSION 13
#define STATE_COUNT 18
#define LARGE_STATE_COUNT 6
#define SYMBOL_COUNT 17
@@ -14,6 +14,7 @@
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 3
#define MAX_ALIAS_SEQUENCE_LENGTH 3
+#define PRODUCTION_ID_COUNT 3
enum {
sym_identifier = 1,
@@ -34,7 +35,7 @@ enum {
sym_parenthesized = 16,
};
-static const char *ts_symbol_names[] = {
+static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
[sym_identifier] = "identifier",
[anon_sym_BANG] = "!",
@@ -54,7 +55,7 @@ static const char *ts_symbol_names[] = {
[sym_parenthesized] = "parenthesized",
};
-static TSSymbol ts_symbol_map[] = {
+static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
[sym_identifier] = sym_identifier,
[anon_sym_BANG] = anon_sym_BANG,
@@ -151,14 +152,14 @@ enum {
field_right = 3,
};
-static const char *ts_field_names[] = {
+static const char * const ts_field_names[] = {
[0] = NULL,
[field_expression] = "expression",
[field_left] = "left",
[field_right] = "right",
};
-static const TSFieldMapSlice ts_field_map_slices[3] = {
+static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 1},
[2] = {.index = 1, .length = 2},
};
@@ -171,11 +172,11 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_right, 2},
};
-static TSSymbol ts_alias_sequences[3][MAX_ALIAS_SEQUENCE_LENGTH] = {
+static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
[0] = {0},
};
-static uint16_t ts_non_terminal_alias_map[] = {
+static const uint16_t ts_non_terminal_alias_map[] = {
0,
};
@@ -279,7 +280,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
}
}
-static TSLexMode ts_lex_modes[STATE_COUNT] = {
+static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0},
[1] = {.lex_state = 1},
[2] = {.lex_state = 1},
@@ -300,7 +301,7 @@ static TSLexMode ts_lex_modes[STATE_COUNT] = {
[17] = {.lex_state = 0},
};
-static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
+static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
[sym_identifier] = ACTIONS(1),
@@ -375,7 +376,7 @@ static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
},
};
-static uint16_t ts_small_parse_table[] = {
+static const uint16_t ts_small_parse_table[] = {
[0] = 3,
ACTIONS(11), 1,
anon_sym_EQ_EQ,
@@ -448,7 +449,7 @@ static uint16_t ts_small_parse_table[] = {
sym_identifier,
};
-static uint32_t ts_small_parse_table_map[] = {
+static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(6)] = 0,
[SMALL_STATE(7)] = 13,
[SMALL_STATE(8)] = 20,
@@ -463,7 +464,7 @@ static uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(17)] = 85,
};
-static TSParseActionEntry ts_parse_actions[] = {
+static const TSParseActionEntry ts_parse_actions[] = {
[0] = {.entry = {.count = 0, .reusable = false}},
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6),
@@ -495,30 +496,31 @@ extern "C" {
#endif
extern const TSLanguage *tree_sitter_context_predicate(void) {
- static TSLanguage language = {
+ static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT,
.token_count = TOKEN_COUNT,
.external_token_count = EXTERNAL_TOKEN_COUNT,
- .symbol_names = ts_symbol_names,
- .symbol_metadata = ts_symbol_metadata,
- .parse_table = (const uint16_t *)ts_parse_table,
- .parse_actions = ts_parse_actions,
- .lex_modes = ts_lex_modes,
- .alias_sequences = (const TSSymbol *)ts_alias_sequences,
- .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
- .lex_fn = ts_lex,
+ .state_count = STATE_COUNT,
+ .large_state_count = LARGE_STATE_COUNT,
+ .production_id_count = PRODUCTION_ID_COUNT,
.field_count = FIELD_COUNT,
- .field_map_slices = (const TSFieldMapSlice *)ts_field_map_slices,
- .field_map_entries = (const TSFieldMapEntry *)ts_field_map_entries,
+ .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
+ .parse_table = &ts_parse_table[0][0],
+ .small_parse_table = ts_small_parse_table,
+ .small_parse_table_map = ts_small_parse_table_map,
+ .parse_actions = ts_parse_actions,
+ .symbol_names = ts_symbol_names,
.field_names = ts_field_names,
- .large_state_count = LARGE_STATE_COUNT,
- .small_parse_table = (const uint16_t *)ts_small_parse_table,
- .small_parse_table_map = (const uint32_t *)ts_small_parse_table_map,
+ .field_map_slices = ts_field_map_slices,
+ .field_map_entries = ts_field_map_entries,
+ .symbol_metadata = ts_symbol_metadata,
.public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map,
- .state_count = STATE_COUNT,
+ .alias_sequences = &ts_alias_sequences[0][0],
+ .lex_modes = ts_lex_modes,
+ .lex_fn = ts_lex,
};
return &language;
}
@@ -13,6 +13,8 @@ extern "C" {
#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;
@@ -30,12 +32,10 @@ typedef struct {
uint16_t length;
} TSFieldMapSlice;
-typedef uint16_t TSStateId;
-
typedef struct {
- bool visible : 1;
- bool named : 1;
- bool supertype: 1;
+ bool visible;
+ bool named;
+ bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
@@ -57,21 +57,21 @@ typedef enum {
TSParseActionTypeRecover,
} TSParseActionType;
-typedef struct {
- union {
- struct {
- TSStateId state;
- bool extra : 1;
- bool repetition : 1;
- } shift;
- struct {
- TSSymbol symbol;
- int16_t dynamic_precedence;
- uint8_t child_count;
- uint8_t production_id;
- } reduce;
- } params;
- TSParseActionType type : 4;
+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 {
@@ -83,7 +83,7 @@ typedef union {
TSParseAction action;
struct {
uint8_t count;
- bool reusable : 1;
+ bool reusable;
} entry;
} TSParseActionEntry;
@@ -93,13 +93,24 @@ struct TSLanguage {
uint32_t alias_count;
uint32_t token_count;
uint32_t external_token_count;
- const char **symbol_names;
- const TSSymbolMetadata *symbol_metadata;
+ 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 TSLexMode *lex_modes;
+ 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;
- uint16_t max_alias_sequence_length;
+ const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
@@ -112,16 +123,6 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} 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 SHIFT(state_value) \
- { \
- { \
- .params = { \
- .shift = { \
- .state = state_value \
- } \
- }, \
- .type = TSParseActionTypeShift \
- } \
- }
+#define SHIFT(state_value) \
+ {{ \
+ .shift = { \
+ .type = TSParseActionTypeShift, \
+ .state = state_value \
+ } \
+ }}
#define SHIFT_REPEAT(state_value) \
- { \
- { \
- .params = { \
- .shift = { \
- .state = state_value, \
- .repetition = true \
- } \
- }, \
- .type = TSParseActionTypeShift \
+ {{ \
+ .shift = { \
+ .type = TSParseActionTypeShift, \
+ .state = state_value, \
+ .repetition = true \
} \
- }
-
-#define RECOVER() \
- { \
- { .type = TSParseActionTypeRecover } \
- }
+ }}
#define SHIFT_EXTRA() \
- { \
- { \
- .params = { \
- .shift = { \
- .extra = true \
- } \
- }, \
- .type = TSParseActionTypeShift \
+ {{ \
+ .shift = { \
+ .type = TSParseActionTypeShift, \
+ .extra = true \
} \
- }
+ }}
#define REDUCE(symbol_val, child_count_val, ...) \
- { \
- { \
- .params = { \
- .reduce = { \
- .symbol = symbol_val, \
- .child_count = child_count_val, \
- __VA_ARGS__ \
- }, \
- }, \
- .type = TSParseActionTypeReduce \
- } \
- }
-
-#define ACCEPT_INPUT() \
- { \
- { .type = TSParseActionTypeAccept } \
- }
+ {{ \
+ .reduce = { \
+ .type = TSParseActionTypeReduce, \
+ .symbol = symbol_val, \
+ .child_count = child_count_val, \
+ __VA_ARGS__ \
+ }, \
+ }}
+
+#define RECOVER() \
+ {{ \
+ .type = TSParseActionTypeRecover \
+ }}
+
+#define ACCEPT_INPUT() \
+ {{ \
+ .type = TSParseActionTypeAccept \
+ }}
#ifdef __cplusplus
}
@@ -38,7 +38,7 @@ similar = "1.3"
simplelog = "0.9"
smallvec = {version = "1.6", features = ["union"]}
smol = "1.2.5"
-tree-sitter = "0.19.3"
+tree-sitter = "0.19.5"
tree-sitter-rust = "0.19.0"
[dev-dependencies]