Skip to content

Commit

Permalink
bump tree-sitter-cli in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed May 4, 2024
1 parent b2a98a4 commit a42d196
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Nix derivation: `nix build .#parser-lib`
The parser can be compiled to WebAssembly as well, which requires `emscripten`:

```
$ tree-sitter build-wasm
$ tree-sitter build --wasm
```

The resulting binary is written to `$PWD/tree-sitter-haskell.wasm`.
Expand Down
3 changes: 3 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ fn main() {
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
#[cfg(target_env = "msvc")]
c_config.flag("-utf-8");

let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);

Expand Down
2 changes: 1 addition & 1 deletion nix/outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
runHook preBuild
mkdir -p .emscriptencache
export EM_CACHE=$(pwd)/.emscriptencache
tree-sitter build-wasm
tree-sitter build --wasm
runHook postBuild
'';

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"devDependencies": {
"prebuildify": "^6.0.0",
"tree-sitter-cli": "^0.21.0",
"tree-sitter-cli": "^0.22.0",
"web-tree-sitter": "^0.21.0"
},
"scripts": {
Expand Down
51 changes: 43 additions & 8 deletions src/tree_sitter/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ typedef union {
} entry;
} TSParseActionEntry;

typedef struct {
int32_t start;
int32_t end;
} TSCharacterRange;

struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
Expand Down Expand Up @@ -125,6 +130,24 @@ struct TSLanguage {
const TSStateId *primary_state_ids;
};

static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}

/*
* Lexer Macros
*/
Expand Down Expand Up @@ -154,6 +177,17 @@ struct TSLanguage {
goto next_state; \
}

#define ADVANCE_MAP(...) \
{ \
static const uint16_t map[] = { __VA_ARGS__ }; \
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
if (map[i] == lookahead) { \
state = map[i + 1]; \
goto next_state; \
} \
} \
}

#define SKIP(state_value) \
{ \
skip = true; \
Expand Down Expand Up @@ -203,14 +237,15 @@ struct TSLanguage {
} \
}}

#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
#define REDUCE(symbol_name, children, precedence, prod_id) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_name, \
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
}, \
}}

#define RECOVER() \
Expand Down

0 comments on commit a42d196

Please sign in to comment.