diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-22 12:49:58 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-22 12:49:58 +0100 |
| commit | 0dce637073c97752e436ee5a1d1e16bf3dc8e7b2 (patch) | |
| tree | a79b36c2f7009bc9c18023e53a466a5ad4777529 /vendor/tree-sitter-tcl/src/scanner.c | |
| parent | 59b30c1305ff6bcb63c673898893edcda19e27e4 (diff) | |
| download | crep-0dce637073c97752e436ee5a1d1e16bf3dc8e7b2.tar.gz | |
Add Tcl grammar and ABI compliance check
Diffstat (limited to 'vendor/tree-sitter-tcl/src/scanner.c')
| -rw-r--r-- | vendor/tree-sitter-tcl/src/scanner.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/tree-sitter-tcl/src/scanner.c b/vendor/tree-sitter-tcl/src/scanner.c new file mode 100644 index 0000000..f55054a --- /dev/null +++ b/vendor/tree-sitter-tcl/src/scanner.c @@ -0,0 +1,67 @@ +#include "tree_sitter/parser.h" +#include <wctype.h> + +enum TokenType { + CONCAT, + NS_DELIM, +}; + +static bool is_eof(TSLexer *lexer) { + return lexer->lookahead == 0; +} + +static bool is_concat_valid(TSLexer *lexer, const bool *valid_symbols) { + return valid_symbols[CONCAT] && ( + iswalpha(lexer->lookahead) || + lexer->lookahead == '$' || + lexer->lookahead == '[' || + lexer->lookahead == '_' + ); + // return valid_symbols[CONCAT] && !( + // is_eof(lexer) || + // iswspace(lexer->lookahead) || + // lexer->lookahead == ']' || + // lexer->lookahead == '$' || + // lexer->lookahead == ')' || + // lexer->lookahead == '}' + // ); +} + +static bool scan_ns_delim(TSLexer *lexer) { + if (lexer->lookahead == ':') { + lexer->advance(lexer, false); + if (lexer->lookahead == ':') { + lexer->advance(lexer, false); + if (iswalpha(lexer->lookahead)) { + lexer->result_symbol = NS_DELIM; + return true; + } + } + } + return false; +} + +void *tree_sitter_tcl_external_scanner_create() { + return NULL; +} + +bool tree_sitter_tcl_external_scanner_scan(void *payload, TSLexer *lexer, + const bool *valid_symbols) { + if (valid_symbols[NS_DELIM]) { + return scan_ns_delim(lexer); + } + + if (is_concat_valid(lexer, valid_symbols)) { + return true; + } + + return false; +} + +unsigned tree_sitter_tcl_external_scanner_serialize(void *payload, char *state) { + return 0; +} + +void tree_sitter_tcl_external_scanner_deserialize(void *payload, const char *state, unsigned length){ } + +void tree_sitter_tcl_external_scanner_destroy(void *payload) {} |
