@konomanoasa/tree-sitter-posix-awk 0.20.0 → 0.20.1
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/Cargo.toml +2 -2
- package/README.md +2 -0
- package/grammar.js +29 -33
- package/package.json +7 -7
- package/src/parser.c +1 -1
- package/src/scanner.c +47 -77
- package/tree-sitter.json +1 -1
package/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "konomanoasa-tree-sitter-posix-awk"
|
|
3
|
-
version = "0.20.
|
|
3
|
+
version = "0.20.1"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
description = "Tree-sitter grammar for POSIX awk."
|
|
6
6
|
readme = "README.md"
|
|
@@ -30,7 +30,7 @@ path = "test/bindings.test.rs"
|
|
|
30
30
|
tree-sitter-language = "0.1.8"
|
|
31
31
|
|
|
32
32
|
[dev-dependencies]
|
|
33
|
-
tree-sitter = "0.27.
|
|
33
|
+
tree-sitter = "0.27.1"
|
|
34
34
|
|
|
35
35
|
[build-dependencies]
|
|
36
36
|
cc = "1.4"
|
package/README.md
CHANGED
package/grammar.js
CHANGED
|
@@ -75,6 +75,18 @@ const continuationMarker = () => token.immediate("\\");
|
|
|
75
75
|
const signOperator = ($, character) =>
|
|
76
76
|
alias(character === "+" ? $._plus_operator : $._minus_operator, character);
|
|
77
77
|
|
|
78
|
+
const prefixOperator = ($, unary) =>
|
|
79
|
+
field(
|
|
80
|
+
"operator",
|
|
81
|
+
unary
|
|
82
|
+
? choice(signOperator($, "+"), signOperator($, "-"))
|
|
83
|
+
: alias($._not_operator, "!"),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const updateOperator = ($) => field("operator", choice($.incr, $.decr));
|
|
87
|
+
|
|
88
|
+
const fieldOperator = ($) => field("operator", alias($._field_operator, "$"));
|
|
89
|
+
|
|
78
90
|
const assignmentOperator = ($) =>
|
|
79
91
|
choice(
|
|
80
92
|
"=",
|
|
@@ -339,12 +351,7 @@ for (const print of [false, true]) {
|
|
|
339
351
|
choice(
|
|
340
352
|
seq(
|
|
341
353
|
$._select_prefix,
|
|
342
|
-
|
|
343
|
-
"operator",
|
|
344
|
-
unary
|
|
345
|
-
? choice(signOperator($, "+"), signOperator($, "-"))
|
|
346
|
-
: alias($._not_operator, "!"),
|
|
347
|
-
),
|
|
354
|
+
prefixOperator($, unary),
|
|
348
355
|
field("operand", expr($)),
|
|
349
356
|
),
|
|
350
357
|
seq(
|
|
@@ -411,11 +418,11 @@ for (const print of [false, true]) {
|
|
|
411
418
|
seq(
|
|
412
419
|
$._select_postfix,
|
|
413
420
|
field("operand", $._child_lvalue),
|
|
414
|
-
|
|
421
|
+
updateOperator($),
|
|
415
422
|
),
|
|
416
423
|
seq(
|
|
417
424
|
$._select_prefix,
|
|
418
|
-
|
|
425
|
+
updateOperator($),
|
|
419
426
|
field("operand", $._child_lvalue),
|
|
420
427
|
),
|
|
421
428
|
seq(
|
|
@@ -450,11 +457,7 @@ Object.assign(boundaryRules, {
|
|
|
450
457
|
alias($._boundary_arguments, $.expr_list),
|
|
451
458
|
"]",
|
|
452
459
|
),
|
|
453
|
-
seq(
|
|
454
|
-
$._select_field,
|
|
455
|
-
field("operator", alias($._field_operator, "$")),
|
|
456
|
-
field("operand", $._child_expr),
|
|
457
|
-
),
|
|
460
|
+
seq($._select_field, fieldOperator($), field("operand", $._child_expr)),
|
|
458
461
|
),
|
|
459
462
|
_boundary_arguments: ($) =>
|
|
460
463
|
choice(
|
|
@@ -503,6 +506,10 @@ Object.assign(boundaryRules, {
|
|
|
503
506
|
|
|
504
507
|
const localRules = {};
|
|
505
508
|
const localNode = ($, name) => alias($[`local_${name}`], $[name]);
|
|
509
|
+
const localSubscriptable = ($) =>
|
|
510
|
+
seq($.name, optional(seq("[", localNode($, "expr_list"), "]")));
|
|
511
|
+
const localPrefixUpdate = ($) =>
|
|
512
|
+
seq(updateOperator($), field("operand", localNode($, "lvalue")));
|
|
506
513
|
const localAtoms = ($, print, lvalue = localNode($, "lvalue")) =>
|
|
507
514
|
choice(
|
|
508
515
|
$._local_atom,
|
|
@@ -596,12 +603,7 @@ for (const print of [false, true]) {
|
|
|
596
603
|
const operand = any(name);
|
|
597
604
|
return ($) => [
|
|
598
605
|
seq(
|
|
599
|
-
|
|
600
|
-
"operator",
|
|
601
|
-
classification === "unary"
|
|
602
|
-
? choice(signOperator($, "+"), signOperator($, "-"))
|
|
603
|
-
: alias($._not_operator, "!"),
|
|
604
|
-
),
|
|
606
|
+
prefixOperator($, classification === "unary"),
|
|
605
607
|
field("operand", operand($)),
|
|
606
608
|
),
|
|
607
609
|
];
|
|
@@ -610,12 +612,9 @@ for (const print of [false, true]) {
|
|
|
610
612
|
return ($) => [
|
|
611
613
|
seq(
|
|
612
614
|
field("operand", alias($.local_postfix_lvalue, $.lvalue)),
|
|
613
|
-
|
|
614
|
-
),
|
|
615
|
-
seq(
|
|
616
|
-
field("operator", choice($.incr, $.decr)),
|
|
617
|
-
field("operand", localNode($, "lvalue")),
|
|
615
|
+
updateOperator($),
|
|
618
616
|
),
|
|
617
|
+
localPrefixUpdate($),
|
|
619
618
|
];
|
|
620
619
|
}
|
|
621
620
|
const left = member(
|
|
@@ -693,9 +692,9 @@ Object.assign(localRules, {
|
|
|
693
692
|
),
|
|
694
693
|
local_lvalue: ($) =>
|
|
695
694
|
choice(
|
|
696
|
-
|
|
695
|
+
localSubscriptable($),
|
|
697
696
|
seq(
|
|
698
|
-
|
|
697
|
+
fieldOperator($),
|
|
699
698
|
field("operand", alias($.local_field_expr, $.expr)),
|
|
700
699
|
),
|
|
701
700
|
),
|
|
@@ -703,9 +702,9 @@ Object.assign(localRules, {
|
|
|
703
702
|
prec(
|
|
704
703
|
1,
|
|
705
704
|
choice(
|
|
706
|
-
|
|
705
|
+
localSubscriptable($),
|
|
707
706
|
seq(
|
|
708
|
-
|
|
707
|
+
fieldOperator($),
|
|
709
708
|
field("operand", alias($.local_postfix_field_expr, $.expr)),
|
|
710
709
|
),
|
|
711
710
|
),
|
|
@@ -723,13 +722,10 @@ Object.assign(localRules, {
|
|
|
723
722
|
choice(
|
|
724
723
|
$._local_non_unary_atom,
|
|
725
724
|
seq(
|
|
726
|
-
|
|
725
|
+
prefixOperator($, false),
|
|
727
726
|
field("operand", alias($.local_unary, $.expr)),
|
|
728
727
|
),
|
|
729
|
-
|
|
730
|
-
field("operator", choice($.incr, $.decr)),
|
|
731
|
-
field("operand", localNode($, "lvalue")),
|
|
732
|
-
),
|
|
728
|
+
localPrefixUpdate($),
|
|
733
729
|
),
|
|
734
730
|
local_expr_list: ($) =>
|
|
735
731
|
choice(localNode($, "expr"), localNode($, "multiple_expr_list")),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konomanoasa/tree-sitter-posix-awk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tree-sitter grammar for POSIX awk.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
"check:queries": "npm run tree-sitter -- check-queries",
|
|
26
26
|
"format": "biome format --write .",
|
|
27
27
|
"generate": "npm run tree-sitter -- generate-all",
|
|
28
|
-
"test": "npm run tree-sitter -- test-corpus --rebuild && node --test --test-concurrency=1 --test-skip-pattern=\"posix_awk: stress:\"
|
|
28
|
+
"test": "npm run tree-sitter -- test-corpus --rebuild && node --test --test-concurrency=1 --test-skip-pattern=\"posix_awk: stress:\" test/build.test.js test/cst.test.js test/highlight.test.js test/incremental.test.js test/parser.test.js",
|
|
29
29
|
"test:fuzz": "node --test --test-name-pattern=\"fixed-seed generated histories\" test/incremental.test.js",
|
|
30
30
|
"test:fuzz:corpus": "npm run tree-sitter -- fuzz-all --iterations 100 --edits 5",
|
|
31
31
|
"test:highlights": "node --test test/highlight.test.js",
|
|
32
32
|
"test:incremental": "node --test --test-concurrency=1 test/cst.test.js test/parser.test.js test/incremental.test.js",
|
|
33
|
-
"test:performance": "node --test
|
|
33
|
+
"test:performance": "node --test test/performance.test.js",
|
|
34
34
|
"test:sanitize": "node scripts/check-c.js --sanitize",
|
|
35
35
|
"test:scanner": "node scripts/check-c.js",
|
|
36
|
-
"test:stress": "node --test --test-name-pattern=\"posix_awk: stress:\" test/
|
|
36
|
+
"test:stress": "node --test --test-name-pattern=\"posix_awk: stress:\" test/parser.test.js",
|
|
37
37
|
"tree-sitter": "node scripts/tree-sitter.js"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@biomejs/biome": "2.5.
|
|
41
|
-
"@types/node": "26.5
|
|
42
|
-
"tree-sitter-cli": "0.27.
|
|
40
|
+
"@biomejs/biome": "2.5.15",
|
|
41
|
+
"@types/node": "26.6.5",
|
|
42
|
+
"tree-sitter-cli": "0.27.1",
|
|
43
43
|
"typescript": "7.0.2"
|
|
44
44
|
},
|
|
45
45
|
"allowScripts": {
|
package/src/parser.c
CHANGED
|
@@ -65894,7 +65894,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_posix_awk(void) {
|
|
|
65894
65894
|
.metadata = {
|
|
65895
65895
|
.major_version = 0,
|
|
65896
65896
|
.minor_version = 20,
|
|
65897
|
-
.patch_version =
|
|
65897
|
+
.patch_version = 1,
|
|
65898
65898
|
},
|
|
65899
65899
|
};
|
|
65900
65900
|
return &language;
|
package/src/scanner.c
CHANGED
|
@@ -169,6 +169,7 @@ typedef struct {
|
|
|
169
169
|
|
|
170
170
|
#define SAVE_FIRST SAVE_0
|
|
171
171
|
#define RESTORE_FIRST RESTORE_0
|
|
172
|
+
enum { SAVED_DIGITS = RESTORE_FIRST - SAVE_FIRST };
|
|
172
173
|
// BEGIN generated reserved words from grammar.js.
|
|
173
174
|
enum {
|
|
174
175
|
MAX_RESERVED_WORD_LENGTH = 8,
|
|
@@ -736,7 +737,7 @@ static bool skip_group(TSLexer *lexer, bool *tuple) {
|
|
|
736
737
|
depth--;
|
|
737
738
|
after_operand = true;
|
|
738
739
|
} else if (character_in(character, "+-") && lexer->lookahead == character) {
|
|
739
|
-
//
|
|
740
|
+
// Updates require lvalues, so a following slash divides.
|
|
740
741
|
lexer->advance(lexer, false);
|
|
741
742
|
after_operand = true;
|
|
742
743
|
} else if (character_in(character, "&|") && lexer->lookahead == character) {
|
|
@@ -744,6 +745,8 @@ static bool skip_group(TSLexer *lexer, bool *tuple) {
|
|
|
744
745
|
after_operand = false;
|
|
745
746
|
separated = true;
|
|
746
747
|
} else {
|
|
748
|
+
if (character == '{' || character == '}' || character == ';')
|
|
749
|
+
return false;
|
|
747
750
|
after_operand = is_word_continue(character) || character == '.';
|
|
748
751
|
separated = character == ',';
|
|
749
752
|
}
|
|
@@ -762,7 +765,7 @@ static WordAtom word_atom(TSLexer *lexer, WordKind word) {
|
|
|
762
765
|
return ATOM_PLAIN;
|
|
763
766
|
}
|
|
764
767
|
|
|
765
|
-
//
|
|
768
|
+
// Restoring the probe must preserve furthest lookahead.
|
|
766
769
|
typedef struct {
|
|
767
770
|
TSLexer lexer;
|
|
768
771
|
TSLexer *source;
|
|
@@ -1009,13 +1012,6 @@ static int probe_precedence(int token) {
|
|
|
1009
1012
|
}
|
|
1010
1013
|
}
|
|
1011
1014
|
|
|
1012
|
-
typedef struct {
|
|
1013
|
-
size_t end;
|
|
1014
|
-
int ceiling, kind;
|
|
1015
|
-
bool lvalue, postfix, unary;
|
|
1016
|
-
uint64_t children[2];
|
|
1017
|
-
} RecognizedExpression;
|
|
1018
|
-
|
|
1019
1015
|
typedef struct {
|
|
1020
1016
|
int *tokens;
|
|
1021
1017
|
size_t length, capacity;
|
|
@@ -1081,7 +1077,6 @@ static int descriptor_kind(uint64_t descriptor) {
|
|
|
1081
1077
|
return signature_kind(descriptor_signature(descriptor));
|
|
1082
1078
|
}
|
|
1083
1079
|
|
|
1084
|
-
// Store the short signature in low bits to reduce base-4 stack digits.
|
|
1085
1080
|
enum { SAVED_SIGNATURE_BITS = 17 };
|
|
1086
1081
|
static const uint64_t SAVED_SIGNATURE_MASK =
|
|
1087
1082
|
(UINT64_C(1) << SAVED_SIGNATURE_BITS) - 1;
|
|
@@ -1101,19 +1096,6 @@ static uint64_t restored_descriptor(uint64_t saved) {
|
|
|
1101
1096
|
);
|
|
1102
1097
|
}
|
|
1103
1098
|
|
|
1104
|
-
static RecognizedExpression outline_expression(BoundaryOutline outline) {
|
|
1105
|
-
const uint32_t signature = descriptor_signature(outline.descriptor);
|
|
1106
|
-
return (RecognizedExpression){
|
|
1107
|
-
.end = descriptor_length(outline.descriptor),
|
|
1108
|
-
.kind = descriptor_kind(outline.descriptor),
|
|
1109
|
-
.ceiling = signature_ceiling(signature),
|
|
1110
|
-
.lvalue = signature & SIGNATURE_LVALUE,
|
|
1111
|
-
.postfix = signature & SIGNATURE_POSTFIX,
|
|
1112
|
-
.unary = signature & SIGNATURE_UNARY,
|
|
1113
|
-
.children = {outline.children[0], outline.children[1]},
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
1099
|
static void recognizer_destroy(RecognizerInput *parser) {
|
|
1118
1100
|
ts_free(parser->tokens);
|
|
1119
1101
|
ts_free(parser->tree);
|
|
@@ -1669,10 +1651,6 @@ static void recognizer_step(Recognizer *parser) {
|
|
|
1669
1651
|
frame->stage = RECOGNIZER_BINARY;
|
|
1670
1652
|
break;
|
|
1671
1653
|
case RECOGNIZER_BINARY: {
|
|
1672
|
-
if (frame->precedence == EXPR_CONCATENATION && parser->value.unary) {
|
|
1673
|
-
parser->valid = false;
|
|
1674
|
-
break;
|
|
1675
|
-
}
|
|
1676
1654
|
const bool unary = frame->left.unary;
|
|
1677
1655
|
frame->left = recognizer_node(
|
|
1678
1656
|
parser,
|
|
@@ -2144,11 +2122,6 @@ shared_compute(SharedRecognition *parser, uint32_t start, int minimum) {
|
|
|
2144
2122
|
for (size_t i = 0; i < rights->length && !parser->failed; i++) {
|
|
2145
2123
|
const uint32_t right = rights->items[i];
|
|
2146
2124
|
const SharedNode child = parser->nodes[right - 1];
|
|
2147
|
-
if (
|
|
2148
|
-
next.precedence == EXPR_CONCATENATION &&
|
|
2149
|
-
(shared_shape(child) & SIGNATURE_UNARY)
|
|
2150
|
-
)
|
|
2151
|
-
continue;
|
|
2152
2125
|
shared_add(
|
|
2153
2126
|
parser,
|
|
2154
2127
|
&work,
|
|
@@ -2359,7 +2332,7 @@ static bool recognizer_parse(RecognizerInput *input) {
|
|
|
2359
2332
|
size_t position = input->length;
|
|
2360
2333
|
while (position && !parser.alternatives[position - 1]) position--;
|
|
2361
2334
|
if (!position) break;
|
|
2362
|
-
// Only positions
|
|
2335
|
+
// Only positions beyond the backtrack point are exhausted.
|
|
2363
2336
|
for (size_t i = 0; i < parser.history_count; i++) {
|
|
2364
2337
|
if (parser.history[i].position > position - 1)
|
|
2365
2338
|
recognizer_failed(&parser, parser.history[i], true);
|
|
@@ -2399,7 +2372,11 @@ boundary_emit(TSLexer *lexer, BoundaryState *state, unsigned token) {
|
|
|
2399
2372
|
return true;
|
|
2400
2373
|
}
|
|
2401
2374
|
|
|
2402
|
-
|
|
2375
|
+
static void cache_clear(BoundaryState *state) {
|
|
2376
|
+
state->cache_count = state->cache_index = state->cache_repeats =
|
|
2377
|
+
state->cache_delta = 0;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2403
2380
|
enum {
|
|
2404
2381
|
SHIFT_DESCRIPTOR = 1,
|
|
2405
2382
|
SHIFT_LEFT = 2,
|
|
@@ -2535,8 +2512,7 @@ static bool cache_period(
|
|
|
2535
2512
|
|
|
2536
2513
|
static void
|
|
2537
2514
|
cache_boundary(BoundaryState *state, const RecognizerInput *parser) {
|
|
2538
|
-
state
|
|
2539
|
-
state->cache_delta = 0;
|
|
2515
|
+
cache_clear(state);
|
|
2540
2516
|
if (!BOUNDARY_CACHE_CAPACITY || !parser->tree_root) return;
|
|
2541
2517
|
if (parser->tree_count > SIZE_MAX / 2 / sizeof(size_t) - 1) return;
|
|
2542
2518
|
size_t *order = ts_calloc(parser->tree_count * 2 + 2, sizeof(*order));
|
|
@@ -2576,17 +2552,13 @@ cache_boundary(BoundaryState *state, const RecognizerInput *parser) {
|
|
|
2576
2552
|
ts_free(order);
|
|
2577
2553
|
}
|
|
2578
2554
|
|
|
2579
|
-
static bool
|
|
2580
|
-
|
|
2581
|
-
uint64_t requested,
|
|
2582
|
-
RecognizedExpression *node
|
|
2583
|
-
) {
|
|
2555
|
+
static bool
|
|
2556
|
+
take_boundary(BoundaryState *state, uint64_t requested, BoundaryOutline *node) {
|
|
2584
2557
|
if (
|
|
2585
2558
|
!state->cache_count ||
|
|
2586
2559
|
state->cache[state->cache_index].descriptor != requested
|
|
2587
2560
|
) {
|
|
2588
|
-
state
|
|
2589
|
-
state->cache_delta = 0;
|
|
2561
|
+
cache_clear(state);
|
|
2590
2562
|
return false;
|
|
2591
2563
|
}
|
|
2592
2564
|
BoundaryOutline outline = state->cache[state->cache_index];
|
|
@@ -2603,7 +2575,7 @@ static bool take_boundary(
|
|
|
2603
2575
|
if (cached->repeat & SHIFT_RIGHT)
|
|
2604
2576
|
cached->children[1] -= state->cache_delta;
|
|
2605
2577
|
}
|
|
2606
|
-
} else state
|
|
2578
|
+
} else cache_clear(state);
|
|
2607
2579
|
}
|
|
2608
2580
|
} else if (--state->cache[0].repeat) {
|
|
2609
2581
|
uint32_t delta = descriptor_length(outline.descriptor) -
|
|
@@ -2618,7 +2590,7 @@ static bool take_boundary(
|
|
|
2618
2590
|
state->cache_count * sizeof(*state->cache)
|
|
2619
2591
|
);
|
|
2620
2592
|
}
|
|
2621
|
-
*node =
|
|
2593
|
+
*node = outline;
|
|
2622
2594
|
return true;
|
|
2623
2595
|
}
|
|
2624
2596
|
|
|
@@ -2635,7 +2607,7 @@ static void collect_expression(
|
|
|
2635
2607
|
const int token = probe_token(input, expect_operand);
|
|
2636
2608
|
if (
|
|
2637
2609
|
!token ||
|
|
2638
|
-
character_in(token, "\n;,)
|
|
2610
|
+
character_in(token, "\n;,)]}{#") ||
|
|
2639
2611
|
(token == ':' && !questions && !branches) ||
|
|
2640
2612
|
(print && !count && !questions && (token == '>' || token == '|'))
|
|
2641
2613
|
)
|
|
@@ -2672,11 +2644,12 @@ atom_token(InputProbe *input, BoundaryState *state, bool lvalue) {
|
|
|
2672
2644
|
}
|
|
2673
2645
|
|
|
2674
2646
|
static unsigned selection_token(
|
|
2675
|
-
|
|
2647
|
+
BoundaryOutline selected,
|
|
2676
2648
|
InputProbe *input,
|
|
2677
2649
|
BoundaryState *state
|
|
2678
2650
|
) {
|
|
2679
|
-
|
|
2651
|
+
const uint32_t signature = descriptor_signature(selected.descriptor);
|
|
2652
|
+
switch (signature_kind(signature)) {
|
|
2680
2653
|
case RECOGNIZED_GET:
|
|
2681
2654
|
return selected.children[0] ? SELECT_TARGET_GET : SELECT_GET;
|
|
2682
2655
|
case RECOGNIZED_FILE:
|
|
@@ -2691,7 +2664,7 @@ static unsigned selection_token(
|
|
|
2691
2664
|
return SELECT_CONCAT;
|
|
2692
2665
|
case RECOGNIZED_TUPLE:
|
|
2693
2666
|
case 0:
|
|
2694
|
-
return atom_token(input, state,
|
|
2667
|
+
return atom_token(input, state, signature & SIGNATURE_LVALUE);
|
|
2695
2668
|
case RECOGNIZED_BRANCHES:
|
|
2696
2669
|
return SELECT_BRANCHES;
|
|
2697
2670
|
case '?':
|
|
@@ -2718,7 +2691,7 @@ static bool select_boundary(TSLexer *lexer, BoundaryState *state) {
|
|
|
2718
2691
|
RecognizerInput parser = {
|
|
2719
2692
|
.expected = requested == UNCONSTRAINED ? 0 : descriptor_signature(requested)
|
|
2720
2693
|
};
|
|
2721
|
-
|
|
2694
|
+
BoundaryOutline selected = {0};
|
|
2722
2695
|
if (!take_boundary(state, requested, &selected)) {
|
|
2723
2696
|
collect_expression(&input, &parser, count, state->print);
|
|
2724
2697
|
if (
|
|
@@ -2728,15 +2701,14 @@ static bool select_boundary(TSLexer *lexer, BoundaryState *state) {
|
|
|
2728
2701
|
!parser.failed &&
|
|
2729
2702
|
recognizer_parse(&parser)
|
|
2730
2703
|
) {
|
|
2731
|
-
|
|
2732
|
-
selected = outline_expression(root);
|
|
2704
|
+
selected = parser.tree[parser.tree_root - 1].outline;
|
|
2733
2705
|
cache_boundary(state, &parser);
|
|
2734
|
-
take_boundary(state,
|
|
2706
|
+
take_boundary(state, selected.descriptor, &selected);
|
|
2735
2707
|
}
|
|
2736
2708
|
}
|
|
2737
2709
|
unsigned token = ERROR_SENTINEL;
|
|
2738
|
-
if (selected.
|
|
2739
|
-
state->unary = selected.
|
|
2710
|
+
if (descriptor_length(selected.descriptor)) {
|
|
2711
|
+
state->unary = descriptor_signature(selected.descriptor) & SIGNATURE_UNARY;
|
|
2740
2712
|
state->pending[0] = selected.children[0];
|
|
2741
2713
|
state->pending[1] = selected.children[1];
|
|
2742
2714
|
token = selection_token(selected, &input, state);
|
|
@@ -2748,13 +2720,22 @@ static bool select_boundary(TSLexer *lexer, BoundaryState *state) {
|
|
|
2748
2720
|
return token != ERROR_SENTINEL;
|
|
2749
2721
|
}
|
|
2750
2722
|
|
|
2751
|
-
// Close children before trailing blanks to preserve enclosing node ranges.
|
|
2752
2723
|
static bool restoring_requested(const bool *valid) {
|
|
2753
2724
|
bool restoring = valid[END_CHILD] || valid[RESUME];
|
|
2754
|
-
for (unsigned
|
|
2725
|
+
for (unsigned digit = 0; digit < SAVED_DIGITS; digit++)
|
|
2726
|
+
restoring |= valid[RESTORE_FIRST + digit];
|
|
2755
2727
|
return restoring;
|
|
2756
2728
|
}
|
|
2757
2729
|
|
|
2730
|
+
static bool root_requested(const bool *valid) {
|
|
2731
|
+
return valid[ROOT] ||
|
|
2732
|
+
valid[PRINT_ROOT] ||
|
|
2733
|
+
valid[FOR_IN] ||
|
|
2734
|
+
valid[PRINT_ARGUMENTS] ||
|
|
2735
|
+
valid[LOCAL_ROOT] ||
|
|
2736
|
+
valid[LOCAL_PRINT_ROOT];
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2758
2739
|
static bool boundary_requested(const bool *valid) {
|
|
2759
2740
|
for (unsigned i = ROOT; i <= LOCAL_PRINT_ROOT; i++)
|
|
2760
2741
|
if (valid[i]) return true;
|
|
@@ -2874,7 +2855,7 @@ static unsigned root_token(InputProbe *probe, const bool *valid) {
|
|
|
2874
2855
|
(!valid[ROOT] && !valid[LOCAL_ROOT] && !print) ||
|
|
2875
2856
|
(print && (first == '>' || first == '|')) ||
|
|
2876
2857
|
!first ||
|
|
2877
|
-
character_in(first, "\n;,)
|
|
2858
|
+
character_in(first, "\n;,)]}{:#")
|
|
2878
2859
|
)
|
|
2879
2860
|
return ERROR_SENTINEL;
|
|
2880
2861
|
if (local) return print ? LOCAL_PRINT_ROOT : LOCAL_ROOT;
|
|
@@ -2898,18 +2879,9 @@ static bool scan_root(TSLexer *lexer, BoundaryState *state, const bool *valid) {
|
|
|
2898
2879
|
static bool
|
|
2899
2880
|
scan_boundary(TSLexer *lexer, BoundaryState *state, const bool *valid) {
|
|
2900
2881
|
lexer->mark_end(lexer);
|
|
2901
|
-
if (valid[NEXT_ARGUMENT] || valid[BEGIN_CHILD])
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
if (
|
|
2905
|
-
valid[ROOT] ||
|
|
2906
|
-
valid[PRINT_ROOT] ||
|
|
2907
|
-
valid[FOR_IN] ||
|
|
2908
|
-
valid[PRINT_ARGUMENTS] ||
|
|
2909
|
-
valid[LOCAL_ROOT] ||
|
|
2910
|
-
valid[LOCAL_PRINT_ROOT]
|
|
2911
|
-
)
|
|
2912
|
-
return scan_root(lexer, state, valid);
|
|
2882
|
+
if ((valid[NEXT_ARGUMENT] || valid[BEGIN_CHILD]) && lexer->lookahead == '\n')
|
|
2883
|
+
return false;
|
|
2884
|
+
if (root_requested(valid)) return scan_root(lexer, state, valid);
|
|
2913
2885
|
if (valid[NEXT_ARGUMENT]) {
|
|
2914
2886
|
state->pending[0] = UNCONSTRAINED;
|
|
2915
2887
|
return boundary_emit(lexer, state, NEXT_ARGUMENT);
|
|
@@ -2925,9 +2897,9 @@ scan_boundary(TSLexer *lexer, BoundaryState *state, const bool *valid) {
|
|
|
2925
2897
|
boundary_reset(state, 0, BOUNDARY_RESTORING);
|
|
2926
2898
|
return boundary_emit(lexer, state, END_CHILD);
|
|
2927
2899
|
}
|
|
2928
|
-
for (unsigned digit = 0; digit <
|
|
2900
|
+
for (unsigned digit = 0; digit < SAVED_DIGITS; digit++)
|
|
2929
2901
|
if (valid[RESTORE_FIRST + digit]) {
|
|
2930
|
-
state->carry = state->carry *
|
|
2902
|
+
state->carry = state->carry * SAVED_DIGITS + digit;
|
|
2931
2903
|
return boundary_emit(lexer, state, RESTORE_FIRST + digit);
|
|
2932
2904
|
}
|
|
2933
2905
|
if (valid[BEGIN_CHILD]) {
|
|
@@ -2938,15 +2910,13 @@ scan_boundary(TSLexer *lexer, BoundaryState *state, const bool *valid) {
|
|
|
2938
2910
|
state->phase = BOUNDARY_SAVING;
|
|
2939
2911
|
}
|
|
2940
2912
|
if (state->carry) {
|
|
2941
|
-
unsigned digit = state->carry
|
|
2942
|
-
state->carry
|
|
2913
|
+
const unsigned digit = state->carry % SAVED_DIGITS;
|
|
2914
|
+
state->carry /= SAVED_DIGITS;
|
|
2943
2915
|
return boundary_emit(lexer, state, SAVE_FIRST + digit);
|
|
2944
2916
|
}
|
|
2945
2917
|
uint64_t active = state->next;
|
|
2946
2918
|
boundary_reset(state, active, BOUNDARY_READY);
|
|
2947
|
-
if (active == UNCONSTRAINED)
|
|
2948
|
-
state->cache_count = state->cache_index = state->cache_repeats =
|
|
2949
|
-
state->cache_delta = 0;
|
|
2919
|
+
if (active == UNCONSTRAINED) cache_clear(state);
|
|
2950
2920
|
return boundary_emit(lexer, state, BEGIN_CHILD);
|
|
2951
2921
|
}
|
|
2952
2922
|
if (state->active && !select_boundary(lexer, state)) return false;
|