@konomanoasa/tree-sitter-posix-awk 0.18.0 → 0.19.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,61 +7,24 @@
7
7
  #define ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
8
8
 
9
9
  enum TokenType {
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
- NAME_WORD,
28
- FOR_IN_VARIABLE_WORD,
29
10
  GETLINE_WORD,
30
- IN_WORD,
31
- BUILTIN_FUNC_NAME_WORD,
32
- BUILTIN_CALL_WORD,
11
+ GETLINE_TARGET_WORD,
12
+ GETLINE_OMITTED_WORD,
13
+ GETLINE_FIELD_WORD,
14
+ GETLINE_PREFER_TARGET_WORD,
15
+ GETLINE_PREFER_OMITTED_WORD,
33
16
  FUNC_NAME_WORD,
34
- NUMBER,
35
17
  DIVISION_SLASH,
36
18
  ERE_OPENING_SLASH,
37
- DIV_ASSIGN_OPERATOR,
38
- ADD_ASSIGN_OPERATOR,
39
- SUB_ASSIGN_OPERATOR,
40
- MUL_ASSIGN_OPERATOR,
41
- MOD_ASSIGN_OPERATOR,
42
- POW_ASSIGN_OPERATOR,
43
- OR_OPERATOR,
44
- AND_OPERATOR,
45
- NO_MATCH_OPERATOR,
46
- EQ_OPERATOR,
47
- LE_OPERATOR,
48
- GE_OPERATOR,
49
- NE_OPERATOR,
50
19
  INCR_OPERATOR,
51
20
  DECR_OPERATOR,
52
- APPEND_OPERATOR,
53
21
  PLUS_OPERATOR,
54
22
  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,
23
+ GETLINE_PIPE,
64
24
  ERE_COMPOUND_OPENING,
25
+ ERE_ESCAPED_COMPOUND_OPENING,
26
+ ERE_COMPOUND_SINGLE,
27
+ ERE_COMPOUND_MULTI,
65
28
  ERE_DOT_CLOSING,
66
29
  ERE_EQUAL_CLOSING,
67
30
  ERE_COLON_CLOSING,
@@ -71,25 +34,22 @@ enum TokenType {
71
34
  ERE_CLOSING,
72
35
  STRING_OPENING,
73
36
  STRING_CLOSING,
74
- STRING_CONTENT,
75
37
  STRING_ESCAPE,
76
38
  ERE_NAMED_ESCAPE,
77
39
  ERE_QUOTED_ESCAPE,
78
40
  ERE_OCTAL_ESCAPE,
79
41
  ERE_UNDEFINED_ESCAPE,
80
42
  ERE_ESCAPED_DELIMITER,
81
- ERE_CLASS_NAME,
82
- ERE_DUP_COUNT,
83
43
  COMMENT,
84
44
  CONTINUATION_BACKSLASH,
85
45
  CONTINUATION_NEWLINE,
46
+ LITERAL_BREAK,
86
47
  STRAY_BACKSLASH,
87
48
  ERROR_SENTINEL,
88
49
  TOKEN_TYPE_COUNT,
89
50
  };
90
51
 
91
52
  enum {
92
- MAX_RESERVED_WORD_LENGTH = 8,
93
53
  SERIALIZED_SCANNER_STATE_SIZE = 1,
94
54
  };
95
55
 
@@ -97,17 +57,20 @@ typedef char SerializedScannerStateFitsTreeSitterBuffer
97
57
  [SERIALIZED_SCANNER_STATE_SIZE <= TREE_SITTER_SERIALIZATION_BUFFER_SIZE ? 1
98
58
  : -1];
99
59
 
60
+ typedef enum {
61
+ WORD_NONE,
62
+ WORD_NAME,
63
+ WORD_KEYWORD,
64
+ WORD_MEMBERSHIP,
65
+ WORD_GETLINE,
66
+ WORD_BUILTIN,
67
+ } WordKind;
68
+
100
69
  typedef struct {
101
70
  const char *spelling;
102
- enum TokenType token;
71
+ WordKind kind;
103
72
  } ReservedWord;
104
73
 
105
- typedef struct {
106
- int32_t first;
107
- int32_t second;
108
- enum TokenType token;
109
- } CompositeOperator;
110
-
111
74
  typedef enum {
112
75
  LEXICAL_MODE_OUTSIDE,
113
76
  LEXICAL_MODE_ERE_BODY,
@@ -122,87 +85,55 @@ typedef struct {
122
85
  LexicalMode mode;
123
86
  } ScannerState;
124
87
 
125
- static const ReservedWord RESERVED_WORDS[] = {
126
- {"BEGIN", BEGIN_KEYWORD},
127
- {"break", BREAK_KEYWORD},
128
- {"continue", CONTINUE_KEYWORD},
129
- {"delete", DELETE_KEYWORD},
130
- {"do", DO_KEYWORD},
131
- {"else", ELSE_KEYWORD},
132
- {"END", END_KEYWORD},
133
- {"exit", EXIT_KEYWORD},
134
- {"for", FOR_KEYWORD},
135
- {"function", FUNCTION_KEYWORD},
136
- {"getline", GETLINE_WORD},
137
- {"if", IF_KEYWORD},
138
- {"in", IN_WORD},
139
- {"next", NEXT_KEYWORD},
140
- {"nextfile", NEXTFILE_KEYWORD},
141
- {"print", PRINT_KEYWORD},
142
- {"printf", PRINTF_KEYWORD},
143
- {"return", RETURN_KEYWORD},
144
- {"while", WHILE_KEYWORD},
145
- {"atan2", BUILTIN_FUNC_NAME_WORD},
146
- {"close", BUILTIN_FUNC_NAME_WORD},
147
- {"cos", BUILTIN_FUNC_NAME_WORD},
148
- {"exp", BUILTIN_FUNC_NAME_WORD},
149
- {"fflush", BUILTIN_FUNC_NAME_WORD},
150
- {"gsub", BUILTIN_FUNC_NAME_WORD},
151
- {"index", BUILTIN_FUNC_NAME_WORD},
152
- {"int", BUILTIN_FUNC_NAME_WORD},
153
- {"length", BUILTIN_FUNC_NAME_WORD},
154
- {"log", BUILTIN_FUNC_NAME_WORD},
155
- {"match", BUILTIN_FUNC_NAME_WORD},
156
- {"rand", BUILTIN_FUNC_NAME_WORD},
157
- {"sin", BUILTIN_FUNC_NAME_WORD},
158
- {"split", BUILTIN_FUNC_NAME_WORD},
159
- {"sprintf", BUILTIN_FUNC_NAME_WORD},
160
- {"sqrt", BUILTIN_FUNC_NAME_WORD},
161
- {"srand", BUILTIN_FUNC_NAME_WORD},
162
- {"sub", BUILTIN_FUNC_NAME_WORD},
163
- {"substr", BUILTIN_FUNC_NAME_WORD},
164
- {"system", BUILTIN_FUNC_NAME_WORD},
165
- {"tolower", BUILTIN_FUNC_NAME_WORD},
166
- {"toupper", BUILTIN_FUNC_NAME_WORD},
167
- };
168
-
169
- static const CompositeOperator COMPOSITE_OPERATORS[] = {
170
- {'+', '=', ADD_ASSIGN_OPERATOR},
171
- {'-', '=', SUB_ASSIGN_OPERATOR},
172
- {'*', '=', MUL_ASSIGN_OPERATOR},
173
- {'%', '=', MOD_ASSIGN_OPERATOR},
174
- {'^', '=', POW_ASSIGN_OPERATOR},
175
- {'|', '|', OR_OPERATOR},
176
- {'&', '&', AND_OPERATOR},
177
- {'!', '~', NO_MATCH_OPERATOR},
178
- {'=', '=', EQ_OPERATOR},
179
- {'<', '=', LE_OPERATOR},
180
- {'>', '=', GE_OPERATOR},
181
- {'!', '=', NE_OPERATOR},
182
- {'+', '+', INCR_OPERATOR},
183
- {'-', '-', DECR_OPERATOR},
184
- {'>', '>', APPEND_OPERATOR},
88
+ // BEGIN generated reserved words from grammar.js.
89
+ enum {
90
+ MAX_RESERVED_WORD_LENGTH = 8,
185
91
  };
186
92
 
187
- typedef struct {
188
- int32_t character;
189
- enum TokenType token;
190
- } SingleOperator;
191
-
192
- // Redirection precedes comparison where the parser accepts both.
193
- static const SingleOperator SINGLE_OPERATORS[] = {
194
- {'+', PLUS_OPERATOR},
195
- {'-', MINUS_OPERATOR},
196
- {'*', STAR_OPERATOR},
197
- {'%', PERCENT_OPERATOR},
198
- {'^', CARET_OPERATOR},
199
- {'!', BANG_OPERATOR},
200
- {'<', LESS_OPERATOR},
201
- {'>', OUTPUT_GREATER},
202
- {'>', GREATER_OPERATOR},
203
- {'=', EQUAL_OPERATOR},
204
- {'|', PIPE_OPERATOR},
93
+ static const ReservedWord RESERVED_WORDS[] = {
94
+ {"BEGIN", WORD_KEYWORD},
95
+ {"END", WORD_KEYWORD},
96
+ {"break", WORD_KEYWORD},
97
+ {"continue", WORD_KEYWORD},
98
+ {"delete", WORD_KEYWORD},
99
+ {"do", WORD_KEYWORD},
100
+ {"else", WORD_KEYWORD},
101
+ {"exit", WORD_KEYWORD},
102
+ {"for", WORD_KEYWORD},
103
+ {"function", WORD_KEYWORD},
104
+ {"if", WORD_KEYWORD},
105
+ {"next", WORD_KEYWORD},
106
+ {"nextfile", WORD_KEYWORD},
107
+ {"print", WORD_KEYWORD},
108
+ {"printf", WORD_KEYWORD},
109
+ {"return", WORD_KEYWORD},
110
+ {"while", WORD_KEYWORD},
111
+ {"in", WORD_MEMBERSHIP},
112
+ {"getline", WORD_GETLINE},
113
+ {"atan2", WORD_BUILTIN},
114
+ {"close", WORD_BUILTIN},
115
+ {"cos", WORD_BUILTIN},
116
+ {"exp", WORD_BUILTIN},
117
+ {"fflush", WORD_BUILTIN},
118
+ {"gsub", WORD_BUILTIN},
119
+ {"index", WORD_BUILTIN},
120
+ {"int", WORD_BUILTIN},
121
+ {"length", WORD_BUILTIN},
122
+ {"log", WORD_BUILTIN},
123
+ {"match", WORD_BUILTIN},
124
+ {"rand", WORD_BUILTIN},
125
+ {"sin", WORD_BUILTIN},
126
+ {"split", WORD_BUILTIN},
127
+ {"sprintf", WORD_BUILTIN},
128
+ {"sqrt", WORD_BUILTIN},
129
+ {"srand", WORD_BUILTIN},
130
+ {"sub", WORD_BUILTIN},
131
+ {"substr", WORD_BUILTIN},
132
+ {"system", WORD_BUILTIN},
133
+ {"tolower", WORD_BUILTIN},
134
+ {"toupper", WORD_BUILTIN},
205
135
  };
136
+ // END generated reserved words.
206
137
 
207
138
  static bool is_ascii_blank(int32_t character) {
208
139
  return character == ' ' || character == '\t';
@@ -255,23 +186,23 @@ static bool emit_mode(
255
186
  return emit(lexer, token);
256
187
  }
257
188
 
258
- static enum TokenType classify_word(const char *word, size_t length) {
189
+ static WordKind classify_word(const char *word, size_t length) {
259
190
  if (length > MAX_RESERVED_WORD_LENGTH) {
260
- return NAME_WORD;
191
+ return WORD_NAME;
261
192
  }
262
193
  for (size_t i = 0; i < ARRAY_LENGTH(RESERVED_WORDS); i++) {
263
194
  if (strcmp(RESERVED_WORDS[i].spelling, word) == 0) {
264
- return RESERVED_WORDS[i].token;
195
+ return RESERVED_WORDS[i].kind;
265
196
  }
266
197
  }
267
- return NAME_WORD;
198
+ return WORD_NAME;
268
199
  }
269
200
 
270
- static enum TokenType scan_word_spelling(TSLexer *lexer) {
201
+ static WordKind scan_word_spelling(TSLexer *lexer) {
271
202
  char spelling[MAX_RESERVED_WORD_LENGTH + 1] = {0};
272
203
  size_t length = 0;
273
204
  if (!is_word_start(lexer->lookahead)) {
274
- return TOKEN_TYPE_COUNT;
205
+ return WORD_NONE;
275
206
  }
276
207
  do {
277
208
  if (length < MAX_RESERVED_WORD_LENGTH) {
@@ -301,44 +232,40 @@ static bool skip_token_layout(TSLexer *lexer) {
301
232
  }
302
233
  }
303
234
 
304
- static bool scan_for_in_shape(TSLexer *lexer) {
305
- if (!skip_token_layout(lexer) || scan_word_spelling(lexer) != IN_WORD) {
235
+ static bool scan_lvalue_start(TSLexer *lexer) {
236
+ if (!skip_token_layout(lexer)) {
306
237
  return false;
307
238
  }
308
- if (!skip_token_layout(lexer) || scan_word_spelling(lexer) != NAME_WORD) {
309
- return false;
239
+ if (lexer->lookahead == '$') {
240
+ return true;
310
241
  }
311
- return skip_token_layout(lexer) && lexer->lookahead == ')';
242
+ return scan_word_spelling(lexer) == WORD_NAME && lexer->lookahead != '(';
312
243
  }
313
244
 
314
- static enum TokenType
315
- promote_word(TSLexer *lexer, const bool *valid_symbols, enum TokenType token) {
316
- switch (token) {
317
- case NAME_WORD:
318
- if (lexer->lookahead == '(') {
319
- return FUNC_NAME_WORD;
245
+ static bool skip_literal(TSLexer *lexer) {
246
+ const int32_t delimiter = lexer->lookahead;
247
+ for (;;) {
248
+ lexer->advance(lexer, false);
249
+ if (lexer->lookahead == '\\') {
250
+ lexer->advance(lexer, false);
251
+ } else if (lexer->lookahead == delimiter) {
252
+ lexer->advance(lexer, false);
253
+ return true;
320
254
  }
321
- if (valid_symbols[FOR_IN_VARIABLE_WORD] && scan_for_in_shape(lexer)) {
322
- return FOR_IN_VARIABLE_WORD;
255
+ if (lexer->eof(lexer) || lexer->lookahead == '\n') {
256
+ return false;
323
257
  }
324
- return token;
325
- case BUILTIN_FUNC_NAME_WORD:
326
- return skip_token_layout(lexer) && lexer->lookahead == '('
327
- ? BUILTIN_CALL_WORD
328
- : token;
329
- default:
330
- return token;
331
258
  }
332
259
  }
333
260
 
334
- static bool scan_word_token(TSLexer *lexer, const bool *valid_symbols) {
335
- enum TokenType token = scan_word_spelling(lexer);
336
- lexer->mark_end(lexer);
337
- token = promote_word(lexer, valid_symbols, token);
338
- return valid_symbols[token] && emit(lexer, token);
339
- }
261
+ typedef enum {
262
+ NUMBER_ABSENT,
263
+ NUMBER_WHOLE,
264
+ NUMBER_BEFORE_WORD,
265
+ } NumberExtent;
340
266
 
341
- static bool scan_number_token(TSLexer *lexer) {
267
+ // BEFORE_WORD consumes an incomplete exponent beyond the token end.
268
+ static NumberExtent skip_number(TSLexer *lexer, bool token) {
342
269
  bool digits = false;
343
270
  bool floating = false;
344
271
  while (is_ascii_digit(lexer->lookahead)) {
@@ -354,68 +281,1118 @@ static bool scan_number_token(TSLexer *lexer) {
354
281
  }
355
282
  }
356
283
  if (!digits) {
357
- return false;
284
+ return NUMBER_ABSENT;
285
+ }
286
+ if (token) {
287
+ lexer->mark_end(lexer);
358
288
  }
359
- lexer->mark_end(lexer);
360
289
  if (lexer->lookahead == 'e' || lexer->lookahead == 'E') {
361
290
  lexer->advance(lexer, false);
362
291
  if (lexer->lookahead == '+' || lexer->lookahead == '-') {
363
292
  lexer->advance(lexer, false);
364
293
  }
365
294
  if (!is_ascii_digit(lexer->lookahead)) {
366
- return emit(lexer, NUMBER);
295
+ return NUMBER_BEFORE_WORD;
367
296
  }
368
297
  floating = true;
369
298
  do {
370
299
  lexer->advance(lexer, false);
371
300
  } while (is_ascii_digit(lexer->lookahead));
372
- lexer->mark_end(lexer);
301
+ if (token) {
302
+ lexer->mark_end(lexer);
303
+ }
373
304
  }
374
305
  if (floating && character_in(lexer->lookahead, "fFlL")) {
375
306
  lexer->advance(lexer, false);
376
- lexer->mark_end(lexer);
307
+ if (token) {
308
+ lexer->mark_end(lexer);
309
+ }
377
310
  }
378
- return emit(lexer, NUMBER);
311
+ return NUMBER_WHOLE;
379
312
  }
380
313
 
381
- static const CompositeOperator *
382
- find_composite_operator(int32_t first, int32_t second) {
383
- for (size_t i = 0; i < ARRAY_LENGTH(COMPOSITE_OPERATORS); i++) {
384
- const CompositeOperator *entry = &COMPOSITE_OPERATORS[i];
385
- if (entry->first == first && entry->second == second) {
386
- return entry;
314
+ // A slash after an update is division: prefix updates require an lvalue.
315
+ static bool skip_group(TSLexer *lexer) {
316
+ bool operand = false;
317
+ bool separated = false;
318
+ unsigned depth = 0;
319
+ do {
320
+ const int32_t character = lexer->lookahead;
321
+ if (lexer->eof(lexer) || (character == '\n' && !separated)) {
322
+ return false;
323
+ }
324
+ if (character == '#') {
325
+ do {
326
+ lexer->advance(lexer, false);
327
+ } while (lexer->lookahead != '\n' && !lexer->eof(lexer));
328
+ continue;
387
329
  }
330
+ if (character_in(character, " \t\n")) {
331
+ lexer->advance(lexer, false);
332
+ continue;
333
+ }
334
+ if (character == '\\') {
335
+ lexer->advance(lexer, false);
336
+ if (lexer->lookahead != '\n') {
337
+ return false;
338
+ }
339
+ lexer->advance(lexer, false);
340
+ continue;
341
+ }
342
+ separated = false;
343
+ if (character == '"' || (character == '/' && !operand)) {
344
+ if (!skip_literal(lexer)) {
345
+ return false;
346
+ }
347
+ operand = true;
348
+ continue;
349
+ }
350
+ if (is_word_start(character)) {
351
+ scan_word_spelling(lexer);
352
+ operand = true;
353
+ continue;
354
+ }
355
+ lexer->advance(lexer, false);
356
+ if (character_in(character, "([")) {
357
+ depth++;
358
+ operand = false;
359
+ } else if (character_in(character, ")]")) {
360
+ depth--;
361
+ operand = true;
362
+ } else if (character_in(character, "+-") && lexer->lookahead == character) {
363
+ lexer->advance(lexer, false);
364
+ operand = true;
365
+ } else if (character_in(character, "&|") && lexer->lookahead == character) {
366
+ lexer->advance(lexer, false);
367
+ operand = false;
368
+ separated = true;
369
+ } else {
370
+ operand = is_word_continue(character) || character == '.';
371
+ separated = character == ',';
372
+ }
373
+ } while (depth > 0);
374
+ return true;
375
+ }
376
+
377
+ // Restoring this cursor must preserve the source lexer's furthest lookahead.
378
+ typedef struct {
379
+ TSLexer lexer;
380
+ TSLexer *source;
381
+ int32_t *characters;
382
+ size_t length;
383
+ size_t capacity;
384
+ size_t position;
385
+ size_t marked_end;
386
+ bool failed;
387
+ bool pipe_checked;
388
+ bool may_have_pipe;
389
+ bool deferred_target;
390
+ } InputProbe;
391
+
392
+ static void probe_restore(InputProbe *probe, size_t position) {
393
+ probe->position = position;
394
+ probe->lexer.lookahead = position < probe->length
395
+ ? probe->characters[position]
396
+ : probe->source->lookahead;
397
+ }
398
+
399
+ static bool probe_eof(const TSLexer *lexer) {
400
+ const InputProbe *probe = (const InputProbe *)lexer;
401
+ return probe->failed ||
402
+ (probe->position == probe->length && probe->source->eof(probe->source));
403
+ }
404
+
405
+ static void probe_advance(TSLexer *lexer, bool skip) {
406
+ InputProbe *probe = (InputProbe *)lexer;
407
+ (void)skip;
408
+ if (probe_eof(lexer)) {
409
+ return;
410
+ }
411
+ if (probe->position == probe->length) {
412
+ if (probe->length == probe->capacity) {
413
+ if (probe->capacity > SIZE_MAX / 2 / sizeof(*probe->characters)) {
414
+ probe->failed = true;
415
+ lexer->lookahead = 0;
416
+ return;
417
+ }
418
+ const size_t capacity = probe->capacity ? probe->capacity * 2 : 64;
419
+ int32_t *characters =
420
+ ts_realloc(probe->characters, capacity * sizeof(*characters));
421
+ if (characters == NULL) {
422
+ probe->failed = true;
423
+ lexer->lookahead = 0;
424
+ return;
425
+ }
426
+ probe->characters = characters;
427
+ probe->capacity = capacity;
428
+ }
429
+ probe->characters[probe->length++] = lexer->lookahead;
430
+ probe->source->advance(probe->source, false);
388
431
  }
389
- return NULL;
432
+ probe_restore(probe, probe->position + 1);
390
433
  }
391
434
 
392
- static const SingleOperator *
393
- find_single_operator(int32_t character, const bool *valid_symbols) {
394
- for (size_t i = 0; i < ARRAY_LENGTH(SINGLE_OPERATORS); i++) {
395
- const SingleOperator *entry = &SINGLE_OPERATORS[i];
396
- if (entry->character == character && valid_symbols[entry->token]) {
397
- return entry;
435
+ static void probe_mark_end(TSLexer *lexer) {
436
+ InputProbe *probe = (InputProbe *)lexer;
437
+ probe->marked_end = probe->position;
438
+ }
439
+
440
+ enum ProbeToken {
441
+ PROBE_END = 0,
442
+ PROBE_VALUE = 256,
443
+ PROBE_NAME,
444
+ PROBE_GETLINE,
445
+ PROBE_UPDATE,
446
+ PROBE_ASSIGNMENT,
447
+ PROBE_COMPARISON,
448
+ PROBE_MATCH,
449
+ PROBE_MEMBERSHIP,
450
+ PROBE_AND,
451
+ PROBE_OR,
452
+ };
453
+
454
+ static int probe_token(InputProbe *probe, bool operand) {
455
+ TSLexer *lexer = &probe->lexer;
456
+ if (!skip_token_layout(lexer) || probe_eof(lexer)) {
457
+ return PROBE_END;
458
+ }
459
+ const int32_t character = lexer->lookahead;
460
+ if (is_ascii_digit(character) || character == '.') {
461
+ const NumberExtent extent = skip_number(lexer, true);
462
+ if (extent == NUMBER_ABSENT) {
463
+ return PROBE_END;
464
+ }
465
+ probe_restore(probe, probe->marked_end);
466
+ return PROBE_VALUE;
467
+ }
468
+ if (character == '"' || (operand && character == '/')) {
469
+ return skip_literal(lexer) ? PROBE_VALUE : PROBE_END;
470
+ }
471
+ if (character == '(') {
472
+ return skip_group(lexer) ? PROBE_VALUE : PROBE_END;
473
+ }
474
+ if (is_word_start(character)) {
475
+ const WordKind word = scan_word_spelling(lexer);
476
+ const bool call = word == WORD_NAME && lexer->lookahead == '(';
477
+ if (word == WORD_GETLINE) {
478
+ return PROBE_GETLINE;
398
479
  }
480
+ if (word == WORD_MEMBERSHIP) {
481
+ return PROBE_MEMBERSHIP;
482
+ }
483
+ if (word != WORD_NAME && word != WORD_BUILTIN) {
484
+ return PROBE_END;
485
+ }
486
+ if (!skip_token_layout(lexer)) {
487
+ return PROBE_END;
488
+ }
489
+ if (call || word == WORD_BUILTIN) {
490
+ return lexer->lookahead != '(' || skip_group(lexer) ? PROBE_VALUE
491
+ : PROBE_END;
492
+ }
493
+ return lexer->lookahead != '[' || skip_group(lexer) ? PROBE_NAME
494
+ : PROBE_END;
399
495
  }
400
- return NULL;
496
+ lexer->advance(lexer, false);
497
+ if (character_in(character, "+-") && lexer->lookahead == character) {
498
+ lexer->advance(lexer, false);
499
+ return PROBE_UPDATE;
500
+ }
501
+ if (character_in(character, "&|") && lexer->lookahead == character) {
502
+ lexer->advance(lexer, false);
503
+ while (!probe_eof(lexer)) {
504
+ if (!skip_token_layout(lexer)) {
505
+ return PROBE_END;
506
+ }
507
+ if (lexer->lookahead == '#') {
508
+ while (!probe_eof(lexer) && lexer->lookahead != '\n') {
509
+ lexer->advance(lexer, false);
510
+ }
511
+ } else if (lexer->lookahead == '\n') {
512
+ lexer->advance(lexer, false);
513
+ } else {
514
+ break;
515
+ }
516
+ }
517
+ return character == '&' ? PROBE_AND : PROBE_OR;
518
+ }
519
+ if (character_in(character, "+-*/%^=<>!") && lexer->lookahead == '=') {
520
+ lexer->advance(lexer, false);
521
+ return character_in(character, "=<>!") ? PROBE_COMPARISON
522
+ : PROBE_ASSIGNMENT;
523
+ }
524
+ if (character == '!' && lexer->lookahead == '~') {
525
+ lexer->advance(lexer, false);
526
+ return PROBE_MATCH;
527
+ }
528
+ return character;
529
+ }
530
+
531
+ typedef struct {
532
+ bool valid;
533
+ bool lvalue;
534
+ // Allows a surrounding field to take the next postfix update.
535
+ bool postfix;
536
+ bool redirected;
537
+ } ProbeExpression;
538
+
539
+ // BEGIN generated expression rules from grammar.js.
540
+ enum ExpressionPrecedence {
541
+ EXPR_ASSIGNMENT = 2,
542
+ EXPR_CONDITIONAL = 3,
543
+ EXPR_LOGICAL_OR = 4,
544
+ EXPR_LOGICAL_AND = 6,
545
+ EXPR_MEMBERSHIP = 8,
546
+ EXPR_MATCH = 10,
547
+ EXPR_COMPARISON = 12,
548
+ EXPR_CONCATENATION = 14,
549
+ EXPR_ADDITIVE = 16,
550
+ EXPR_MULTIPLICATIVE = 18,
551
+ EXPR_UNARY = 20,
552
+ EXPR_EXPONENTIATION = 21,
553
+ EXPR_POSTFIX = 23,
554
+ EXPR_FIELD = 24,
555
+ };
556
+
557
+ static int expression_right_precedence(int precedence) {
558
+ switch (precedence) {
559
+ case EXPR_ASSIGNMENT:
560
+ return EXPR_ASSIGNMENT;
561
+ case EXPR_CONDITIONAL:
562
+ return EXPR_CONDITIONAL;
563
+ case EXPR_UNARY:
564
+ return EXPR_UNARY;
565
+ case EXPR_EXPONENTIATION:
566
+ return EXPR_UNARY;
567
+ case EXPR_FIELD:
568
+ return EXPR_FIELD;
569
+ default:
570
+ return precedence + 1;
571
+ }
572
+ }
573
+
574
+ static bool expression_non_associative(int precedence) {
575
+ switch (precedence) {
576
+ case EXPR_MATCH:
577
+ case EXPR_COMPARISON:
578
+ return true;
579
+ default:
580
+ return false;
581
+ }
582
+ }
583
+ // END generated expression rules.
584
+
585
+ static int probe_precedence(int token) {
586
+ switch (token) {
587
+ case '=':
588
+ case PROBE_ASSIGNMENT:
589
+ return EXPR_ASSIGNMENT;
590
+ case '?':
591
+ return EXPR_CONDITIONAL;
592
+ case PROBE_OR:
593
+ return EXPR_LOGICAL_OR;
594
+ case PROBE_AND:
595
+ return EXPR_LOGICAL_AND;
596
+ case PROBE_MEMBERSHIP:
597
+ return EXPR_MEMBERSHIP;
598
+ case '~':
599
+ case PROBE_MATCH:
600
+ return EXPR_MATCH;
601
+ case '<':
602
+ case '>':
603
+ case PROBE_COMPARISON:
604
+ return EXPR_COMPARISON;
605
+ case '+':
606
+ case '-':
607
+ return EXPR_ADDITIVE;
608
+ case '*':
609
+ case '/':
610
+ case '%':
611
+ return EXPR_MULTIPLICATIVE;
612
+ case '^':
613
+ return EXPR_EXPONENTIATION;
614
+ case PROBE_UPDATE:
615
+ return EXPR_POSTFIX;
616
+ case PROBE_NAME:
617
+ case PROBE_VALUE:
618
+ case PROBE_GETLINE:
619
+ case '$':
620
+ case '!':
621
+ return EXPR_CONCATENATION;
622
+ default:
623
+ return 0;
624
+ }
625
+ }
626
+
627
+ static bool probe_has_pipe(InputProbe *input) {
628
+ if (input->pipe_checked) {
629
+ return input->may_have_pipe;
630
+ }
631
+ input->pipe_checked = true;
632
+ const size_t start = input->position;
633
+ probe_restore(input, 0);
634
+ bool operand = true;
635
+ bool found = false;
636
+ for (;;) {
637
+ const int token = probe_token(input, operand);
638
+ if (token == '|') {
639
+ found = true;
640
+ break;
641
+ }
642
+ if (probe_precedence(token) == 0 && !character_in(token, "$!:")) {
643
+ break;
644
+ }
645
+ operand = token !=
646
+ PROBE_VALUE &&
647
+ token !=
648
+ PROBE_NAME &&
649
+ token !=
650
+ PROBE_GETLINE &&
651
+ token != PROBE_UPDATE;
652
+ }
653
+ probe_restore(input, start);
654
+ input->may_have_pipe = found;
655
+ return found;
656
+ }
657
+
658
+ typedef enum {
659
+ PROBE_EXPRESSION = 1,
660
+ PROBE_PREFIX,
661
+ PROBE_LVALUE,
662
+ PROBE_GET,
663
+ PROBE_TARGET_TAIL,
664
+ } ProbeRule;
665
+
666
+ typedef struct {
667
+ size_t position;
668
+ ProbeRule rule;
669
+ int argument;
670
+ } ProbeKey;
671
+
672
+ typedef struct {
673
+ ProbeKey key;
674
+ size_t end;
675
+ ProbeExpression expression;
676
+ } ProbeMemo;
677
+
678
+ enum ProbeStep {
679
+ PROBE_START,
680
+ PROBE_AFTER_TARGET_UPDATE,
681
+ PROBE_AFTER_TARGET_LVALUE,
682
+ PROBE_AFTER_FIELD_OPERAND,
683
+ PROBE_AFTER_PREFIX_OPERAND,
684
+ PROBE_AFTER_UNARY_OPERAND,
685
+ PROBE_GET_TARGET,
686
+ PROBE_GET_TAIL,
687
+ PROBE_GET_SOURCE,
688
+ PROBE_GET_REDIRECTED,
689
+ PROBE_EXPR_OPERAND,
690
+ PROBE_EXPR_NEXT,
691
+ PROBE_EXPR_OPERATOR,
692
+ PROBE_EXPR_CONSEQUENCE,
693
+ PROBE_EXPR_RIGHT,
694
+ PROBE_EXPR_PIPE,
695
+ PROBE_EXPR_PIPE_SOURCE,
696
+ PROBE_EXPR_PIPE_GET,
697
+ };
698
+
699
+ enum ProbeGetContext {
700
+ PROBE_FIELD_GET = 1,
701
+ PROBE_SOURCE_ALLOWED = 2,
702
+ PROBE_NO_PIPE = 256,
703
+ };
704
+
705
+ typedef struct {
706
+ ProbeKey key;
707
+ unsigned stage;
708
+ size_t end;
709
+ size_t operand;
710
+ size_t pipe_end;
711
+ int token;
712
+ int precedence;
713
+ int non_associative;
714
+ int ceiling;
715
+ ProbeExpression left;
716
+ ProbeExpression target;
717
+ } ProbeFrame;
718
+
719
+ typedef struct {
720
+ InputProbe *input;
721
+ ProbeFrame *frames;
722
+ size_t length;
723
+ size_t capacity;
724
+ ProbeMemo *memo;
725
+ size_t memo_length;
726
+ size_t memo_capacity;
727
+ ProbeExpression result;
728
+ } ProbeParser;
729
+
730
+ static size_t probe_hash(ProbeKey key) {
731
+ return (key.position * 2654435761u) ^
732
+ ((unsigned)key.rule * 97u + (unsigned)key.argument);
401
733
  }
402
734
 
403
- static bool scan_operator(TSLexer *lexer, const bool *valid_symbols) {
735
+ static ProbeMemo *probe_memo_slot(ProbeParser *parser, ProbeKey key) {
736
+ size_t slot = probe_hash(key) & (parser->memo_capacity - 1);
737
+ while (parser->memo[slot].key.rule != 0) {
738
+ const ProbeKey found = parser->memo[slot].key;
739
+ if (
740
+ found.position ==
741
+ key.position &&
742
+ found.rule ==
743
+ key.rule &&
744
+ found.argument == key.argument
745
+ ) {
746
+ break;
747
+ }
748
+ slot = (slot + 1) & (parser->memo_capacity - 1);
749
+ }
750
+ return &parser->memo[slot];
751
+ }
752
+
753
+ static bool probe_memo_reserve(ProbeParser *parser) {
754
+ if (parser->memo_length * 2 < parser->memo_capacity) {
755
+ return true;
756
+ }
757
+ const size_t old_capacity = parser->memo_capacity;
758
+ if (old_capacity > SIZE_MAX / 2 / sizeof(*parser->memo)) {
759
+ parser->input->failed = true;
760
+ return false;
761
+ }
762
+ const size_t capacity = old_capacity ? old_capacity * 2 : 64;
763
+ ProbeMemo *memo = ts_calloc(capacity, sizeof(*memo));
764
+ if (memo == NULL) {
765
+ parser->input->failed = true;
766
+ return false;
767
+ }
768
+ ProbeMemo *old = parser->memo;
769
+ parser->memo = memo;
770
+ parser->memo_capacity = capacity;
771
+ for (size_t i = 0; i < old_capacity; i++) {
772
+ if (old[i].key.rule != 0) {
773
+ *probe_memo_slot(parser, old[i].key) = old[i];
774
+ }
775
+ }
776
+ ts_free(old);
777
+ return true;
778
+ }
779
+
780
+ static bool probe_memoizes(ProbeRule rule) {
781
+ return rule != PROBE_PREFIX && rule != PROBE_GET;
782
+ }
783
+
784
+ static void probe_call(ProbeParser *parser, ProbeRule rule, int argument) {
785
+ const ProbeKey key = {parser->input->position, rule, argument};
786
+ if (probe_memoizes(rule)) {
787
+ if (!probe_memo_reserve(parser)) {
788
+ return;
789
+ }
790
+ const ProbeMemo *memo = probe_memo_slot(parser, key);
791
+ if (memo->key.rule != 0) {
792
+ probe_restore(parser->input, memo->end);
793
+ parser->result = memo->expression;
794
+ return;
795
+ }
796
+ }
797
+ if (parser->length == parser->capacity) {
798
+ if (parser->capacity > SIZE_MAX / 2 / sizeof(*parser->frames)) {
799
+ parser->input->failed = true;
800
+ return;
801
+ }
802
+ const size_t capacity = parser->capacity ? parser->capacity * 2 : 32;
803
+ ProbeFrame *frames = ts_realloc(parser->frames, capacity * sizeof(*frames));
804
+ if (frames == NULL) {
805
+ parser->input->failed = true;
806
+ return;
807
+ }
808
+ parser->frames = frames;
809
+ parser->capacity = capacity;
810
+ }
811
+ parser->frames[parser->length++] = (ProbeFrame){.key = key};
812
+ }
813
+
814
+ static void probe_return(ProbeParser *parser, ProbeExpression result) {
815
+ const ProbeKey key = parser->frames[--parser->length].key;
816
+ parser->result = result;
817
+ if (probe_memoizes(key.rule) && probe_memo_reserve(parser)) {
818
+ ProbeMemo *memo = probe_memo_slot(parser, key);
819
+ if (memo->key.rule == 0) {
820
+ parser->memo_length++;
821
+ }
822
+ *memo = (ProbeMemo){key, parser->input->position, result};
823
+ }
824
+ }
825
+
826
+ static ProbeExpression
827
+ probe_parse(InputProbe *input, ProbeRule rule, int argument) {
828
+ ProbeParser parser = {.input = input};
829
+ probe_call(&parser, rule, argument);
830
+ while (parser.length && !input->failed) {
831
+ ProbeFrame *frame = &parser.frames[parser.length - 1];
832
+ switch (frame->key.rule) {
833
+ case PROBE_TARGET_TAIL:
834
+ if (frame->stage == PROBE_AFTER_TARGET_LVALUE) {
835
+ probe_restore(input, frame->key.position);
836
+ probe_return(&parser, (ProbeExpression){.valid = parser.result.valid});
837
+ } else if (frame->stage == PROBE_AFTER_TARGET_UPDATE) {
838
+ if (parser.result.valid) {
839
+ frame->stage = PROBE_AFTER_TARGET_LVALUE;
840
+ probe_call(&parser, PROBE_TARGET_TAIL, 0);
841
+ } else {
842
+ probe_restore(input, frame->key.position);
843
+ probe_return(&parser, (ProbeExpression){0});
844
+ }
845
+ } else if (
846
+ !skip_token_layout(&input->lexer) ||
847
+ !character_in(input->lexer.lookahead, "+-") ||
848
+ probe_token(input, false) != PROBE_UPDATE
849
+ ) {
850
+ probe_restore(input, frame->key.position);
851
+ probe_return(&parser, (ProbeExpression){.valid = true});
852
+ } else {
853
+ frame->stage = PROBE_AFTER_TARGET_UPDATE;
854
+ probe_call(&parser, PROBE_LVALUE, true);
855
+ }
856
+ break;
857
+ case PROBE_LVALUE:
858
+ if (frame->stage == PROBE_AFTER_FIELD_OPERAND) {
859
+ ProbeExpression result = parser.result;
860
+ result.lvalue = result.valid;
861
+ probe_return(&parser, result);
862
+ break;
863
+ }
864
+ if (
865
+ !skip_token_layout(&input->lexer) ||
866
+ (!is_word_start(input->lexer.lookahead) &&
867
+ input->lexer.lookahead != '$')
868
+ ) {
869
+ probe_restore(input, frame->key.position);
870
+ probe_return(&parser, (ProbeExpression){0});
871
+ break;
872
+ }
873
+ frame->token = probe_token(input, true);
874
+ if (frame->token == PROBE_NAME) {
875
+ probe_return(&parser, (ProbeExpression){true, true, true, false});
876
+ } else if (frame->token != '$') {
877
+ probe_restore(input, frame->key.position);
878
+ probe_return(&parser, (ProbeExpression){0});
879
+ } else {
880
+ do {
881
+ frame->operand = input->position;
882
+ } while (probe_token(input, true) == '$');
883
+ probe_restore(input, frame->operand);
884
+ frame->stage = PROBE_AFTER_FIELD_OPERAND;
885
+ probe_call(&parser, PROBE_PREFIX, !frame->key.argument | PROBE_NO_PIPE);
886
+ }
887
+ break;
888
+ case PROBE_PREFIX:
889
+ if (frame->stage == PROBE_AFTER_PREFIX_OPERAND) {
890
+ probe_return(&parser, parser.result);
891
+ break;
892
+ }
893
+ if (frame->stage == PROBE_AFTER_UNARY_OPERAND) {
894
+ probe_return(&parser, (ProbeExpression){.valid = parser.result.valid});
895
+ break;
896
+ }
897
+ switch (probe_token(input, true)) {
898
+ case PROBE_VALUE:
899
+ probe_return(
900
+ &parser,
901
+ (ProbeExpression){.valid = true, .postfix = true}
902
+ );
903
+ break;
904
+ case PROBE_NAME:
905
+ probe_return(&parser, (ProbeExpression){true, true, true, false});
906
+ break;
907
+ case PROBE_GETLINE:
908
+ frame->stage = PROBE_AFTER_PREFIX_OPERAND;
909
+ probe_call(
910
+ &parser,
911
+ PROBE_GET,
912
+ (frame->key.argument & PROBE_FIELD_GET) | PROBE_SOURCE_ALLOWED
913
+ );
914
+ break;
915
+ case '$':
916
+ probe_restore(input, frame->key.position);
917
+ frame->stage = PROBE_AFTER_PREFIX_OPERAND;
918
+ probe_call(&parser, PROBE_LVALUE, false);
919
+ break;
920
+ case PROBE_UPDATE:
921
+ frame->stage = PROBE_AFTER_UNARY_OPERAND;
922
+ probe_call(&parser, PROBE_LVALUE, true);
923
+ break;
924
+ case '+':
925
+ case '-':
926
+ case '!':
927
+ frame->stage = PROBE_AFTER_UNARY_OPERAND;
928
+ probe_call(
929
+ &parser,
930
+ PROBE_EXPRESSION,
931
+ EXPR_UNARY | (frame->key.argument & PROBE_NO_PIPE)
932
+ );
933
+ break;
934
+ default:
935
+ probe_restore(input, frame->key.position);
936
+ probe_return(&parser, (ProbeExpression){0});
937
+ break;
938
+ }
939
+ break;
940
+ case PROBE_GET:
941
+ switch (frame->stage) {
942
+ case PROBE_START:
943
+ frame->stage = PROBE_GET_TARGET;
944
+ probe_call(&parser, PROBE_LVALUE, false);
945
+ break;
946
+ case PROBE_GET_TARGET:
947
+ frame->target = parser.result;
948
+ frame->stage = PROBE_GET_SOURCE;
949
+ if (!frame->target.valid) {
950
+ probe_restore(input, frame->key.position);
951
+ } else if (!(frame->key.argument & PROBE_FIELD_GET)) {
952
+ frame->stage = PROBE_GET_TAIL;
953
+ probe_call(&parser, PROBE_TARGET_TAIL, 0);
954
+ }
955
+ break;
956
+ case PROBE_GET_TAIL:
957
+ if (!parser.result.valid) {
958
+ input->deferred_target = true;
959
+ probe_restore(input, frame->key.position);
960
+ frame->target = (ProbeExpression){0};
961
+ }
962
+ frame->stage = PROBE_GET_SOURCE;
963
+ break;
964
+ case PROBE_GET_SOURCE:
965
+ frame->left = (ProbeExpression){
966
+ .valid = true,
967
+ .postfix = !frame->target.valid || frame->target.postfix,
968
+ .redirected = frame->target.redirected,
969
+ };
970
+ frame->end = input->position;
971
+ if (
972
+ (frame->key.argument & PROBE_SOURCE_ALLOWED) &&
973
+ probe_token(input, false) == '<'
974
+ ) {
975
+ frame->stage = PROBE_GET_REDIRECTED;
976
+ probe_call(&parser, PROBE_EXPRESSION, EXPR_ASSIGNMENT);
977
+ } else {
978
+ probe_restore(input, frame->end);
979
+ probe_return(&parser, frame->left);
980
+ }
981
+ break;
982
+ default:
983
+ probe_return(
984
+ &parser,
985
+ (ProbeExpression){
986
+ .valid = parser.result.valid,
987
+ .postfix = true,
988
+ .redirected = true,
989
+ }
990
+ );
991
+ break;
992
+ }
993
+ break;
994
+ case PROBE_EXPRESSION:
995
+ switch (frame->stage) {
996
+ case PROBE_START:
997
+ frame->stage = PROBE_EXPR_OPERAND;
998
+ probe_call(&parser, PROBE_PREFIX, frame->key.argument & PROBE_NO_PIPE);
999
+ break;
1000
+ case PROBE_EXPR_OPERAND:
1001
+ if (!parser.result.valid) {
1002
+ probe_return(&parser, parser.result);
1003
+ } else {
1004
+ frame->left = parser.result;
1005
+ frame->stage = PROBE_EXPR_NEXT;
1006
+ }
1007
+ break;
1008
+ case PROBE_EXPR_NEXT:
1009
+ frame->end = input->position;
1010
+ frame->token = probe_token(input, false);
1011
+ frame->precedence = probe_precedence(frame->token);
1012
+ if (frame->token == '|' && frame->key.argument == EXPR_ASSIGNMENT) {
1013
+ if (probe_token(input, false) != PROBE_GETLINE) {
1014
+ probe_restore(input, frame->end);
1015
+ probe_return(&parser, frame->left);
1016
+ } else {
1017
+ frame->stage = PROBE_EXPR_PIPE;
1018
+ probe_call(&parser, PROBE_GET, 0);
1019
+ }
1020
+ } else if (frame->token == PROBE_UPDATE) {
1021
+ const size_t operand = input->position;
1022
+ const bool prefix = scan_lvalue_start(&input->lexer);
1023
+ probe_restore(input, operand);
1024
+ if (
1025
+ (frame->key.argument & ~PROBE_NO_PIPE) <=
1026
+ EXPR_POSTFIX &&
1027
+ frame->left.lvalue &&
1028
+ frame->left.postfix &&
1029
+ (!frame->left.redirected || !prefix)
1030
+ ) {
1031
+ frame->left = (ProbeExpression){.valid = true};
1032
+ frame->stage = PROBE_EXPR_NEXT;
1033
+ } else {
1034
+ frame->precedence = prefix ? EXPR_CONCATENATION : 0;
1035
+ frame->stage = PROBE_EXPR_OPERATOR;
1036
+ }
1037
+ } else {
1038
+ frame->stage = PROBE_EXPR_OPERATOR;
1039
+ }
1040
+ break;
1041
+ case PROBE_EXPR_OPERATOR: {
1042
+ const int precedence = frame->precedence;
1043
+ if (
1044
+ precedence <
1045
+ (frame->key.argument & ~PROBE_NO_PIPE) ||
1046
+ (frame->ceiling != 0 && precedence > frame->ceiling) ||
1047
+ precedence ==
1048
+ frame->non_associative ||
1049
+ (precedence == EXPR_ASSIGNMENT && !frame->left.lvalue)
1050
+ ) {
1051
+ if (
1052
+ !(frame->key.argument & PROBE_NO_PIPE) &&
1053
+ (precedence > 0 || frame->token == '|') &&
1054
+ probe_has_pipe(input)
1055
+ ) {
1056
+ probe_restore(input, frame->key.position);
1057
+ frame->stage = PROBE_EXPR_PIPE_SOURCE;
1058
+ probe_call(
1059
+ &parser,
1060
+ PROBE_EXPRESSION,
1061
+ EXPR_ASSIGNMENT | PROBE_NO_PIPE
1062
+ );
1063
+ } else {
1064
+ probe_restore(input, frame->end);
1065
+ probe_return(&parser, frame->left);
1066
+ }
1067
+ break;
1068
+ }
1069
+ if (precedence == EXPR_CONCATENATION) {
1070
+ probe_restore(input, frame->end);
1071
+ }
1072
+ if (frame->token == '?') {
1073
+ frame->stage = PROBE_EXPR_CONSEQUENCE;
1074
+ probe_call(
1075
+ &parser,
1076
+ PROBE_EXPRESSION,
1077
+ EXPR_ASSIGNMENT | (frame->key.argument & PROBE_NO_PIPE)
1078
+ );
1079
+ } else if (frame->token == PROBE_MEMBERSHIP) {
1080
+ parser.result = (ProbeExpression){
1081
+ .valid = probe_token(input, true) == PROBE_NAME,
1082
+ };
1083
+ frame->stage = PROBE_EXPR_RIGHT;
1084
+ } else {
1085
+ const int right_precedence = expression_right_precedence(precedence);
1086
+ frame->stage = PROBE_EXPR_RIGHT;
1087
+ probe_call(
1088
+ &parser,
1089
+ PROBE_EXPRESSION,
1090
+ right_precedence | (frame->key.argument & PROBE_NO_PIPE)
1091
+ );
1092
+ }
1093
+ break;
1094
+ }
1095
+ case PROBE_EXPR_CONSEQUENCE:
1096
+ if (!parser.result.valid || probe_token(input, false) != ':') {
1097
+ probe_restore(input, frame->end);
1098
+ probe_return(&parser, frame->left);
1099
+ } else {
1100
+ frame->stage = PROBE_EXPR_RIGHT;
1101
+ probe_call(
1102
+ &parser,
1103
+ PROBE_EXPRESSION,
1104
+ EXPR_CONDITIONAL | (frame->key.argument & PROBE_NO_PIPE)
1105
+ );
1106
+ }
1107
+ break;
1108
+ case PROBE_EXPR_RIGHT:
1109
+ case PROBE_EXPR_PIPE:
1110
+ case PROBE_EXPR_PIPE_GET:
1111
+ if (
1112
+ !parser.result.valid ||
1113
+ (frame->stage ==
1114
+ PROBE_EXPR_PIPE_GET &&
1115
+ (input->position <
1116
+ frame->end ||
1117
+ input->position == frame->pipe_end))
1118
+ ) {
1119
+ probe_restore(input, frame->end);
1120
+ probe_return(&parser, frame->left);
1121
+ } else {
1122
+ if (frame->stage == PROBE_EXPR_PIPE_GET) {
1123
+ frame->pipe_end = input->position;
1124
+ }
1125
+ frame->non_associative = frame->stage ==
1126
+ PROBE_EXPR_RIGHT &&
1127
+ expression_non_associative(frame->precedence)
1128
+ ? frame->precedence
1129
+ : 0;
1130
+ frame->ceiling =
1131
+ frame->stage == PROBE_EXPR_RIGHT ? frame->precedence : 0;
1132
+ frame->left = (ProbeExpression){.valid = true};
1133
+ frame->stage = PROBE_EXPR_NEXT;
1134
+ }
1135
+ break;
1136
+ case PROBE_EXPR_PIPE_SOURCE:
1137
+ if (
1138
+ !parser.result.valid ||
1139
+ probe_token(input, false) !=
1140
+ '|' ||
1141
+ probe_token(input, false) != PROBE_GETLINE
1142
+ ) {
1143
+ probe_restore(input, frame->end);
1144
+ probe_return(&parser, frame->left);
1145
+ } else {
1146
+ frame->stage = PROBE_EXPR_PIPE_GET;
1147
+ probe_call(&parser, PROBE_GET, 0);
1148
+ }
1149
+ break;
1150
+ }
1151
+ break;
1152
+ }
1153
+ }
1154
+ const ProbeExpression result =
1155
+ input->failed ? (ProbeExpression){0} : parser.result;
1156
+ ts_free(parser.frames);
1157
+ ts_free(parser.memo);
1158
+ return result;
1159
+ }
1160
+
1161
+ typedef enum {
1162
+ PROBE_SOURCE,
1163
+ PROBE_UNARY_TARGET,
1164
+ PROBE_PREFIX_GETLINE,
1165
+ } ProbeContext;
1166
+
1167
+ static bool
1168
+ probe_getline_field(TSLexer *lexer, ProbeContext context, bool *deferred) {
1169
+ InputProbe probe = {
1170
+ .lexer =
1171
+ {
1172
+ .lookahead = lexer->lookahead,
1173
+ .advance = probe_advance,
1174
+ .mark_end = probe_mark_end,
1175
+ .eof = probe_eof,
1176
+ },
1177
+ .source = lexer,
1178
+ };
1179
+ bool survives = true;
1180
+ bool source = context == PROBE_SOURCE;
1181
+ bool tail = false;
1182
+ if (context == PROBE_UNARY_TARGET) {
1183
+ if (
1184
+ probe_parse(&probe, PROBE_EXPRESSION, EXPR_UNARY | PROBE_NO_PIPE).valid
1185
+ ) {
1186
+ source = probe_token(&probe, false) == '<';
1187
+ }
1188
+ } else if (context == PROBE_PREFIX_GETLINE) {
1189
+ const bool targeted = probe_parse(&probe, PROBE_LVALUE, false).valid;
1190
+ const size_t end = probe.position;
1191
+ source = probe_token(&probe, false) == '<';
1192
+ if (!source) {
1193
+ probe_restore(&probe, end);
1194
+ tail = !targeted;
1195
+ }
1196
+ }
1197
+ if (source) {
1198
+ tail = probe_parse(&probe, PROBE_EXPRESSION, EXPR_ASSIGNMENT).valid;
1199
+ }
1200
+ if (tail) {
1201
+ survives = probe_parse(&probe, PROBE_TARGET_TAIL, 0).valid;
1202
+ }
1203
+ *deferred |= probe.deferred_target;
1204
+ ts_free(probe.characters);
1205
+ return survives;
1206
+ }
1207
+
1208
+ typedef enum {
1209
+ LVALUE_SHAPE_NONE,
1210
+ LVALUE_SHAPE_POSTFIX,
1211
+ LVALUE_SHAPE_SETTLED,
1212
+ LVALUE_SHAPE_OPEN,
1213
+ } LvalueShape;
1214
+
1215
+ // POSTFIX leaves an update outside a getline source; OPEN may accept one.
1216
+ // SETTLED leaves no update to place, including malformed input.
1217
+ static LvalueShape
1218
+ skip_lvalue(TSLexer *lexer, bool prefix_update, bool *deferred) {
1219
+ bool targeted = false;
1220
+ for (;;) {
1221
+ if (!skip_token_layout(lexer)) {
1222
+ return LVALUE_SHAPE_SETTLED;
1223
+ }
1224
+ bool field = false;
1225
+ while (lexer->lookahead == '$') {
1226
+ field = true;
1227
+ lexer->advance(lexer, false);
1228
+ if (!skip_token_layout(lexer)) {
1229
+ return LVALUE_SHAPE_SETTLED;
1230
+ }
1231
+ if (character_in(lexer->lookahead, "+-!")) {
1232
+ return targeted &&
1233
+ !probe_getline_field(lexer, PROBE_UNARY_TARGET, deferred)
1234
+ ? LVALUE_SHAPE_POSTFIX
1235
+ : LVALUE_SHAPE_SETTLED;
1236
+ }
1237
+ }
1238
+ bool name = false;
1239
+ bool input = false;
1240
+ if (
1241
+ field && (is_ascii_digit(lexer->lookahead) || lexer->lookahead == '.')
1242
+ ) {
1243
+ if (skip_number(lexer, false) != NUMBER_WHOLE) {
1244
+ return LVALUE_SHAPE_SETTLED;
1245
+ }
1246
+ } else if (field && lexer->lookahead == '(') {
1247
+ if (!skip_group(lexer)) {
1248
+ return LVALUE_SHAPE_SETTLED;
1249
+ }
1250
+ } else if (field && character_in(lexer->lookahead, "\"/")) {
1251
+ if (!skip_literal(lexer)) {
1252
+ return LVALUE_SHAPE_SETTLED;
1253
+ }
1254
+ } else {
1255
+ const WordKind word = scan_word_spelling(lexer);
1256
+ const bool call = word == WORD_NAME && lexer->lookahead == '(';
1257
+ if (field && word == WORD_GETLINE) {
1258
+ if (prefix_update) {
1259
+ return probe_getline_field(lexer, PROBE_PREFIX_GETLINE, deferred)
1260
+ ? LVALUE_SHAPE_SETTLED
1261
+ : LVALUE_SHAPE_POSTFIX;
1262
+ }
1263
+ if (!skip_token_layout(lexer)) {
1264
+ return LVALUE_SHAPE_SETTLED;
1265
+ }
1266
+ if (is_word_start(lexer->lookahead) || lexer->lookahead == '$') {
1267
+ targeted = true;
1268
+ continue;
1269
+ }
1270
+ input = true;
1271
+ } else if (field && (call || word == WORD_BUILTIN)) {
1272
+ if (
1273
+ !skip_token_layout(lexer) ||
1274
+ (lexer->lookahead == '(' && !skip_group(lexer))
1275
+ ) {
1276
+ return LVALUE_SHAPE_SETTLED;
1277
+ }
1278
+ } else if (call || word != WORD_NAME) {
1279
+ return field || targeted ? LVALUE_SHAPE_SETTLED : LVALUE_SHAPE_NONE;
1280
+ } else {
1281
+ name = true;
1282
+ }
1283
+ }
1284
+ if (!skip_token_layout(lexer)) {
1285
+ return LVALUE_SHAPE_SETTLED;
1286
+ }
1287
+ if (name && lexer->lookahead == '[') {
1288
+ if (!skip_group(lexer) || !skip_token_layout(lexer)) {
1289
+ return LVALUE_SHAPE_SETTLED;
1290
+ }
1291
+ }
1292
+ if ((input || targeted) && lexer->lookahead == '<') {
1293
+ lexer->advance(lexer, false);
1294
+ if (lexer->lookahead != '=') {
1295
+ return probe_getline_field(lexer, PROBE_SOURCE, deferred)
1296
+ ? LVALUE_SHAPE_SETTLED
1297
+ : LVALUE_SHAPE_POSTFIX;
1298
+ }
1299
+ }
1300
+ return LVALUE_SHAPE_OPEN;
1301
+ }
1302
+ }
1303
+
1304
+ static enum TokenType probe_getline_operand(TSLexer *lexer, bool *deferred) {
1305
+ for (bool updated = false;; updated = true) {
1306
+ const LvalueShape shape = skip_lvalue(lexer, updated, deferred);
1307
+ if (shape == LVALUE_SHAPE_POSTFIX) {
1308
+ return GETLINE_OMITTED_WORD;
1309
+ }
1310
+ if (shape == LVALUE_SHAPE_NONE) {
1311
+ return updated ? GETLINE_OMITTED_WORD : GETLINE_WORD;
1312
+ }
1313
+ const int32_t sign = lexer->lookahead;
1314
+ if (shape == LVALUE_SHAPE_SETTLED || (sign != '+' && sign != '-')) {
1315
+ return GETLINE_TARGET_WORD;
1316
+ }
1317
+ lexer->advance(lexer, false);
1318
+ if (lexer->lookahead != sign) {
1319
+ return GETLINE_TARGET_WORD;
1320
+ }
1321
+ lexer->advance(lexer, false);
1322
+ }
1323
+ }
1324
+
1325
+ static enum TokenType scan_getline_operand(TSLexer *lexer) {
1326
+ bool deferred = false;
1327
+ const enum TokenType token = probe_getline_operand(lexer, &deferred);
1328
+ if (!deferred) {
1329
+ return token;
1330
+ }
1331
+ if (token == GETLINE_TARGET_WORD) {
1332
+ return GETLINE_PREFER_TARGET_WORD;
1333
+ }
1334
+ return token == GETLINE_OMITTED_WORD ? GETLINE_PREFER_OMITTED_WORD : token;
1335
+ }
1336
+
1337
+ static bool scan_contextual_word(
1338
+ TSLexer *lexer,
1339
+ const bool *valid_symbols,
1340
+ bool recovering
1341
+ ) {
1342
+ const WordKind word = scan_word_spelling(lexer);
1343
+ lexer->mark_end(lexer);
1344
+ if (word == WORD_NAME && lexer->lookahead == '(') {
1345
+ return emit(lexer, FUNC_NAME_WORD);
1346
+ }
1347
+ if (word != WORD_GETLINE) {
1348
+ return false;
1349
+ }
1350
+ // Returning GETLINE_WORD here makes repeated recovery quadratic.
1351
+ if (recovering) {
1352
+ return emit(lexer, ERROR_SENTINEL);
1353
+ }
1354
+ enum TokenType token = GETLINE_WORD;
1355
+ if (valid_symbols[GETLINE_TARGET_WORD]) {
1356
+ token = scan_getline_operand(lexer);
1357
+ } else if (valid_symbols[GETLINE_FIELD_WORD]) {
1358
+ token = GETLINE_FIELD_WORD;
1359
+ }
1360
+ return emit(lexer, token);
1361
+ }
1362
+
1363
+ static bool scan_sign(TSLexer *lexer, const bool *valid_symbols) {
404
1364
  const int32_t first = lexer->lookahead;
1365
+ if (first != '+' && first != '-') {
1366
+ return false;
1367
+ }
405
1368
  lexer->advance(lexer, false);
406
1369
  lexer->mark_end(lexer);
407
- const CompositeOperator *composite =
408
- find_composite_operator(first, lexer->lookahead);
409
- if (composite != NULL) {
410
- if (!valid_symbols[composite->token]) {
411
- return false;
412
- }
1370
+ if (lexer->lookahead == '=') {
1371
+ return false;
1372
+ }
1373
+ if (lexer->lookahead == first) {
413
1374
  lexer->advance(lexer, false);
414
1375
  lexer->mark_end(lexer);
415
- return emit(lexer, composite->token);
1376
+ const enum TokenType token = first == '+' ? INCR_OPERATOR : DECR_OPERATOR;
1377
+ return scan_lvalue_start(lexer) &&
1378
+ valid_symbols[token] &&
1379
+ emit(lexer, token);
416
1380
  }
417
- const SingleOperator *single = find_single_operator(first, valid_symbols);
418
- return single != NULL && emit(lexer, single->token);
1381
+ const enum TokenType token = first == '+' ? PLUS_OPERATOR : MINUS_OPERATOR;
1382
+ return valid_symbols[token] && emit(lexer, token);
1383
+ }
1384
+
1385
+ // Read past output pipes too, so later edits invalidate reused nodes.
1386
+ static bool
1387
+ scan_getline_pipe(TSLexer *lexer, const bool *valid_symbols, bool recovering) {
1388
+ lexer->advance(lexer, false);
1389
+ lexer->mark_end(lexer);
1390
+ const bool getline =
1391
+ skip_token_layout(lexer) && scan_word_spelling(lexer) == WORD_GETLINE;
1392
+ return getline &&
1393
+ !recovering &&
1394
+ valid_symbols[GETLINE_PIPE] &&
1395
+ emit(lexer, GETLINE_PIPE);
419
1396
  }
420
1397
 
421
1398
  static bool scan_slash_start(
@@ -425,18 +1402,8 @@ static bool scan_slash_start(
425
1402
  ) {
426
1403
  lexer->advance(lexer, false);
427
1404
  lexer->mark_end(lexer);
428
- if (lexer->lookahead == '=') {
429
- if (valid_symbols[DIV_ASSIGN_OPERATOR]) {
430
- lexer->advance(lexer, false);
431
- lexer->mark_end(lexer);
432
- return emit(lexer, DIV_ASSIGN_OPERATOR);
433
- }
434
- if (valid_symbols[DIVISION_SLASH]) {
435
- return false;
436
- }
437
- }
438
1405
  if (valid_symbols[DIVISION_SLASH]) {
439
- return emit(lexer, DIVISION_SLASH);
1406
+ return lexer->lookahead != '=' && emit(lexer, DIVISION_SLASH);
440
1407
  }
441
1408
  return valid_symbols[ERE_OPENING_SLASH] &&
442
1409
  emit_mode(state, lexer, LEXICAL_MODE_ERE_BODY, ERE_OPENING_SLASH);
@@ -474,8 +1441,7 @@ static bool scan_escape(const ScannerState *state, TSLexer *lexer) {
474
1441
  }
475
1442
 
476
1443
  // Every backslash must be emitted to prevent fallback to the internal marker.
477
- static bool
478
- scan_backslash(ScannerState *state, TSLexer *lexer, bool recovering) {
1444
+ static bool scan_backslash(ScannerState *state, TSLexer *lexer) {
479
1445
  lexer->advance(lexer, false);
480
1446
  lexer->mark_end(lexer);
481
1447
  if (state->mode == LEXICAL_MODE_OUTSIDE) {
@@ -489,28 +1455,7 @@ scan_backslash(ScannerState *state, TSLexer *lexer, bool recovering) {
489
1455
  CONTINUATION_BACKSLASH
490
1456
  );
491
1457
  }
492
- return !recovering && scan_escape(state, lexer);
493
- }
494
-
495
- static bool scan_string_content(TSLexer *lexer) {
496
- bool consumed = false;
497
- while (!lexer->eof(lexer) && !character_in(lexer->lookahead, "\"\\\n")) {
498
- consumed = true;
499
- lexer->advance(lexer, false);
500
- }
501
- lexer->mark_end(lexer);
502
- return consumed && emit(lexer, STRING_CONTENT);
503
- }
504
-
505
- static bool scan_ere_spelling(TSLexer *lexer, enum TokenType token) {
506
- do {
507
- lexer->advance(lexer, false);
508
- } while (
509
- is_ascii_digit(lexer->lookahead) ||
510
- (token == ERE_CLASS_NAME && is_ascii_letter(lexer->lookahead))
511
- );
512
- lexer->mark_end(lexer);
513
- return emit(lexer, token);
1458
+ return scan_escape(state, lexer);
514
1459
  }
515
1460
 
516
1461
  typedef struct {
@@ -527,6 +1472,57 @@ static const EreCompoundToken ERE_COMPOUND_TOKENS[] = {
527
1472
  {ERE_COLON_CLOSING, ERE_COMPOUND_CONTENT, ':', LEXICAL_MODE_ERE_CLASS},
528
1473
  };
529
1474
 
1475
+ static bool compound_has_escape(TSLexer *lexer, int32_t marker) {
1476
+ lexer->advance(lexer, false);
1477
+ while (
1478
+ !lexer->eof(lexer) && lexer->lookahead != '\n' && lexer->lookahead != '/'
1479
+ ) {
1480
+ const int32_t character = lexer->lookahead;
1481
+ if (character == '\\') {
1482
+ return true;
1483
+ }
1484
+ lexer->advance(lexer, false);
1485
+ if (character == marker && lexer->lookahead == ']') {
1486
+ break;
1487
+ }
1488
+ }
1489
+ return false;
1490
+ }
1491
+
1492
+ static bool scan_ere_collating_element(
1493
+ const ScannerState *state,
1494
+ TSLexer *lexer,
1495
+ const bool *valid_symbols
1496
+ ) {
1497
+ const int32_t marker = state->mode == LEXICAL_MODE_ERE_COLLATING ? '.' : '=';
1498
+ const int32_t first = lexer->lookahead;
1499
+ unsigned count = 0;
1500
+ while (
1501
+ !lexer->eof(lexer) &&
1502
+ lexer->lookahead !=
1503
+ '\n' &&
1504
+ lexer->lookahead !=
1505
+ '/' &&
1506
+ lexer->lookahead != '\\'
1507
+ ) {
1508
+ lexer->mark_end(lexer);
1509
+ const int32_t character = lexer->lookahead;
1510
+ lexer->advance(lexer, false);
1511
+ if (character == marker && lexer->lookahead == ']') {
1512
+ if (count == 0 || (count == 1 && character_in(first, "-]"))) {
1513
+ return false;
1514
+ }
1515
+ const enum TokenType token =
1516
+ count == 1 ? ERE_COMPOUND_SINGLE : ERE_COMPOUND_MULTI;
1517
+ return valid_symbols[token] && emit(lexer, token);
1518
+ }
1519
+ if (count < 2) {
1520
+ count++;
1521
+ }
1522
+ }
1523
+ return false;
1524
+ }
1525
+
530
1526
  static bool scan_ere_compound_token(
531
1527
  ScannerState *state,
532
1528
  TSLexer *lexer,
@@ -542,10 +1538,14 @@ static bool scan_ere_compound_token(
542
1538
  if (!terminates) {
543
1539
  return valid_symbols[token->content] && emit(lexer, token->content);
544
1540
  }
545
- if (!valid_symbols[token->delimiter]) {
1541
+ if (
1542
+ !valid_symbols[token->delimiter] &&
1543
+ !(opening && valid_symbols[ERE_ESCAPED_COMPOUND_OPENING])
1544
+ ) {
546
1545
  return false;
547
1546
  }
548
1547
  LexicalMode mode = LEXICAL_MODE_ERE_BODY;
1548
+ enum TokenType delimiter = token->delimiter;
549
1549
  if (opening) {
550
1550
  for (size_t i = 1; i < ARRAY_LENGTH(ERE_COMPOUND_TOKENS); i++) {
551
1551
  if (ERE_COMPOUND_TOKENS[i].first == lexer->lookahead) {
@@ -553,8 +1553,15 @@ static bool scan_ere_compound_token(
553
1553
  break;
554
1554
  }
555
1555
  }
1556
+ if (
1557
+ mode !=
1558
+ LEXICAL_MODE_ERE_CLASS &&
1559
+ compound_has_escape(lexer, lexer->lookahead)
1560
+ ) {
1561
+ delimiter = ERE_ESCAPED_COMPOUND_OPENING;
1562
+ }
556
1563
  }
557
- return emit_mode(state, lexer, mode, token->delimiter);
1564
+ return valid_symbols[delimiter] && emit_mode(state, lexer, mode, delimiter);
558
1565
  }
559
1566
 
560
1567
  static bool scan_ere_context(
@@ -564,18 +1571,20 @@ static bool scan_ere_context(
564
1571
  bool recovering
565
1572
  ) {
566
1573
  if (!recovering) {
1574
+ if (
1575
+ (state->mode ==
1576
+ LEXICAL_MODE_ERE_COLLATING ||
1577
+ state->mode == LEXICAL_MODE_ERE_EQUIVALENCE) &&
1578
+ (valid_symbols[ERE_COMPOUND_SINGLE] || valid_symbols[ERE_COMPOUND_MULTI])
1579
+ ) {
1580
+ return scan_ere_collating_element(state, lexer, valid_symbols);
1581
+ }
567
1582
  for (size_t i = 0; i < ARRAY_LENGTH(ERE_COMPOUND_TOKENS); i++) {
568
1583
  const EreCompoundToken *token = &ERE_COMPOUND_TOKENS[i];
569
1584
  if (lexer->lookahead == token->first) {
570
1585
  return scan_ere_compound_token(state, lexer, token, valid_symbols);
571
1586
  }
572
1587
  }
573
- if (valid_symbols[ERE_CLASS_NAME] && is_ascii_letter(lexer->lookahead)) {
574
- return scan_ere_spelling(lexer, ERE_CLASS_NAME);
575
- }
576
- if (valid_symbols[ERE_DUP_COUNT] && is_ascii_digit(lexer->lookahead)) {
577
- return scan_ere_spelling(lexer, ERE_DUP_COUNT);
578
- }
579
1588
  }
580
1589
  if (lexer->lookahead == '/' && valid_symbols[ERE_CLOSING]) {
581
1590
  lexer->advance(lexer, false);
@@ -654,7 +1663,12 @@ bool tree_sitter_posix_awk_external_scanner_scan(
654
1663
  }
655
1664
  lexer->mark_end(lexer);
656
1665
  if (lexer->lookahead == '\\') {
657
- return scan_backslash(state, lexer, recovering);
1666
+ return scan_backslash(state, lexer);
1667
+ }
1668
+ // Save the mode change without consuming the newline.
1669
+ if (lexer->lookahead == '\n' && state->mode != LEXICAL_MODE_OUTSIDE) {
1670
+ return valid_symbols[LITERAL_BREAK] &&
1671
+ emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, LITERAL_BREAK);
658
1672
  }
659
1673
  if (is_ere_mode(state->mode)) {
660
1674
  return scan_ere_context(state, lexer, valid_symbols, recovering);
@@ -665,9 +1679,7 @@ bool tree_sitter_posix_awk_external_scanner_scan(
665
1679
  lexer->mark_end(lexer);
666
1680
  return emit_mode(state, lexer, LEXICAL_MODE_OUTSIDE, STRING_CLOSING);
667
1681
  }
668
- return !recovering &&
669
- valid_symbols[STRING_CONTENT] &&
670
- scan_string_content(lexer);
1682
+ return false;
671
1683
  }
672
1684
  if (lexer->lookahead == '#' && valid_symbols[COMMENT]) {
673
1685
  return scan_comment(lexer);
@@ -677,20 +1689,17 @@ bool tree_sitter_posix_awk_external_scanner_scan(
677
1689
  lexer->mark_end(lexer);
678
1690
  return emit_mode(state, lexer, LEXICAL_MODE_STRING, STRING_OPENING);
679
1691
  }
680
- if (recovering) {
681
- return false;
682
- }
683
1692
  if (is_word_start(lexer->lookahead)) {
684
- return scan_word_token(lexer, valid_symbols);
1693
+ return scan_contextual_word(lexer, valid_symbols, recovering);
685
1694
  }
686
- if (
687
- (is_ascii_digit(lexer->lookahead) || lexer->lookahead == '.') &&
688
- valid_symbols[NUMBER]
689
- ) {
690
- return scan_number_token(lexer);
1695
+ if (lexer->lookahead == '|') {
1696
+ return scan_getline_pipe(lexer, valid_symbols, recovering);
1697
+ }
1698
+ if (recovering) {
1699
+ return false;
691
1700
  }
692
1701
  if (lexer->lookahead == '/') {
693
1702
  return scan_slash_start(state, lexer, valid_symbols);
694
1703
  }
695
- return scan_operator(lexer, valid_symbols);
1704
+ return scan_sign(lexer, valid_symbols);
696
1705
  }