1#include "tree_sitter/parser.h"
 2#include <wctype.h>
 3
 4enum TokenType {
 5  CONCAT,
 6  NS_DELIM,
 7};
 8
 9static bool is_eof(TSLexer *lexer) {
10  return lexer->lookahead == 0;
11}
12
13static bool is_concat_valid(TSLexer *lexer, const bool *valid_symbols) {
14  return valid_symbols[CONCAT] && (
15    iswalpha(lexer->lookahead) ||
16    lexer->lookahead == '$' ||
17    lexer->lookahead == '[' ||
18    lexer->lookahead == '_'
19  );
20  // return valid_symbols[CONCAT] && !(
21  //         is_eof(lexer) ||
22  //         iswspace(lexer->lookahead) ||
23  //         lexer->lookahead == ']' ||
24  //         lexer->lookahead == '$' ||
25  //         lexer->lookahead == ')' ||
26  //         lexer->lookahead == '}'
27  //         );
28}
29
30static bool scan_ns_delim(TSLexer *lexer) {
31  if (lexer->lookahead == ':') {
32    lexer->advance(lexer, false);
33    if (lexer->lookahead == ':') {
34      lexer->advance(lexer, false);
35      if (iswalpha(lexer->lookahead)) {
36        lexer->result_symbol = NS_DELIM;
37        return true;
38      }
39    }
40  }
41  return false;
42}
43
44void *tree_sitter_tcl_external_scanner_create() {
45  return NULL;
46}
47
48bool tree_sitter_tcl_external_scanner_scan(void *payload, TSLexer *lexer,
49                                          const bool *valid_symbols) {
50  if (valid_symbols[NS_DELIM]) {
51    return scan_ns_delim(lexer);
52  }
53
54  if (is_concat_valid(lexer, valid_symbols)) {
55    return true;
56  }
57
58  return false;
59}
60
61unsigned tree_sitter_tcl_external_scanner_serialize(void *payload, char *state) {
62  return 0;
63}
64
65void tree_sitter_tcl_external_scanner_deserialize(void *payload, const char *state, unsigned length){ }
66
67void tree_sitter_tcl_external_scanner_destroy(void *payload) {}