@konomanoasa/tree-sitter-awk 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/scanner.c CHANGED
@@ -333,12 +333,19 @@ static void skip_ascii_blanks(TSLexer *lexer) {
333
333
  }
334
334
  }
335
335
 
336
- static bool advance_comment_to_boundary(TSLexer *lexer);
336
+ static void advance_comment_to_boundary(TSLexer *lexer) {
337
+ if (lexer->lookahead != '#') {
338
+ return;
339
+ }
340
+ do {
341
+ lexer->advance(lexer, false);
342
+ } while (lexer->lookahead != '\n' && !lexer->eof(lexer));
343
+ }
337
344
 
338
345
  static bool advance_layout_gap(TSLexer *lexer) {
339
346
  for (;;) {
340
347
  skip_ascii_blanks(lexer);
341
- (void)advance_comment_to_boundary(lexer);
348
+ advance_comment_to_boundary(lexer);
342
349
  if (lexer->lookahead == '\n') {
343
350
  lexer->advance(lexer, false);
344
351
  continue;
@@ -402,28 +409,31 @@ static WordKind scan_word_kind(TSLexer *lexer) {
402
409
  return scan_func_name_suffix(lexer, scan_word_spelling(lexer));
403
410
  }
404
411
 
405
- static bool
406
- emit_word_kind(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
412
+ static const WordToken *find_word_token(WordKind kind) {
407
413
  for (size_t i = 0; i < ARRAY_LENGTH(WORD_TOKENS); i++) {
408
- if (WORD_TOKENS[i].kind == kind && valid_symbols[WORD_TOKENS[i].token]) {
409
- lexer->result_symbol = WORD_TOKENS[i].token;
410
- return true;
414
+ if (WORD_TOKENS[i].kind == kind) {
415
+ return &WORD_TOKENS[i];
411
416
  }
412
417
  }
418
+ return NULL;
419
+ }
413
420
 
414
- return false;
421
+ static bool
422
+ emit_word_kind(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
423
+ const WordToken *token = find_word_token(kind);
424
+ if (token == NULL || !valid_symbols[token->token]) {
425
+ return false;
426
+ }
427
+ lexer->result_symbol = token->token;
428
+ return true;
415
429
  }
416
430
 
417
431
  static bool word_token_is_valid(const bool *valid_symbols, WordKind kind) {
418
432
  if (kind == WORD_KIND_NAME && valid_symbols[FUNC_NAME_WORD]) {
419
433
  return true;
420
434
  }
421
- for (size_t i = 0; i < ARRAY_LENGTH(WORD_TOKENS); i++) {
422
- if (WORD_TOKENS[i].kind == kind && valid_symbols[WORD_TOKENS[i].token]) {
423
- return true;
424
- }
425
- }
426
- return false;
435
+ const WordToken *token = find_word_token(kind);
436
+ return token != NULL && valid_symbols[token->token];
427
437
  }
428
438
 
429
439
  static bool
@@ -450,12 +460,8 @@ static bool has_word_marker(const bool *valid_symbols) {
450
460
  }
451
461
 
452
462
  static unsigned word_roles(WordKind kind) {
453
- for (size_t i = 0; i < ARRAY_LENGTH(WORD_TOKENS); i++) {
454
- if (WORD_TOKENS[i].kind == kind) {
455
- return WORD_TOKENS[i].roles;
456
- }
457
- }
458
- return 0;
463
+ const WordToken *token = find_word_token(kind);
464
+ return token == NULL ? 0 : token->roles;
459
465
  }
460
466
 
461
467
  static bool word_has_role(WordKind kind, unsigned roles) {
@@ -642,10 +648,8 @@ has_greater_start(const bool *valid_symbols, bool allow_zero_width_guard) {
642
648
  (allow_zero_width_guard && valid_symbols[OUTPUT_GREATER_GUARD]);
643
649
  }
644
650
 
645
- // '>' can start GE, APPEND or a plain redirection '>'. One dispatcher decides
646
- // from the following character, so a two-character operator that turns out to
647
- // be invalid cannot block the zero-width redirection guard. Error mode emits
648
- // only operators that have source text.
651
+ // Dispatch together so an invalid two-character operator cannot block the
652
+ // zero-width redirection guard.
649
653
  static bool scan_greater_start(
650
654
  TSLexer *lexer,
651
655
  const bool *valid_symbols,
@@ -689,8 +693,6 @@ static bool scan_slash_start(
689
693
  lexer->result_symbol = DIV_ASSIGN_OPERATOR;
690
694
  return true;
691
695
  }
692
- // Where division is valid, "/=" is the longest match: never split it
693
- // into a division slash followed by '='.
694
696
  if (valid_symbols[DIVISION_SLASH]) {
695
697
  return false;
696
698
  }
@@ -733,8 +735,6 @@ static bool emit_word_item_boundary(
733
735
  return false;
734
736
  }
735
737
 
736
- // Requires lexer->lookahead == '\n': decides whether the required target
737
- // follows the raw newline.
738
738
  static bool
739
739
  scan_required_target_guard(TSLexer *lexer, const bool *valid_symbols) {
740
740
  lexer->advance(lexer, false);
@@ -799,12 +799,10 @@ static bool scan_ere_backslash_context(
799
799
  }
800
800
 
801
801
  lexer->advance(lexer, false);
802
- if (
803
- !valid_symbols[ERROR_SENTINEL] &&
804
- lexer->lookahead ==
805
- '/' &&
806
- valid_symbols[ERE_ESCAPED_DELIMITER_START]
807
- ) {
802
+ if (valid_symbols[ERROR_SENTINEL]) {
803
+ return false;
804
+ }
805
+ if (lexer->lookahead == '/' && valid_symbols[ERE_ESCAPED_DELIMITER_START]) {
808
806
  lexer->result_symbol = ERE_ESCAPED_DELIMITER_START;
809
807
  state->ere_mode = ERE_MODE_ESCAPED_DELIMITER;
810
808
  return true;
@@ -813,7 +811,6 @@ static bool scan_ere_backslash_context(
813
811
  lexer->lookahead !=
814
812
  '\n' &&
815
813
  !lexer->eof(lexer) &&
816
- !valid_symbols[ERROR_SENTINEL] &&
817
814
  valid_symbols[ERE_ESCAPE_START]
818
815
  ) {
819
816
  lexer->result_symbol = ERE_ESCAPE_START;
@@ -883,16 +880,6 @@ static bool word_starts_simple_statement(WordKind kind) {
883
880
  }
884
881
  }
885
882
 
886
- static bool advance_comment_to_boundary(TSLexer *lexer) {
887
- if (lexer->lookahead != '#') {
888
- return false;
889
- }
890
- do {
891
- lexer->advance(lexer, false);
892
- } while (lexer->lookahead != '\n' && !lexer->eof(lexer));
893
- return true;
894
- }
895
-
896
883
  static bool scan_boundary_target(TSLexer *lexer, const bool *valid_symbols) {
897
884
  const bool expression_valid = valid_symbols[LC_BEFORE_EXPRESSION];
898
885
  enum TokenType delimiter;
@@ -1066,7 +1053,6 @@ static bool scan_boundary_target(TSLexer *lexer, const bool *valid_symbols) {
1066
1053
  }
1067
1054
 
1068
1055
  static bool has_line_continuation_marker(const bool *valid_symbols) {
1069
- // The LC_BEFORE_* tokens form one contiguous enum range.
1070
1056
  for (
1071
1057
  enum TokenType token = LC_BEFORE_OPERATOR; token <= LC_BEFORE_CLOSE_BRACKET;
1072
1058
  token++
@@ -0,0 +1,6 @@
1
+ #include <stddef.h>
2
+ #include <tree_sitter/tree-sitter-awk.h>
3
+
4
+ int main(void) {
5
+ return tree_sitter_awk() == NULL;
6
+ }
package/tree-sitter.json CHANGED
@@ -11,7 +11,7 @@
11
11
  }
12
12
  ],
13
13
  "metadata": {
14
- "version": "0.2.0",
14
+ "version": "0.4.0",
15
15
  "license": "MIT",
16
16
  "description": "Tree-sitter grammar for POSIX awk.",
17
17
  "authors": [
@@ -24,7 +24,7 @@
24
24
  }
25
25
  },
26
26
  "bindings": {
27
- "c": false,
27
+ "c": true,
28
28
  "go": false,
29
29
  "node": false,
30
30
  "python": false,