@konomanoasa/tree-sitter-posix-awk 0.13.0 → 0.15.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
@@ -7,23 +7,23 @@
7
7
  #define ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
8
8
 
9
9
  enum TokenType {
10
- BEGIN_WORD,
11
- END_WORD,
12
- FUNCTION_WORD,
13
- PRINT_WORD,
14
- BREAK_WORD,
15
- CONTINUE_WORD,
16
- DELETE_WORD,
17
- DO_WORD,
18
- ELSE_WORD,
19
- EXIT_WORD,
20
- FOR_WORD,
21
- IF_WORD,
22
- NEXT_WORD,
23
- NEXTFILE_WORD,
24
- PRINTF_WORD,
25
- RETURN_WORD,
26
- WHILE_WORD,
10
+ BEGIN_KEYWORD,
11
+ END_KEYWORD,
12
+ FUNCTION_KEYWORD,
13
+ PRINT_KEYWORD,
14
+ BREAK_KEYWORD,
15
+ CONTINUE_KEYWORD,
16
+ DELETE_KEYWORD,
17
+ DO_KEYWORD,
18
+ ELSE_KEYWORD,
19
+ EXIT_KEYWORD,
20
+ FOR_KEYWORD,
21
+ IF_KEYWORD,
22
+ NEXT_KEYWORD,
23
+ NEXTFILE_KEYWORD,
24
+ PRINTF_KEYWORD,
25
+ RETURN_KEYWORD,
26
+ WHILE_KEYWORD,
27
27
  NAME_WORD,
28
28
  FOR_IN_VARIABLE_WORD,
29
29
  GETLINE_WORD,
@@ -31,9 +31,7 @@ enum TokenType {
31
31
  BUILTIN_FUNC_NAME_WORD,
32
32
  BUILTIN_CALL_WORD,
33
33
  FUNC_NAME_WORD,
34
- NUMBER_INTEGER,
35
- NUMBER_FRACTION,
36
- NUMBER_EXPONENT,
34
+ NUMBER,
37
35
  DIVISION_SLASH,
38
36
  ERE_OPENING_SLASH,
39
37
  DIV_ASSIGN_OPERATOR,
@@ -52,20 +50,39 @@ enum TokenType {
52
50
  INCR_OPERATOR,
53
51
  DECR_OPERATOR,
54
52
  APPEND_OPERATOR,
55
- OUTPUT_GREATER_GUARD,
56
- ERE_COMPOUND_OPEN_GUARD,
57
- ERE_DOT_CLOSE_GUARD,
58
- ERE_EQUAL_CLOSE_GUARD,
59
- ERE_COLON_CLOSE_GUARD,
60
- ERE_ESCAPE_START,
61
- ERE_ESCAPED_DELIMITER_START,
62
- ERE_ESCAPED_DELIMITER_END,
53
+ PLUS_OPERATOR,
54
+ MINUS_OPERATOR,
55
+ STAR_OPERATOR,
56
+ PERCENT_OPERATOR,
57
+ CARET_OPERATOR,
58
+ BANG_OPERATOR,
59
+ LESS_OPERATOR,
60
+ GREATER_OPERATOR,
61
+ EQUAL_OPERATOR,
62
+ PIPE_OPERATOR,
63
+ OUTPUT_GREATER,
64
+ ERE_COMPOUND_OPENING,
65
+ ERE_DOT_CLOSING,
66
+ ERE_EQUAL_CLOSING,
67
+ ERE_COLON_CLOSING,
68
+ ERE_BRACKET_LITERAL_OPEN,
69
+ ERE_COMPOUND_CONTENT,
63
70
  ERE_CLOSING_HYPHEN,
64
71
  ERE_CLOSING,
65
72
  STRING_OPENING,
66
- STRING_END,
73
+ STRING_CLOSING,
74
+ STRING_CONTENT,
75
+ STRING_ESCAPE,
76
+ ERE_NAMED_ESCAPE,
77
+ ERE_QUOTED_ESCAPE,
78
+ ERE_OCTAL_ESCAPE,
79
+ ERE_UNDEFINED_ESCAPE,
80
+ ERE_ESCAPED_DELIMITER,
81
+ ERE_CLASS_NAME,
82
+ ERE_DUP_COUNT,
67
83
  COMMENT,
68
- SPLIT_TOKEN,
84
+ CONTINUATION_BACKSLASH,
85
+ CONTINUATION_NEWLINE,
69
86
  ERROR_SENTINEL,
70
87
  TOKEN_TYPE_COUNT,
71
88
  };
@@ -123,18 +140,14 @@ typedef struct {
123
140
  enum TokenType token;
124
141
  } CompositeOperator;
125
142
 
126
- typedef enum {
127
- NUMBER_KIND_NONE,
128
- NUMBER_KIND_INTEGER,
129
- NUMBER_KIND_FRACTION,
130
- NUMBER_KIND_EXPONENT,
131
- } NumberKind;
132
-
133
143
  typedef enum {
134
144
  LEXICAL_MODE_OUTSIDE,
135
145
  LEXICAL_MODE_ERE_BODY,
136
- LEXICAL_MODE_ERE_ESCAPED_DELIMITER,
146
+ LEXICAL_MODE_ERE_COLLATING,
147
+ LEXICAL_MODE_ERE_EQUIVALENCE,
148
+ LEXICAL_MODE_ERE_CLASS,
137
149
  LEXICAL_MODE_STRING,
150
+ LEXICAL_MODE_CONTINUED_NEWLINE,
138
151
  } LexicalMode;
139
152
 
140
153
  typedef struct {
@@ -186,23 +199,23 @@ static const WordEntry WORDS[] = {
186
199
  };
187
200
 
188
201
  static const WordToken WORD_TOKENS[] = {
189
- {WORD_KIND_BEGIN, BEGIN_WORD},
190
- {WORD_KIND_END, END_WORD},
191
- {WORD_KIND_FUNCTION, FUNCTION_WORD},
192
- {WORD_KIND_PRINT, PRINT_WORD},
193
- {WORD_KIND_BREAK, BREAK_WORD},
194
- {WORD_KIND_CONTINUE, CONTINUE_WORD},
195
- {WORD_KIND_DELETE, DELETE_WORD},
196
- {WORD_KIND_DO, DO_WORD},
197
- {WORD_KIND_ELSE, ELSE_WORD},
198
- {WORD_KIND_EXIT, EXIT_WORD},
199
- {WORD_KIND_FOR, FOR_WORD},
200
- {WORD_KIND_IF, IF_WORD},
201
- {WORD_KIND_NEXT, NEXT_WORD},
202
- {WORD_KIND_NEXTFILE, NEXTFILE_WORD},
203
- {WORD_KIND_PRINTF, PRINTF_WORD},
204
- {WORD_KIND_RETURN, RETURN_WORD},
205
- {WORD_KIND_WHILE, WHILE_WORD},
202
+ {WORD_KIND_BEGIN, BEGIN_KEYWORD},
203
+ {WORD_KIND_END, END_KEYWORD},
204
+ {WORD_KIND_FUNCTION, FUNCTION_KEYWORD},
205
+ {WORD_KIND_PRINT, PRINT_KEYWORD},
206
+ {WORD_KIND_BREAK, BREAK_KEYWORD},
207
+ {WORD_KIND_CONTINUE, CONTINUE_KEYWORD},
208
+ {WORD_KIND_DELETE, DELETE_KEYWORD},
209
+ {WORD_KIND_DO, DO_KEYWORD},
210
+ {WORD_KIND_ELSE, ELSE_KEYWORD},
211
+ {WORD_KIND_EXIT, EXIT_KEYWORD},
212
+ {WORD_KIND_FOR, FOR_KEYWORD},
213
+ {WORD_KIND_IF, IF_KEYWORD},
214
+ {WORD_KIND_NEXT, NEXT_KEYWORD},
215
+ {WORD_KIND_NEXTFILE, NEXTFILE_KEYWORD},
216
+ {WORD_KIND_PRINTF, PRINTF_KEYWORD},
217
+ {WORD_KIND_RETURN, RETURN_KEYWORD},
218
+ {WORD_KIND_WHILE, WHILE_KEYWORD},
206
219
  {WORD_KIND_NAME, NAME_WORD},
207
220
  {WORD_KIND_FOR_IN_VARIABLE, FOR_IN_VARIABLE_WORD},
208
221
  {WORD_KIND_GETLINE, GETLINE_WORD},
@@ -231,10 +244,32 @@ static const CompositeOperator COMPOSITE_OPERATORS[] = {
231
244
  {'>', '>', APPEND_OPERATOR},
232
245
  };
233
246
 
247
+ typedef struct {
248
+ int32_t character;
249
+ enum TokenType token;
250
+ } SingleOperator;
251
+
252
+ static const SingleOperator SINGLE_OPERATORS[] = {
253
+ {'+', PLUS_OPERATOR},
254
+ {'-', MINUS_OPERATOR},
255
+ {'*', STAR_OPERATOR},
256
+ {'%', PERCENT_OPERATOR},
257
+ {'^', CARET_OPERATOR},
258
+ {'!', BANG_OPERATOR},
259
+ {'<', LESS_OPERATOR},
260
+ {'>', GREATER_OPERATOR},
261
+ {'=', EQUAL_OPERATOR},
262
+ {'|', PIPE_OPERATOR},
263
+ };
264
+
234
265
  static bool is_ascii_blank(int32_t character) {
235
266
  return character == ' ' || character == '\t';
236
267
  }
237
268
 
269
+ static bool is_ere_mode(LexicalMode mode) {
270
+ return mode >= LEXICAL_MODE_ERE_BODY && mode <= LEXICAL_MODE_ERE_CLASS;
271
+ }
272
+
238
273
  static bool is_ascii_digit(int32_t character) {
239
274
  return character >= '0' && character <= '9';
240
275
  }
@@ -252,62 +287,6 @@ static bool is_word_continue(int32_t character) {
252
287
  return is_word_start(character) || is_ascii_digit(character);
253
288
  }
254
289
 
255
- typedef enum {
256
- CONTINUATION_NONE,
257
- CONTINUATION_PAIRS,
258
- CONTINUATION_INVALID,
259
- } ContinuationResult;
260
-
261
- static ContinuationResult advance_line_continuations(TSLexer *lexer) {
262
- ContinuationResult result = CONTINUATION_NONE;
263
-
264
- while (lexer->lookahead == '\\') {
265
- lexer->advance(lexer, false);
266
- if (lexer->lookahead != '\n') {
267
- return CONTINUATION_INVALID;
268
- }
269
-
270
- lexer->advance(lexer, false);
271
- result = CONTINUATION_PAIRS;
272
- }
273
-
274
- return result;
275
- }
276
-
277
- // Skipping during lookahead would move the token start past its marked end.
278
- static void skip_ascii_blanks(TSLexer *lexer) {
279
- while (is_ascii_blank(lexer->lookahead)) {
280
- lexer->advance(lexer, true);
281
- }
282
- }
283
-
284
- static void advance_ascii_blanks(TSLexer *lexer) {
285
- while (is_ascii_blank(lexer->lookahead)) {
286
- lexer->advance(lexer, false);
287
- }
288
- }
289
-
290
- static void advance_comment_to_boundary(TSLexer *lexer) {
291
- if (lexer->lookahead != '#') {
292
- return;
293
- }
294
- do {
295
- lexer->advance(lexer, false);
296
- } while (lexer->lookahead != '\n' && !lexer->eof(lexer));
297
- }
298
-
299
- static bool advance_boundary_gap_remainder(TSLexer *lexer) {
300
- for (;;) {
301
- advance_ascii_blanks(lexer);
302
- if (lexer->lookahead != '\\') {
303
- return true;
304
- }
305
- if (advance_line_continuations(lexer) == CONTINUATION_INVALID) {
306
- return false;
307
- }
308
- }
309
- }
310
-
311
290
  static bool emit(TSLexer *lexer, enum TokenType token) {
312
291
  lexer->result_symbol = token;
313
292
  return true;
@@ -327,54 +306,60 @@ static WordKind classify_word(const char *word, size_t length) {
327
306
  if (length > MAX_RESERVED_WORD_LENGTH) {
328
307
  return WORD_KIND_NAME;
329
308
  }
330
-
331
309
  for (size_t i = 0; i < ARRAY_LENGTH(WORDS); i++) {
332
310
  if (strcmp(WORDS[i].spelling, word) == 0) {
333
311
  return WORDS[i].kind;
334
312
  }
335
313
  }
336
-
337
314
  return WORD_KIND_NAME;
338
315
  }
339
316
 
340
317
  static WordKind scan_word_spelling(TSLexer *lexer) {
341
- char word[MAX_RESERVED_WORD_LENGTH + 1] = {0};
318
+ char spelling[MAX_RESERVED_WORD_LENGTH + 1] = {0};
342
319
  size_t length = 0;
343
-
344
320
  if (!is_word_start(lexer->lookahead)) {
345
321
  return WORD_KIND_NONE;
346
322
  }
347
-
348
- while (is_word_continue(lexer->lookahead)) {
323
+ do {
349
324
  if (length < MAX_RESERVED_WORD_LENGTH) {
350
- word[length] = (char)lexer->lookahead;
325
+ spelling[length] = (char)lexer->lookahead;
351
326
  }
352
327
  if (length <= MAX_RESERVED_WORD_LENGTH) {
353
328
  length++;
354
329
  }
355
330
  lexer->advance(lexer, false);
356
- }
331
+ } while (is_word_continue(lexer->lookahead));
332
+ return classify_word(spelling, length);
333
+ }
357
334
 
358
- return classify_word(word, length);
335
+ static bool skip_token_layout(TSLexer *lexer) {
336
+ for (;;) {
337
+ if (is_ascii_blank(lexer->lookahead)) {
338
+ lexer->advance(lexer, false);
339
+ } else if (lexer->lookahead == '\\') {
340
+ lexer->advance(lexer, false);
341
+ if (lexer->lookahead != '\n') {
342
+ return false;
343
+ }
344
+ lexer->advance(lexer, false);
345
+ } else {
346
+ return true;
347
+ }
348
+ }
359
349
  }
360
350
 
361
351
  static bool scan_for_in_shape(TSLexer *lexer) {
352
+ if (!skip_token_layout(lexer) || scan_word_spelling(lexer) != WORD_KIND_IN) {
353
+ return false;
354
+ }
362
355
  if (
363
- !advance_boundary_gap_remainder(lexer) ||
364
- scan_word_spelling(lexer) !=
365
- WORD_KIND_IN ||
366
- !advance_boundary_gap_remainder(lexer) ||
367
- scan_word_spelling(lexer) !=
368
- WORD_KIND_NAME ||
369
- !advance_boundary_gap_remainder(lexer)
356
+ !skip_token_layout(lexer) || scan_word_spelling(lexer) != WORD_KIND_NAME
370
357
  ) {
371
358
  return false;
372
359
  }
373
- return lexer->lookahead == ')';
360
+ return skip_token_layout(lexer) && lexer->lookahead == ')';
374
361
  }
375
362
 
376
- // Only promote for-in variables where expected: the same spelling can be
377
- // a parenthesized membership test.
378
363
  static WordKind
379
364
  promote_word_kind(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
380
365
  switch (kind) {
@@ -387,10 +372,9 @@ promote_word_kind(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
387
372
  }
388
373
  return kind;
389
374
  case WORD_KIND_BUILTIN_FUNC_NAME:
390
- if (!advance_boundary_gap_remainder(lexer)) {
391
- return kind;
392
- }
393
- return lexer->lookahead == '(' ? WORD_KIND_BUILTIN_CALL : kind;
375
+ return skip_token_layout(lexer) && lexer->lookahead == '('
376
+ ? WORD_KIND_BUILTIN_CALL
377
+ : kind;
394
378
  default:
395
379
  return kind;
396
380
  }
@@ -405,60 +389,6 @@ static const WordToken *find_word_token(WordKind kind) {
405
389
  return NULL;
406
390
  }
407
391
 
408
- static bool
409
- emit_word_kind(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
410
- const WordToken *token = find_word_token(kind);
411
- if (token == NULL || !valid_symbols[token->token]) {
412
- return false;
413
- }
414
- return emit(lexer, token->token);
415
- }
416
-
417
- static bool word_kind_is_valid(const bool *valid_symbols, WordKind kind) {
418
- const WordToken *token = find_word_token(kind);
419
- return token != NULL && valid_symbols[token->token];
420
- }
421
-
422
- static bool word_spelling_is_valid(const bool *valid_symbols, WordKind kind) {
423
- switch (kind) {
424
- case WORD_KIND_NAME:
425
- return word_kind_is_valid(valid_symbols, WORD_KIND_NAME) ||
426
- word_kind_is_valid(valid_symbols, WORD_KIND_FUNC_NAME) ||
427
- word_kind_is_valid(valid_symbols, WORD_KIND_FOR_IN_VARIABLE);
428
- case WORD_KIND_BUILTIN_FUNC_NAME:
429
- return word_kind_is_valid(valid_symbols, kind) ||
430
- word_kind_is_valid(valid_symbols, WORD_KIND_BUILTIN_CALL);
431
- default:
432
- return word_kind_is_valid(valid_symbols, kind);
433
- }
434
- }
435
-
436
- static bool
437
- scan_word_token(TSLexer *lexer, const bool *valid_symbols, WordKind kind) {
438
- lexer->mark_end(lexer);
439
- const ContinuationResult continuation = advance_line_continuations(lexer);
440
- if (continuation == CONTINUATION_INVALID) {
441
- return emit_word_kind(lexer, valid_symbols, kind);
442
- }
443
- if (
444
- continuation == CONTINUATION_PAIRS && is_word_continue(lexer->lookahead)
445
- ) {
446
- if (!valid_symbols[SPLIT_TOKEN]) {
447
- return false;
448
- }
449
- lexer->mark_end(lexer);
450
- return emit(lexer, SPLIT_TOKEN);
451
- }
452
- if (!word_spelling_is_valid(valid_symbols, kind)) {
453
- return false;
454
- }
455
- return emit_word_kind(
456
- lexer,
457
- valid_symbols,
458
- promote_word_kind(lexer, valid_symbols, kind)
459
- );
460
- }
461
-
462
392
  static bool has_word_token(const bool *valid_symbols) {
463
393
  for (size_t i = 0; i < ARRAY_LENGTH(WORD_TOKENS); i++) {
464
394
  if (valid_symbols[WORD_TOKENS[i].token]) {
@@ -468,88 +398,52 @@ static bool has_word_token(const bool *valid_symbols) {
468
398
  return false;
469
399
  }
470
400
 
471
- static enum TokenType number_kind_token(NumberKind kind) {
472
- switch (kind) {
473
- case NUMBER_KIND_FRACTION:
474
- return NUMBER_FRACTION;
475
- case NUMBER_KIND_EXPONENT:
476
- return NUMBER_EXPONENT;
477
- default:
478
- return NUMBER_INTEGER;
479
- }
480
- }
481
-
482
- static bool peek_number_continuations(TSLexer *lexer, bool *crossed) {
483
- const ContinuationResult continuation = advance_line_continuations(lexer);
484
- if (continuation == CONTINUATION_PAIRS) {
485
- *crossed = true;
486
- }
487
- return continuation != CONTINUATION_INVALID;
488
- }
489
-
490
- static NumberKind
491
- accept_number(TSLexer *lexer, NumberKind kind, bool crossed, bool *split) {
401
+ static bool scan_word_token(TSLexer *lexer, const bool *valid_symbols) {
402
+ WordKind kind = scan_word_spelling(lexer);
492
403
  lexer->mark_end(lexer);
493
- *split = crossed;
494
- return kind;
404
+ kind = promote_word_kind(lexer, valid_symbols, kind);
405
+ const WordToken *token = find_word_token(kind);
406
+ return token !=
407
+ NULL &&
408
+ valid_symbols[token->token] &&
409
+ emit(lexer, token->token);
495
410
  }
496
411
 
497
- static NumberKind scan_number_kind(TSLexer *lexer, bool *split) {
498
- NumberKind kind = NUMBER_KIND_NONE;
499
- bool crossed = false;
500
-
412
+ static bool scan_number_token(TSLexer *lexer) {
413
+ bool digits = false;
414
+ bool floating = false;
501
415
  while (is_ascii_digit(lexer->lookahead)) {
416
+ digits = true;
502
417
  lexer->advance(lexer, false);
503
- kind = accept_number(lexer, NUMBER_KIND_INTEGER, crossed, split);
504
- if (!peek_number_continuations(lexer, &crossed)) {
505
- return kind;
506
- }
507
418
  }
508
419
  if (lexer->lookahead == '.') {
420
+ floating = true;
509
421
  lexer->advance(lexer, false);
510
- if (kind != NUMBER_KIND_NONE) {
511
- kind = accept_number(lexer, NUMBER_KIND_FRACTION, crossed, split);
512
- }
513
- if (!peek_number_continuations(lexer, &crossed)) {
514
- return kind;
515
- }
516
422
  while (is_ascii_digit(lexer->lookahead)) {
423
+ digits = true;
517
424
  lexer->advance(lexer, false);
518
- kind = accept_number(lexer, NUMBER_KIND_FRACTION, crossed, split);
519
- if (!peek_number_continuations(lexer, &crossed)) {
520
- return kind;
521
- }
522
425
  }
523
426
  }
524
- if (kind == NUMBER_KIND_NONE) {
525
- return kind;
427
+ if (!digits) {
428
+ return false;
526
429
  }
527
-
430
+ lexer->mark_end(lexer);
528
431
  if (lexer->lookahead == 'e' || lexer->lookahead == 'E') {
529
432
  lexer->advance(lexer, false);
530
- if (!peek_number_continuations(lexer, &crossed)) {
531
- return kind;
532
- }
533
433
  if (lexer->lookahead == '+' || lexer->lookahead == '-') {
534
434
  lexer->advance(lexer, false);
535
- if (!peek_number_continuations(lexer, &crossed)) {
536
- return kind;
537
- }
538
435
  }
539
436
  if (!is_ascii_digit(lexer->lookahead)) {
540
- return kind;
437
+ return emit(lexer, NUMBER);
541
438
  }
542
- while (is_ascii_digit(lexer->lookahead)) {
439
+ floating = true;
440
+ do {
543
441
  lexer->advance(lexer, false);
544
- kind = accept_number(lexer, NUMBER_KIND_EXPONENT, crossed, split);
545
- if (!peek_number_continuations(lexer, &crossed)) {
546
- return kind;
547
- }
548
- }
442
+ } while (is_ascii_digit(lexer->lookahead));
443
+ lexer->mark_end(lexer);
549
444
  }
550
445
  if (
551
- kind !=
552
- NUMBER_KIND_INTEGER &&
446
+ floating &&
553
447
  (lexer->lookahead ==
554
448
  'f' ||
555
449
  lexer->lookahead ==
@@ -559,130 +453,87 @@ static NumberKind scan_number_kind(TSLexer *lexer, bool *split) {
559
453
  lexer->lookahead == 'L')
560
454
  ) {
561
455
  lexer->advance(lexer, false);
562
- kind = accept_number(lexer, kind, crossed, split);
563
- }
564
- return kind;
565
- }
566
-
567
- static bool
568
- emit_number_kind(TSLexer *lexer, const bool *valid_symbols, NumberKind kind) {
569
- if (kind == NUMBER_KIND_NONE || !valid_symbols[number_kind_token(kind)]) {
570
- return false;
456
+ lexer->mark_end(lexer);
571
457
  }
572
- return emit(lexer, number_kind_token(kind));
458
+ return emit(lexer, NUMBER);
573
459
  }
574
460
 
575
- static bool
576
- has_valid_composite_operator_start(int32_t first, const bool *valid_symbols) {
461
+ static const CompositeOperator *
462
+ find_composite_operator(int32_t first, int32_t second) {
577
463
  for (size_t i = 0; i < ARRAY_LENGTH(COMPOSITE_OPERATORS); i++) {
578
464
  if (
579
465
  COMPOSITE_OPERATORS[i].first ==
580
466
  first &&
581
- (valid_symbols[COMPOSITE_OPERATORS[i].token] ||
582
- valid_symbols[SPLIT_TOKEN])
467
+ COMPOSITE_OPERATORS[i].second == second
583
468
  ) {
584
- return true;
469
+ return &COMPOSITE_OPERATORS[i];
585
470
  }
586
471
  }
587
- return false;
472
+ return NULL;
588
473
  }
589
474
 
590
- static const CompositeOperator *
591
- find_composite_operator(int32_t first, int32_t second) {
475
+ static const SingleOperator *find_single_operator(int32_t character) {
476
+ for (size_t i = 0; i < ARRAY_LENGTH(SINGLE_OPERATORS); i++) {
477
+ if (SINGLE_OPERATORS[i].character == character) {
478
+ return &SINGLE_OPERATORS[i];
479
+ }
480
+ }
481
+ return NULL;
482
+ }
483
+
484
+ static bool
485
+ has_valid_composite_operator_start(int32_t first, const bool *valid_symbols) {
592
486
  for (size_t i = 0; i < ARRAY_LENGTH(COMPOSITE_OPERATORS); i++) {
593
487
  if (
594
488
  COMPOSITE_OPERATORS[i].first ==
595
489
  first &&
596
- COMPOSITE_OPERATORS[i].second == second
490
+ valid_symbols[COMPOSITE_OPERATORS[i].token]
597
491
  ) {
598
- return &COMPOSITE_OPERATORS[i];
492
+ return true;
599
493
  }
600
494
  }
601
- return NULL;
495
+ return false;
602
496
  }
603
497
 
604
498
  static bool
605
499
  scan_composite_operator_start(TSLexer *lexer, const bool *valid_symbols) {
606
500
  const int32_t first = lexer->lookahead;
607
501
  lexer->advance(lexer, false);
608
- const ContinuationResult continuation = advance_line_continuations(lexer);
609
- if (continuation == CONTINUATION_INVALID) {
610
- return false;
611
- }
502
+ lexer->mark_end(lexer);
612
503
  const CompositeOperator *composite =
613
504
  find_composite_operator(first, lexer->lookahead);
614
- if (composite == NULL) {
615
- return false;
616
- }
617
- if (continuation == CONTINUATION_PAIRS) {
618
- if (!valid_symbols[SPLIT_TOKEN]) {
505
+ if (composite != NULL) {
506
+ if (!valid_symbols[composite->token]) {
619
507
  return false;
620
508
  }
621
509
  lexer->advance(lexer, false);
622
510
  lexer->mark_end(lexer);
623
- return emit(lexer, SPLIT_TOKEN);
624
- }
625
- if (!valid_symbols[composite->token]) {
626
- return false;
511
+ return emit(lexer, composite->token);
627
512
  }
628
-
629
- lexer->advance(lexer, false);
630
- lexer->mark_end(lexer);
631
- return emit(lexer, composite->token);
632
- }
633
-
634
- static bool
635
- has_greater_start(const bool *valid_symbols, bool allow_zero_width_guard) {
636
- return valid_symbols[SPLIT_TOKEN] ||
637
- valid_symbols[GE_OPERATOR] ||
638
- valid_symbols[APPEND_OPERATOR] ||
639
- (allow_zero_width_guard && valid_symbols[OUTPUT_GREATER_GUARD]);
513
+ const SingleOperator *single = find_single_operator(first);
514
+ return single !=
515
+ NULL &&
516
+ valid_symbols[single->token] &&
517
+ emit(lexer, single->token);
640
518
  }
641
519
 
642
- // Dispatch together so an invalid two-character operator cannot block the
643
- // zero-width redirection guard.
644
- static bool scan_greater_start(
645
- TSLexer *lexer,
646
- const bool *valid_symbols,
647
- bool allow_zero_width_guard
648
- ) {
520
+ static bool scan_greater_start(TSLexer *lexer, const bool *valid_symbols) {
649
521
  lexer->advance(lexer, false);
650
- const ContinuationResult continuation = advance_line_continuations(lexer);
651
- if (
652
- continuation ==
653
- CONTINUATION_PAIRS &&
654
- (lexer->lookahead == '=' || lexer->lookahead == '>')
655
- ) {
656
- if (!valid_symbols[SPLIT_TOKEN]) {
657
- return false;
658
- }
659
- lexer->advance(lexer, false);
660
- lexer->mark_end(lexer);
661
- return emit(lexer, SPLIT_TOKEN);
662
- }
663
- if (continuation == CONTINUATION_NONE && lexer->lookahead == '=') {
664
- if (!valid_symbols[GE_OPERATOR]) {
522
+ lexer->mark_end(lexer);
523
+ if (lexer->lookahead == '=' || lexer->lookahead == '>') {
524
+ const enum TokenType token =
525
+ lexer->lookahead == '=' ? GE_OPERATOR : APPEND_OPERATOR;
526
+ if (!valid_symbols[token]) {
665
527
  return false;
666
528
  }
667
529
  lexer->advance(lexer, false);
668
530
  lexer->mark_end(lexer);
669
- return emit(lexer, GE_OPERATOR);
531
+ return emit(lexer, token);
670
532
  }
671
- if (
672
- continuation ==
673
- CONTINUATION_NONE &&
674
- lexer->lookahead ==
675
- '>' &&
676
- valid_symbols[APPEND_OPERATOR]
677
- ) {
678
- lexer->advance(lexer, false);
679
- lexer->mark_end(lexer);
680
- return emit(lexer, APPEND_OPERATOR);
681
- }
682
- if (!allow_zero_width_guard || !valid_symbols[OUTPUT_GREATER_GUARD]) {
683
- return false;
533
+ if (valid_symbols[OUTPUT_GREATER]) {
534
+ return emit(lexer, OUTPUT_GREATER);
684
535
  }
685
- return emit(lexer, OUTPUT_GREATER_GUARD);
536
+ return valid_symbols[GREATER_OPERATOR] && emit(lexer, GREATER_OPERATOR);
686
537
  }
687
538
 
688
539
  static bool scan_slash_start(
@@ -692,19 +543,7 @@ static bool scan_slash_start(
692
543
  ) {
693
544
  lexer->advance(lexer, false);
694
545
  lexer->mark_end(lexer);
695
- const ContinuationResult continuation = advance_line_continuations(lexer);
696
- if (
697
- continuation ==
698
- CONTINUATION_PAIRS &&
699
- lexer->lookahead ==
700
- '=' &&
701
- valid_symbols[SPLIT_TOKEN]
702
- ) {
703
- lexer->advance(lexer, false);
704
- lexer->mark_end(lexer);
705
- return emit(lexer, SPLIT_TOKEN);
706
- }
707
- if (continuation == CONTINUATION_NONE && lexer->lookahead == '=') {
546
+ if (lexer->lookahead == '=') {
708
547
  if (valid_symbols[DIV_ASSIGN_OPERATOR]) {
709
548
  lexer->advance(lexer, false);
710
549
  lexer->mark_end(lexer);
@@ -717,81 +556,193 @@ static bool scan_slash_start(
717
556
  if (valid_symbols[DIVISION_SLASH]) {
718
557
  return emit(lexer, DIVISION_SLASH);
719
558
  }
720
- if (valid_symbols[ERE_OPENING_SLASH]) {
721
- return emit_mode(state, lexer, LEXICAL_MODE_ERE_BODY, ERE_OPENING_SLASH);
559
+ return valid_symbols[ERE_OPENING_SLASH] &&
560
+ emit_mode(state, lexer, LEXICAL_MODE_ERE_BODY, ERE_OPENING_SLASH);
561
+ }
562
+
563
+ static bool is_octal_digit(int32_t character) {
564
+ return character >= '0' && character <= '7';
565
+ }
566
+
567
+ static bool character_in(int32_t character, const char *characters) {
568
+ return character >
569
+ 0 &&
570
+ character <=
571
+ 127 &&
572
+ strchr(characters, (char)character) != NULL;
573
+ }
574
+
575
+ static bool
576
+ scan_escape(ScannerState *state, TSLexer *lexer, const bool *valid_symbols) {
577
+ if (lexer->eof(lexer) || lexer->lookahead == '\n') {
578
+ return false;
579
+ }
580
+ const int32_t character = lexer->lookahead;
581
+ lexer->advance(lexer, false);
582
+ if (is_octal_digit(character)) {
583
+ for (
584
+ unsigned count = 1; count < 3 && is_octal_digit(lexer->lookahead); count++
585
+ ) {
586
+ lexer->advance(lexer, false);
587
+ }
722
588
  }
723
- return false;
589
+ lexer->mark_end(lexer);
590
+ enum TokenType token = STRING_ESCAPE;
591
+ if (is_ere_mode(state->mode)) {
592
+ if (character == '/') {
593
+ token = ERE_ESCAPED_DELIMITER;
594
+ } else if (is_octal_digit(character)) {
595
+ token = ERE_OCTAL_ESCAPE;
596
+ } else if (character_in(character, "abfnrtv")) {
597
+ token = ERE_NAMED_ESCAPE;
598
+ } else if (character_in(character, "().*+?{}|^$[\\]")) {
599
+ token = ERE_QUOTED_ESCAPE;
600
+ } else {
601
+ token = ERE_UNDEFINED_ESCAPE;
602
+ }
603
+ }
604
+ return valid_symbols[token] && emit(lexer, token);
724
605
  }
725
606
 
726
- static bool scan_ere_backslash_context(
607
+ static bool scan_backslash(
727
608
  ScannerState *state,
728
609
  TSLexer *lexer,
729
- const bool *valid_symbols
610
+ const bool *valid_symbols,
611
+ bool recovering
730
612
  ) {
731
- if (lexer->lookahead != '\\') {
732
- return false;
733
- }
734
-
735
613
  lexer->advance(lexer, false);
736
- if (lexer->lookahead == '\n' && valid_symbols[SPLIT_TOKEN]) {
737
- lexer->advance(lexer, false);
614
+ if (state->mode == LEXICAL_MODE_OUTSIDE) {
615
+ if (lexer->lookahead != '\n' || !valid_symbols[CONTINUATION_BACKSLASH]) {
616
+ return false;
617
+ }
738
618
  lexer->mark_end(lexer);
739
- return emit(lexer, SPLIT_TOKEN);
740
- }
741
- if (valid_symbols[ERROR_SENTINEL]) {
742
- return false;
743
- }
744
- if (lexer->lookahead == '/' && valid_symbols[ERE_ESCAPED_DELIMITER_START]) {
745
619
  return emit_mode(
746
620
  state,
747
621
  lexer,
748
- LEXICAL_MODE_ERE_ESCAPED_DELIMITER,
749
- ERE_ESCAPED_DELIMITER_START
622
+ LEXICAL_MODE_CONTINUED_NEWLINE,
623
+ CONTINUATION_BACKSLASH
750
624
  );
751
625
  }
752
- if (
753
- lexer->lookahead !=
754
- '\n' &&
626
+ return !recovering && scan_escape(state, lexer, valid_symbols);
627
+ }
628
+
629
+ static bool scan_string_content(TSLexer *lexer) {
630
+ bool consumed = false;
631
+ while (
755
632
  !lexer->eof(lexer) &&
756
- valid_symbols[ERE_ESCAPE_START]
633
+ lexer->lookahead !=
634
+ '"' &&
635
+ lexer->lookahead !=
636
+ '\\' &&
637
+ lexer->lookahead != '\n'
757
638
  ) {
758
- return emit(lexer, ERE_ESCAPE_START);
639
+ consumed = true;
640
+ lexer->advance(lexer, false);
759
641
  }
760
- return false;
642
+ lexer->mark_end(lexer);
643
+ return consumed && emit(lexer, STRING_CONTENT);
761
644
  }
762
645
 
763
- static bool is_ere_compound_punctuation(int32_t character) {
764
- switch (character) {
765
- case '.':
766
- case '=':
767
- case ':':
768
- return true;
769
- default:
770
- return false;
771
- }
646
+ static bool scan_ere_spelling(TSLexer *lexer, enum TokenType token) {
647
+ do {
648
+ lexer->advance(lexer, false);
649
+ } while (
650
+ is_ascii_digit(lexer->lookahead) ||
651
+ (token == ERE_CLASS_NAME && is_ascii_letter(lexer->lookahead))
652
+ );
653
+ lexer->mark_end(lexer);
654
+ return emit(lexer, token);
772
655
  }
773
656
 
774
657
  typedef struct {
775
- enum TokenType guard;
776
- int32_t opening;
777
- } EreCompoundGuard;
778
-
779
- static const EreCompoundGuard ERE_COMPOUND_GUARDS[] = {
780
- {ERE_COMPOUND_OPEN_GUARD, '['},
781
- {ERE_DOT_CLOSE_GUARD, '.'},
782
- {ERE_EQUAL_CLOSE_GUARD, '='},
783
- {ERE_COLON_CLOSE_GUARD, ':'},
658
+ enum TokenType delimiter;
659
+ enum TokenType content;
660
+ int32_t first;
661
+ LexicalMode mode;
662
+ } EreCompoundToken;
663
+
664
+ static const EreCompoundToken ERE_COMPOUND_TOKENS[] = {
665
+ {ERE_COMPOUND_OPENING, ERE_BRACKET_LITERAL_OPEN, '[', LEXICAL_MODE_ERE_BODY},
666
+ {ERE_DOT_CLOSING, ERE_COMPOUND_CONTENT, '.', LEXICAL_MODE_ERE_COLLATING},
667
+ {ERE_EQUAL_CLOSING, ERE_COMPOUND_CONTENT, '=', LEXICAL_MODE_ERE_EQUIVALENCE},
668
+ {ERE_COLON_CLOSING, ERE_COMPOUND_CONTENT, ':', LEXICAL_MODE_ERE_CLASS},
784
669
  };
785
670
 
786
- static bool scan_ere_compound_guard(TSLexer *lexer, enum TokenType guard) {
671
+ static bool scan_ere_compound_token(
672
+ ScannerState *state,
673
+ TSLexer *lexer,
674
+ const EreCompoundToken *token,
675
+ const bool *valid_symbols
676
+ ) {
787
677
  lexer->advance(lexer, false);
788
- const bool matches = guard == ERE_COMPOUND_OPEN_GUARD
789
- ? is_ere_compound_punctuation(lexer->lookahead)
678
+ lexer->mark_end(lexer);
679
+ const bool matches = token->delimiter == ERE_COMPOUND_OPENING
680
+ ? character_in(lexer->lookahead, ".=:")
790
681
  : lexer->lookahead == ']';
791
- if (!matches) {
792
- return false;
682
+ if (
683
+ matches &&
684
+ (token->delimiter == ERE_COMPOUND_OPENING || state->mode == token->mode)
685
+ ) {
686
+ if (!valid_symbols[token->delimiter]) {
687
+ return false;
688
+ }
689
+ LexicalMode mode = LEXICAL_MODE_ERE_BODY;
690
+ if (token->delimiter == ERE_COMPOUND_OPENING) {
691
+ for (size_t i = 1; i < ARRAY_LENGTH(ERE_COMPOUND_TOKENS); i++) {
692
+ if (ERE_COMPOUND_TOKENS[i].first == lexer->lookahead) {
693
+ mode = ERE_COMPOUND_TOKENS[i].mode;
694
+ break;
695
+ }
696
+ }
697
+ }
698
+ return emit_mode(state, lexer, mode, token->delimiter);
793
699
  }
794
- return emit(lexer, guard);
700
+ return valid_symbols[token->content] && emit(lexer, token->content);
701
+ }
702
+
703
+ static bool scan_ere_context(
704
+ ScannerState *state,
705
+ TSLexer *lexer,
706
+ const bool *valid_symbols,
707
+ bool recovering
708
+ ) {
709
+ if (!recovering) {
710
+ for (size_t i = 0; i < ARRAY_LENGTH(ERE_COMPOUND_TOKENS); i++) {
711
+ const EreCompoundToken *token = &ERE_COMPOUND_TOKENS[i];
712
+ if (
713
+ lexer->lookahead ==
714
+ token->first &&
715
+ (valid_symbols[token->delimiter] || valid_symbols[token->content])
716
+ ) {
717
+ return scan_ere_compound_token(state, lexer, token, valid_symbols);
718
+ }
719
+ }
720
+ if (valid_symbols[ERE_CLASS_NAME] && is_ascii_letter(lexer->lookahead)) {
721
+ return scan_ere_spelling(lexer, ERE_CLASS_NAME);
722
+ }
723
+ if (valid_symbols[ERE_DUP_COUNT] && is_ascii_digit(lexer->lookahead)) {
724
+ return scan_ere_spelling(lexer, ERE_DUP_COUNT);
725
+ }
726
+ }
727
+ if (lexer->lookahead == '/' && valid_symbols[ERE_CLOSING]) {
728
+ lexer->advance(lexer, false);
729
+ lexer->mark_end(lexer);
730
+ return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, ERE_CLOSING);
731
+ }
732
+ if (lexer->lookahead == '-' && valid_symbols[ERE_CLOSING_HYPHEN]) {
733
+ lexer->advance(lexer, false);
734
+ lexer->mark_end(lexer);
735
+ return lexer->lookahead == ']' && emit(lexer, ERE_CLOSING_HYPHEN);
736
+ }
737
+ return false;
738
+ }
739
+
740
+ static bool scan_comment(TSLexer *lexer) {
741
+ do {
742
+ lexer->advance(lexer, false);
743
+ } while (lexer->lookahead != '\n' && !lexer->eof(lexer));
744
+ lexer->mark_end(lexer);
745
+ return emit(lexer, COMMENT);
795
746
  }
796
747
 
797
748
  void *tree_sitter_posix_awk_external_scanner_create(void) {
@@ -818,170 +769,97 @@ void tree_sitter_posix_awk_external_scanner_deserialize(
818
769
  unsigned length
819
770
  ) {
820
771
  ScannerState *state = payload;
821
- state->mode = LEXICAL_MODE_OUTSIDE;
822
- if (length == SERIALIZED_SCANNER_STATE_SIZE) {
823
- const unsigned char mode = (unsigned char)buffer[0];
824
- if (mode <= LEXICAL_MODE_STRING) {
825
- state->mode = (LexicalMode)mode;
826
- }
772
+ *state = (ScannerState){0};
773
+ if (length != SERIALIZED_SCANNER_STATE_SIZE) {
774
+ return;
775
+ }
776
+ const unsigned char mode = (unsigned char)buffer[0];
777
+ if (mode <= LEXICAL_MODE_CONTINUED_NEWLINE) {
778
+ state->mode = (LexicalMode)mode;
827
779
  }
828
780
  }
829
781
 
830
- static bool scan_ere_context(
831
- ScannerState *state,
782
+ bool tree_sitter_posix_awk_external_scanner_scan(
783
+ void *payload,
832
784
  TSLexer *lexer,
833
785
  const bool *valid_symbols
834
786
  ) {
835
- lexer->mark_end(lexer);
836
-
837
- if (state->mode == LEXICAL_MODE_ERE_ESCAPED_DELIMITER) {
838
- if (lexer->lookahead == '/' && valid_symbols[ERE_ESCAPED_DELIMITER_END]) {
839
- lexer->advance(lexer, false);
840
- lexer->mark_end(lexer);
841
- return emit_mode(
842
- state,
843
- lexer,
844
- LEXICAL_MODE_ERE_BODY,
845
- ERE_ESCAPED_DELIMITER_END
846
- );
847
- }
848
- return scan_ere_backslash_context(state, lexer, valid_symbols);
849
- }
850
-
851
- if (!valid_symbols[ERROR_SENTINEL]) {
852
- for (size_t i = 0; i < ARRAY_LENGTH(ERE_COMPOUND_GUARDS); i++) {
853
- if (
854
- valid_symbols[ERE_COMPOUND_GUARDS[i].guard] &&
855
- lexer->lookahead == ERE_COMPOUND_GUARDS[i].opening
856
- ) {
857
- return scan_ere_compound_guard(lexer, ERE_COMPOUND_GUARDS[i].guard);
858
- }
787
+ ScannerState *state = payload;
788
+ const bool recovering = valid_symbols[ERROR_SENTINEL];
789
+ if (state->mode == LEXICAL_MODE_CONTINUED_NEWLINE) {
790
+ if (lexer->lookahead != '\n' || !valid_symbols[CONTINUATION_NEWLINE]) {
791
+ return false;
859
792
  }
860
- }
861
-
862
- if (lexer->lookahead == '/' && valid_symbols[ERE_CLOSING]) {
863
793
  lexer->advance(lexer, false);
864
794
  lexer->mark_end(lexer);
865
- return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, ERE_CLOSING);
795
+ return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, CONTINUATION_NEWLINE);
866
796
  }
867
-
868
- if (lexer->lookahead == '-' && valid_symbols[ERE_CLOSING_HYPHEN]) {
869
- lexer->advance(lexer, false);
870
- if (lexer->lookahead != ']') {
871
- return false;
797
+ if (state->mode == LEXICAL_MODE_OUTSIDE) {
798
+ while (is_ascii_blank(lexer->lookahead)) {
799
+ lexer->advance(lexer, true);
872
800
  }
873
- lexer->mark_end(lexer);
874
- return emit(lexer, ERE_CLOSING_HYPHEN);
875
801
  }
876
-
877
- return scan_ere_backslash_context(state, lexer, valid_symbols);
878
- }
879
-
880
- static bool scan_string_context(
881
- ScannerState *state,
882
- TSLexer *lexer,
883
- const bool *valid_symbols
884
- ) {
885
802
  lexer->mark_end(lexer);
886
803
  if (lexer->lookahead == '\\') {
887
- lexer->advance(lexer, false);
888
- if (lexer->lookahead == '\n' && valid_symbols[SPLIT_TOKEN]) {
804
+ return scan_backslash(state, lexer, valid_symbols, recovering);
805
+ }
806
+ if (is_ere_mode(state->mode)) {
807
+ return scan_ere_context(state, lexer, valid_symbols, recovering);
808
+ }
809
+ if (state->mode == LEXICAL_MODE_STRING) {
810
+ if (lexer->lookahead == '"' && valid_symbols[STRING_CLOSING]) {
889
811
  lexer->advance(lexer, false);
890
812
  lexer->mark_end(lexer);
891
- return emit(lexer, SPLIT_TOKEN);
813
+ return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, STRING_CLOSING);
892
814
  }
893
- return false;
815
+ return !recovering &&
816
+ valid_symbols[STRING_CONTENT] &&
817
+ scan_string_content(lexer);
894
818
  }
895
- const bool at_string_end =
896
- lexer->lookahead == '"' || lexer->lookahead == '\n' || lexer->eof(lexer);
897
- if (at_string_end && valid_symbols[STRING_END]) {
898
- return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, STRING_END);
899
- }
900
- return false;
901
- }
902
-
903
- static bool scan_string_opening(ScannerState *state, TSLexer *lexer) {
904
- lexer->advance(lexer, false);
905
- lexer->mark_end(lexer);
906
- return emit_mode(state, lexer, LEXICAL_MODE_STRING, STRING_OPENING);
907
- }
908
-
909
- static bool scan_comment(TSLexer *lexer) {
910
- advance_comment_to_boundary(lexer);
911
- lexer->mark_end(lexer);
912
- return emit(lexer, COMMENT);
913
- }
914
-
915
- static bool has_number_token(const bool *valid_symbols) {
916
- return valid_symbols[NUMBER_INTEGER] ||
917
- valid_symbols[NUMBER_FRACTION] ||
918
- valid_symbols[NUMBER_EXPONENT];
919
- }
920
-
921
- bool tree_sitter_posix_awk_external_scanner_scan(
922
- void *payload,
923
- TSLexer *lexer,
924
- const bool *valid_symbols
925
- ) {
926
- ScannerState *state = payload;
927
- switch (state->mode) {
928
- case LEXICAL_MODE_ERE_BODY:
929
- case LEXICAL_MODE_ERE_ESCAPED_DELIMITER:
930
- return scan_ere_context(state, lexer, valid_symbols);
931
- case LEXICAL_MODE_STRING:
932
- return scan_string_context(state, lexer, valid_symbols);
933
- case LEXICAL_MODE_OUTSIDE:
934
- break;
935
- }
936
-
937
- // During recovery all tokens are valid; disable zero-width guards to avoid
938
- // accepting them at arbitrary positions.
939
- const bool recovering = valid_symbols[ERROR_SENTINEL];
940
- skip_ascii_blanks(lexer);
941
- lexer->mark_end(lexer);
942
-
943
819
  if (lexer->lookahead == '#' && valid_symbols[COMMENT]) {
944
820
  return scan_comment(lexer);
945
821
  }
946
-
947
822
  if (lexer->lookahead == '"' && valid_symbols[STRING_OPENING]) {
948
- return scan_string_opening(state, lexer);
823
+ lexer->advance(lexer, false);
824
+ lexer->mark_end(lexer);
825
+ return emit_mode(state, lexer, LEXICAL_MODE_STRING, STRING_OPENING);
949
826
  }
950
-
951
- if (
952
- is_word_start(lexer->lookahead) &&
953
- (has_word_token(valid_symbols) || valid_symbols[SPLIT_TOKEN])
954
- ) {
955
- const WordKind kind = scan_word_spelling(lexer);
956
- return scan_word_token(lexer, valid_symbols, kind);
827
+ if (recovering) {
828
+ return false;
829
+ }
830
+ if (is_word_start(lexer->lookahead) && has_word_token(valid_symbols)) {
831
+ return scan_word_token(lexer, valid_symbols);
957
832
  }
958
833
  if (
959
834
  (is_ascii_digit(lexer->lookahead) || lexer->lookahead == '.') &&
960
- (has_number_token(valid_symbols) || valid_symbols[SPLIT_TOKEN])
835
+ valid_symbols[NUMBER]
961
836
  ) {
962
- bool split = false;
963
- const NumberKind kind = scan_number_kind(lexer, &split);
964
- if (split) {
965
- return valid_symbols[SPLIT_TOKEN] && emit(lexer, SPLIT_TOKEN);
966
- }
967
- return emit_number_kind(lexer, valid_symbols, kind);
837
+ return scan_number_token(lexer);
968
838
  }
969
839
  if (
970
840
  lexer->lookahead ==
971
841
  '/' &&
972
842
  (valid_symbols[DIVISION_SLASH] ||
973
843
  valid_symbols[ERE_OPENING_SLASH] ||
974
- valid_symbols[DIV_ASSIGN_OPERATOR] ||
975
- valid_symbols[SPLIT_TOKEN])
844
+ valid_symbols[DIV_ASSIGN_OPERATOR])
976
845
  ) {
977
846
  return scan_slash_start(state, lexer, valid_symbols);
978
847
  }
979
848
  if (
980
- lexer->lookahead == '>' && has_greater_start(valid_symbols, !recovering)
849
+ lexer->lookahead ==
850
+ '>' &&
851
+ (valid_symbols[GE_OPERATOR] ||
852
+ valid_symbols[GREATER_OPERATOR] ||
853
+ valid_symbols[APPEND_OPERATOR] ||
854
+ valid_symbols[OUTPUT_GREATER])
981
855
  ) {
982
- return scan_greater_start(lexer, valid_symbols, !recovering);
856
+ return scan_greater_start(lexer, valid_symbols);
983
857
  }
984
- if (has_valid_composite_operator_start(lexer->lookahead, valid_symbols)) {
858
+ const SingleOperator *single = find_single_operator(lexer->lookahead);
859
+ if (
860
+ (single != NULL && valid_symbols[single->token]) ||
861
+ has_valid_composite_operator_start(lexer->lookahead, valid_symbols)
862
+ ) {
985
863
  return scan_composite_operator_start(lexer, valid_symbols);
986
864
  }
987
865
  return false;