diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c27899..0131df7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,21 +2,20 @@ name: Test grammar on: push: - branches: [master] + branches: ["*"] + paths: + - grammar.js + - src/** + - bindings/** + - binding.gyp pull_request: - branches: [master] + branches: ["*"] + paths: + - grammar.js + - src/** + - bindings/** + - binding.gyp jobs: test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - name: Checkout repository - - uses: actions/setup-node@v4 - name: Set up NodeJS - with: - node-version: 20 - - run: npm install - name: Install dependencies - - run: npm test - name: Run tests + uses: tree-sitter-grammars/.github/.github/workflows/ci.yml@main diff --git a/Cargo.toml b/Cargo.toml index 4b20218..2132990 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "tree-sitter-poe-filter" description = "poe-filter grammar for the tree-sitter parsing library" -version = "0.2.1" +version = "0.3.0" keywords = ["incremental", "parsing", "poe-filter"] categories = ["parsing", "text-editors"] -repository = "https://github.com/ObserverOfTime/tree-sitter-poe-filter" +repository = "https://github.com/tree-sitter-grammars/tree-sitter-poe-filter" edition = "2021" license = "MIT" diff --git a/README.md b/README.md index 9845fea..73f5a2d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # tree-sitter-poe-filter -[![CI][badge]](https://github.com/ObserverOfTime/tree-sitter-poe-filter/actions) +[![CI][ci]](https://github.com/tree-sitter-grammars/tree-sitter-poe-filter/actions) +[![discord][discord]](https://discord.gg/w7nTvsVJhm) +[![matrix][matrix]](https://matrix.to/#/#nvim-treesitter:matrix.org) A tree-sitter parser for Path of Exile item filters. @@ -15,5 +17,8 @@ A tree-sitter parser for Path of Exile item filters. - [x] Neovim - [ ] Helix - [ ] Emacs +- [ ] Zed -[badge]: https://badgen.net/github/checks/ObserverOfTime/tree-sitter-poe-filter?label=CI&icon=github +[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter-grammars/tree-sitter-poe-filter/ci.yml?logo=github&label=CI +[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=tree-sitter +[matrix]: https://img.shields.io/matrix/nvim-treesitter%3Amatrix.org?logo=matrix&label=nvim-treesitter diff --git a/binding.gyp b/binding.gyp index ae31815..6cb0e49 100644 --- a/binding.gyp +++ b/binding.gyp @@ -9,10 +9,13 @@ "sources": [ "bindings/node/binding.cc", "src/parser.c", - # If your language uses an external scanner, add it here. ], "cflags_c": [ "-std=c99", + "-Wno-unused-but-set-variable" + ], + "cflags_cc": [ + "-Wno-cast-function-type" ] } ] diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index c6061f0..a1a8927 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -2,39 +2,14 @@ fn main() { let src_dir = std::path::Path::new("src"); let mut c_config = cc::Build::new(); - c_config.include(&src_dir); + 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"); + .flag_if_supported("-Wno-parentheses"); 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()); - */ } diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 8e8d89d..3ebae8f 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -4,10 +4,16 @@ //! tree-sitter [Parser][], and then use the parser to parse some code: //! //! ``` -//! let code = ""; +//! let code = r#" +//! Show +//! Class Currency +//! Hide +//! Rarity Normal +//! "#; //! let mut parser = tree_sitter::Parser::new(); //! parser.set_language(tree_sitter_poe_filter::language()).expect("Error loading poe_filter grammar"); //! let tree = parser.parse(code, None).unwrap(); +//! assert!(!tree.root_node().has_error()); //! ``` //! //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html @@ -31,14 +37,7 @@ pub fn language() -> Language { /// 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"); +pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); #[cfg(test)] mod tests { diff --git a/package.json b/package.json index 8d54997..405a174 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-poe-filter", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "description": "PoE filter grammar for tree-sitter", "repository": "ObserverOfTime/tree-sitter-poe-filter", @@ -25,7 +25,7 @@ "nan": "^2.18.0" }, "devDependencies": { - "tree-sitter-cli": "^0.20.8" + "tree-sitter-cli": "~0.21.0-pre-release-1" }, "tree-sitter": [ { diff --git a/src/parser.c b/src/parser.c index e5c645a..4f4df58 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,4 +1,4 @@ -#include +#include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push @@ -24,7 +24,7 @@ #define MAX_ALIAS_SEQUENCE_LENGTH 10 #define PRODUCTION_ID_COUNT 26 -enum { +enum ts_symbol_identifiers { anon_sym_Show = 1, anon_sym_Hide = 2, anon_sym_Minimal = 3, @@ -1176,7 +1176,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }, }; -enum { +enum ts_field_identifiers { field_alpha = 1, field_blue = 2, field_class = 3, @@ -6206,7 +6206,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 1021: ACCEPT_TOKEN(aux_sym_file_token1); - if ((0 <= lookahead && lookahead <= '\t') || + if (!eof && (0 <= lookahead && lookahead <= '\t') || (11 <= lookahead && lookahead <= 31) || lookahead == '"' || lookahead == '*' || diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 2b14ac1..17b4fde 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -13,9 +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 TSStateId; typedef uint16_t TSSymbol; typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; @@ -130,9 +129,16 @@ struct TSLanguage { * Lexer Macros */ +#ifdef _MSC_VER +#define UNUSED __pragma(warning(suppress : 4101)) +#else +#define UNUSED __attribute__((unused)) +#endif + #define START_LEXER() \ bool result = false; \ bool skip = false; \ + UNUSED \ bool eof = false; \ int32_t lookahead; \ goto start; \ @@ -166,7 +172,7 @@ struct TSLanguage { * Parse Table Macros */ -#define SMALL_STATE(id) id - LARGE_STATE_COUNT +#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) #define STATE(id) id @@ -176,7 +182,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value \ + .state = (state_value) \ } \ }} @@ -184,7 +190,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value, \ + .state = (state_value), \ .repetition = true \ } \ }}