@konomanoasa/tree-sitter-diagnostic-sh 0.8.0 → 0.8.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 +1 -1
- package/PARSING_POLICY.md +7 -9
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/parser.c +1 -1
- package/src/scanner.c +111 -92
- package/tree-sitter.json +1 -1
package/Cargo.toml
CHANGED
package/PARSING_POLICY.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# Parsing Policy
|
|
2
2
|
|
|
3
|
-
The parser
|
|
4
|
-
optional features
|
|
5
|
-
|
|
6
|
-
follows [dash 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html). Explicit POSIX requirements take precedence.
|
|
3
|
+
The parser follows [POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html)
|
|
4
|
+
mandatory syntax, excluding optional features and extensions. Syntax not
|
|
5
|
+
determined by POSIX follows [dash 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html).
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
recognizes these commands but does not apply their effects.
|
|
7
|
+
These commands are parsed without changing how subsequent source is parsed.
|
|
10
8
|
|
|
11
|
-
| Command | Effects not applied
|
|
12
|
-
| ------------------ |
|
|
13
|
-
| `alias`, `unalias` | Alias substitution
|
|
9
|
+
| Command | Effects not applied |
|
|
10
|
+
| ------------------ | ----------------------------------- |
|
|
11
|
+
| `alias`, `unalias` | Alias substitution and definitions. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konomanoasa/tree-sitter-diagnostic-sh",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Tree-sitter grammar for diagnostics of POSIX sh.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git+https://github.com/konomanoasa/tree-sitter-diagnostic-sh.git",
|
package/pyproject.toml
CHANGED
package/src/parser.c
CHANGED
|
@@ -15226,7 +15226,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_diagnostic_sh(void) {
|
|
|
15226
15226
|
.metadata = {
|
|
15227
15227
|
.major_version = 0,
|
|
15228
15228
|
.minor_version = 8,
|
|
15229
|
-
.patch_version =
|
|
15229
|
+
.patch_version = 1,
|
|
15230
15230
|
},
|
|
15231
15231
|
};
|
|
15232
15232
|
return &language;
|
package/src/scanner.c
CHANGED
|
@@ -104,7 +104,6 @@ struct Parser {
|
|
|
104
104
|
uint32_t stops;
|
|
105
105
|
bool resumed;
|
|
106
106
|
size_t backquote_end;
|
|
107
|
-
int32_t closer;
|
|
108
107
|
};
|
|
109
108
|
struct Scanner {
|
|
110
109
|
struct Event *events;
|
|
@@ -1427,8 +1426,7 @@ static size_t consumed_offset(const struct Input *input) {
|
|
|
1427
1426
|
static struct Unit read_raw(struct Input *input) {
|
|
1428
1427
|
if (input->position >= input->count)
|
|
1429
1428
|
return (struct Unit){-1, input->end, input->end};
|
|
1430
|
-
|
|
1431
|
-
return unit;
|
|
1429
|
+
return input->units[input->position++];
|
|
1432
1430
|
}
|
|
1433
1431
|
|
|
1434
1432
|
static struct Unit pop(struct Input *input) {
|
|
@@ -1752,8 +1750,6 @@ static void quoted(struct Parser *parser, struct Text *text, int32_t quote) {
|
|
|
1752
1750
|
literal ? BEGIN_SINGLE_QUOTED : BEGIN_DOUBLE_QUOTED,
|
|
1753
1751
|
offset(input)
|
|
1754
1752
|
);
|
|
1755
|
-
int32_t parent_closer = parser->closer;
|
|
1756
|
-
parser->closer = quote;
|
|
1757
1753
|
pop(input);
|
|
1758
1754
|
while (!parser->plan->failed) {
|
|
1759
1755
|
int32_t c = peek_quoted(input, literal);
|
|
@@ -1778,7 +1774,6 @@ static void quoted(struct Parser *parser, struct Text *text, int32_t quote) {
|
|
|
1778
1774
|
if (literal || c != '\\' || !double_quote_escape(parser, text, unit))
|
|
1779
1775
|
text_push(parser, text, unit);
|
|
1780
1776
|
}
|
|
1781
|
-
parser->closer = parent_closer;
|
|
1782
1777
|
owner_end(parser, owner, consumed_offset(input));
|
|
1783
1778
|
unnest(parser);
|
|
1784
1779
|
}
|
|
@@ -1864,9 +1859,8 @@ static void parameter_operator(
|
|
|
1864
1859
|
|
|
1865
1860
|
static struct ParameterHead parameter_head(struct Parser *parser) {
|
|
1866
1861
|
struct Input *input = &parser->input;
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
head.fault.end = head.fault.at;
|
|
1862
|
+
size_t at = offset(input);
|
|
1863
|
+
struct ParameterHead head = {{TOKEN_TYPE_COUNT, at, at, 0}, false, false};
|
|
1870
1864
|
bool hash = peek(input) == '#';
|
|
1871
1865
|
bool length = hash && length_operator(input);
|
|
1872
1866
|
if (length) pop(input);
|
|
@@ -1926,8 +1920,6 @@ parameter_word(struct Parser *parser, bool double_quoted, struct Fault *fault) {
|
|
|
1926
1920
|
static void parameter(struct Parser *parser, bool double_quoted) {
|
|
1927
1921
|
struct Input *input = &parser->input;
|
|
1928
1922
|
pop(input);
|
|
1929
|
-
int32_t parent_closer = parser->closer;
|
|
1930
|
-
parser->closer = '}';
|
|
1931
1923
|
struct ParameterHead head = parameter_head(parser);
|
|
1932
1924
|
struct Fault fault = head.fault;
|
|
1933
1925
|
if (head.operand && head.pattern) double_quoted = false;
|
|
@@ -1952,7 +1944,6 @@ static void parameter(struct Parser *parser, bool double_quoted) {
|
|
|
1952
1944
|
if (peek(input) == '}') pop(input);
|
|
1953
1945
|
else if (fault.kind == TOKEN_TYPE_COUNT)
|
|
1954
1946
|
input_end_gap(parser, PARAMETER_ENDING_GAP);
|
|
1955
|
-
parser->closer = parent_closer;
|
|
1956
1947
|
}
|
|
1957
1948
|
|
|
1958
1949
|
static int hex_value(int32_t c) {
|
|
@@ -2043,7 +2034,8 @@ read_dollar_escape(struct Input *input, struct Unit slash) {
|
|
|
2043
2034
|
read_raw(input);
|
|
2044
2035
|
if (c == '\\') read_raw(input);
|
|
2045
2036
|
escape.count = encode_value(c, escape.bytes);
|
|
2046
|
-
escape.bytes[0] =
|
|
2037
|
+
escape.bytes[0] = escape.bytes[0] < 0x40 ? escape.bytes[0] | 0x40
|
|
2038
|
+
: escape.bytes[0] & 0x1f;
|
|
2047
2039
|
}
|
|
2048
2040
|
} else {
|
|
2049
2041
|
const char *keys = "abefnrtv\"'\\";
|
|
@@ -2101,14 +2093,14 @@ static void dollar_quote(struct Parser *parser, struct Text *text) {
|
|
|
2101
2093
|
|
|
2102
2094
|
struct BackquoteInput {
|
|
2103
2095
|
struct Input *input;
|
|
2104
|
-
bool
|
|
2096
|
+
bool literal_next;
|
|
2105
2097
|
};
|
|
2106
2098
|
|
|
2107
2099
|
static struct Unit backquote_next(struct BackquoteInput *reader) {
|
|
2108
2100
|
struct Input *input = reader->input;
|
|
2109
2101
|
while (input->position < input->count) {
|
|
2110
2102
|
struct Unit unit = input->units[input->position++];
|
|
2111
|
-
if (
|
|
2103
|
+
if (reader->literal_next) {
|
|
2112
2104
|
reader->literal_next = false;
|
|
2113
2105
|
return unit;
|
|
2114
2106
|
}
|
|
@@ -2131,7 +2123,7 @@ static size_t backquote_body(
|
|
|
2131
2123
|
size_t *end
|
|
2132
2124
|
) {
|
|
2133
2125
|
struct Input *input = &parser->input;
|
|
2134
|
-
struct BackquoteInput reader = {.input = input
|
|
2126
|
+
struct BackquoteInput reader = {.input = input};
|
|
2135
2127
|
while (!parser->plan->failed && input->position < input->count) {
|
|
2136
2128
|
struct Unit unit = backquote_next(&reader);
|
|
2137
2129
|
if (unit.value < 0) break;
|
|
@@ -2347,16 +2339,16 @@ static void expansion(
|
|
|
2347
2339
|
static void escaped_character(struct Parser *parser, struct Token *token) {
|
|
2348
2340
|
struct Input *input = &parser->input;
|
|
2349
2341
|
struct Unit slash = pop(input);
|
|
2342
|
+
bool complete = raw(input, input->position) >= 0;
|
|
2350
2343
|
if (
|
|
2351
|
-
|
|
2344
|
+
!complete &&
|
|
2352
2345
|
(parser->backquote_end || input->end == parser->plan->source_end)
|
|
2353
2346
|
) {
|
|
2354
2347
|
text_push(parser, &token->text, slash);
|
|
2355
2348
|
return;
|
|
2356
2349
|
}
|
|
2357
2350
|
size_t owner = owner_begin(parser, BEGIN_ESCAPED_CHARACTER, slash.start);
|
|
2358
|
-
if (
|
|
2359
|
-
text_push(parser, &token->text, escaped_unit(input, slash));
|
|
2351
|
+
if (complete) text_push(parser, &token->text, escaped_unit(input, slash));
|
|
2360
2352
|
else
|
|
2361
2353
|
issue(
|
|
2362
2354
|
parser,
|
|
@@ -2497,11 +2489,22 @@ static struct Fault token_fault(
|
|
|
2497
2489
|
return fault;
|
|
2498
2490
|
}
|
|
2499
2491
|
|
|
2492
|
+
static void text_bytes(
|
|
2493
|
+
struct Parser *parser,
|
|
2494
|
+
struct Text *text,
|
|
2495
|
+
const uint8_t *bytes,
|
|
2496
|
+
size_t count,
|
|
2497
|
+
size_t start,
|
|
2498
|
+
size_t end
|
|
2499
|
+
) {
|
|
2500
|
+
for (size_t i = 0; i < count; i++)
|
|
2501
|
+
text_push(parser, text, (struct Unit){bytes[i], start, end});
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2500
2504
|
static void encode(struct Parser *parser, struct Text *text, struct Unit unit) {
|
|
2501
2505
|
uint8_t bytes[4];
|
|
2502
2506
|
size_t count = encode_value(unit.value, bytes);
|
|
2503
|
-
|
|
2504
|
-
text_push(parser, text, (struct Unit){bytes[i], unit.start, unit.end});
|
|
2507
|
+
text_bytes(parser, text, bytes, count, unit.start, unit.end);
|
|
2505
2508
|
}
|
|
2506
2509
|
|
|
2507
2510
|
enum DelimiterQuote {
|
|
@@ -2547,16 +2550,19 @@ static struct DelimiterGroup *delimiter_top(struct DelimiterReader *reader) {
|
|
|
2547
2550
|
return reader->count ? &reader->groups[reader->count - 1] : NULL;
|
|
2548
2551
|
}
|
|
2549
2552
|
|
|
2553
|
+
static bool delimiter_nest(const struct DelimiterReader *reader) {
|
|
2554
|
+
struct Plan *plan = reader->parser->plan;
|
|
2555
|
+
if (plan->depth + reader->count + reader->quotes < NESTING_LIMIT) return true;
|
|
2556
|
+
plan->failed = true;
|
|
2557
|
+
return false;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2550
2560
|
static bool delimiter_push(
|
|
2551
2561
|
struct DelimiterReader *reader,
|
|
2552
2562
|
enum DelimiterGroupKind kind,
|
|
2553
2563
|
int32_t closing
|
|
2554
2564
|
) {
|
|
2555
|
-
|
|
2556
|
-
if (plan->depth + reader->count + reader->quotes >= NESTING_LIMIT) {
|
|
2557
|
-
plan->failed = true;
|
|
2558
|
-
return false;
|
|
2559
|
-
}
|
|
2565
|
+
if (!delimiter_nest(reader)) return false;
|
|
2560
2566
|
struct DelimiterGroup *grown = diagnostic_grow(
|
|
2561
2567
|
reader->groups,
|
|
2562
2568
|
&reader->capacity,
|
|
@@ -2564,7 +2570,7 @@ static bool delimiter_push(
|
|
|
2564
2570
|
sizeof(*grown)
|
|
2565
2571
|
);
|
|
2566
2572
|
if (!grown) {
|
|
2567
|
-
plan->failed = true;
|
|
2573
|
+
reader->parser->plan->failed = true;
|
|
2568
2574
|
return false;
|
|
2569
2575
|
}
|
|
2570
2576
|
reader->groups = grown;
|
|
@@ -2590,11 +2596,18 @@ static void delimiter_pop(struct DelimiterReader *reader) {
|
|
|
2590
2596
|
reader->quotes = group->quotes;
|
|
2591
2597
|
}
|
|
2592
2598
|
|
|
2599
|
+
static size_t delimiter_outer(
|
|
2600
|
+
const struct DelimiterReader *reader,
|
|
2601
|
+
enum DelimiterGroupKind skipped
|
|
2602
|
+
) {
|
|
2603
|
+
size_t depth = reader->count;
|
|
2604
|
+
while (depth && reader->groups[depth - 1].kind == skipped) depth--;
|
|
2605
|
+
return depth;
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2593
2608
|
static bool
|
|
2594
2609
|
delimiter_close(struct DelimiterReader *reader, enum DelimiterGroupKind kind) {
|
|
2595
|
-
size_t depth = reader
|
|
2596
|
-
while (depth && reader->groups[depth - 1].kind == DELIMITER_PARAMETER)
|
|
2597
|
-
depth--;
|
|
2610
|
+
size_t depth = delimiter_outer(reader, DELIMITER_PARAMETER);
|
|
2598
2611
|
if (!depth || reader->groups[depth - 1].kind != kind) return false;
|
|
2599
2612
|
delimiter_copy(reader);
|
|
2600
2613
|
while (reader->count >= depth) delimiter_pop(reader);
|
|
@@ -2605,10 +2618,7 @@ static void
|
|
|
2605
2618
|
delimiter_single_quote(struct DelimiterReader *reader, bool dollar) {
|
|
2606
2619
|
struct Parser *parser = reader->parser;
|
|
2607
2620
|
struct Input *input = &parser->input;
|
|
2608
|
-
if (
|
|
2609
|
-
parser->plan->failed = true;
|
|
2610
|
-
return;
|
|
2611
|
-
}
|
|
2621
|
+
if (!delimiter_nest(reader)) return;
|
|
2612
2622
|
reader->document.quoted = true;
|
|
2613
2623
|
pop(input);
|
|
2614
2624
|
bool terminated = false;
|
|
@@ -2627,15 +2637,18 @@ delimiter_single_quote(struct DelimiterReader *reader, bool dollar) {
|
|
|
2627
2637
|
escape.source.end,
|
|
2628
2638
|
parser->owner
|
|
2629
2639
|
};
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2640
|
+
size_t count = 0;
|
|
2641
|
+
while (count < escape.count && escape.bytes[count]) count++;
|
|
2642
|
+
if (!terminated)
|
|
2643
|
+
text_bytes(
|
|
2644
|
+
parser,
|
|
2645
|
+
&reader->document.delimiter,
|
|
2646
|
+
escape.bytes,
|
|
2647
|
+
count,
|
|
2648
|
+
unit.start,
|
|
2649
|
+
escape.source.end
|
|
2650
|
+
);
|
|
2651
|
+
if (count < escape.count) terminated = true;
|
|
2639
2652
|
} else if (!terminated) delimiter_encode(reader, unit);
|
|
2640
2653
|
}
|
|
2641
2654
|
reader->incomplete = true;
|
|
@@ -2691,12 +2704,14 @@ static void delimiter_parameter_prefix(struct DelimiterReader *reader) {
|
|
|
2691
2704
|
struct Unit unit = pop(input);
|
|
2692
2705
|
uint8_t bytes[4];
|
|
2693
2706
|
size_t length = encode_value(c, bytes);
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2707
|
+
text_bytes(
|
|
2708
|
+
reader->parser,
|
|
2709
|
+
&reader->document.delimiter,
|
|
2710
|
+
bytes + 1,
|
|
2711
|
+
length - 1,
|
|
2712
|
+
unit.start,
|
|
2713
|
+
unit.end
|
|
2714
|
+
);
|
|
2700
2715
|
return;
|
|
2701
2716
|
}
|
|
2702
2717
|
bool name = is_name_start_character(c), positional = is_decimal_digit(c);
|
|
@@ -2740,10 +2755,33 @@ static void delimiter_dollar(struct DelimiterReader *reader) {
|
|
|
2740
2755
|
}
|
|
2741
2756
|
}
|
|
2742
2757
|
|
|
2743
|
-
static
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2758
|
+
static void delimiter_double_quote(struct DelimiterReader *reader) {
|
|
2759
|
+
pop(&reader->parser->input);
|
|
2760
|
+
switch (reader->quote) {
|
|
2761
|
+
case DELIMITER_PARAMETER_QUOTED:
|
|
2762
|
+
if (delimiter_push(reader, DELIMITER_DOUBLE_QUOTE, '"'))
|
|
2763
|
+
reader->quote = DELIMITER_DOUBLE_QUOTED;
|
|
2764
|
+
break;
|
|
2765
|
+
case DELIMITER_DOUBLE_QUOTED:
|
|
2766
|
+
reader->document.quoted = true;
|
|
2767
|
+
if (
|
|
2768
|
+
reader->count && delimiter_top(reader)->kind == DELIMITER_DOUBLE_QUOTE
|
|
2769
|
+
)
|
|
2770
|
+
delimiter_pop(reader);
|
|
2771
|
+
else {
|
|
2772
|
+
reader->quote = DELIMITER_UNQUOTED;
|
|
2773
|
+
reader->quotes--;
|
|
2774
|
+
}
|
|
2775
|
+
break;
|
|
2776
|
+
default:
|
|
2777
|
+
if (!delimiter_nest(reader)) return;
|
|
2778
|
+
reader->quote = DELIMITER_DOUBLE_QUOTED;
|
|
2779
|
+
reader->quotes++;
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
static bool delimiter_in_parameter(const struct DelimiterReader *reader) {
|
|
2784
|
+
size_t depth = delimiter_outer(reader, DELIMITER_DOUBLE_QUOTE);
|
|
2747
2785
|
return depth && reader->groups[depth - 1].kind == DELIMITER_PARAMETER;
|
|
2748
2786
|
}
|
|
2749
2787
|
|
|
@@ -2793,40 +2831,14 @@ static bool delimiter_step(struct DelimiterReader *reader) {
|
|
|
2793
2831
|
reader->quote == DELIMITER_DOUBLE_QUOTED ||
|
|
2794
2832
|
reader->quote == DELIMITER_PARAMETER_QUOTED
|
|
2795
2833
|
) {
|
|
2796
|
-
if (c
|
|
2797
|
-
else
|
|
2798
|
-
pop(input);
|
|
2799
|
-
if (reader->quote == DELIMITER_PARAMETER_QUOTED) {
|
|
2800
|
-
if (delimiter_push(reader, DELIMITER_DOUBLE_QUOTE, '"'))
|
|
2801
|
-
reader->quote = DELIMITER_DOUBLE_QUOTED;
|
|
2802
|
-
} else {
|
|
2803
|
-
reader->document.quoted = true;
|
|
2804
|
-
if (
|
|
2805
|
-
reader->count && delimiter_top(reader)->kind == DELIMITER_DOUBLE_QUOTE
|
|
2806
|
-
)
|
|
2807
|
-
delimiter_pop(reader);
|
|
2808
|
-
else {
|
|
2809
|
-
reader->quote = DELIMITER_UNQUOTED;
|
|
2810
|
-
reader->quotes--;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2834
|
+
if (c == '"') delimiter_double_quote(reader);
|
|
2835
|
+
else delimiter_copy(reader);
|
|
2814
2836
|
} else if (!reader->count && separator(c)) return false;
|
|
2815
2837
|
else if (reader->quote != DELIMITER_ARITHMETIC_QUOTED && c == '\'')
|
|
2816
2838
|
delimiter_single_quote(reader, false);
|
|
2817
|
-
else if (reader->quote != DELIMITER_ARITHMETIC_QUOTED && c == '"')
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
NESTING_LIMIT
|
|
2821
|
-
) {
|
|
2822
|
-
reader->parser->plan->failed = true;
|
|
2823
|
-
return false;
|
|
2824
|
-
}
|
|
2825
|
-
pop(input);
|
|
2826
|
-
reader->quote = DELIMITER_DOUBLE_QUOTED;
|
|
2827
|
-
reader->quotes++;
|
|
2828
|
-
} else if (c == ')' && delimiter_close(reader, DELIMITER_COMMAND))
|
|
2829
|
-
return true;
|
|
2839
|
+
else if (reader->quote != DELIMITER_ARITHMETIC_QUOTED && c == '"')
|
|
2840
|
+
delimiter_double_quote(reader);
|
|
2841
|
+
else if (c == ')' && delimiter_close(reader, DELIMITER_COMMAND)) return true;
|
|
2830
2842
|
else if (reader->count && c == delimiter_top(reader)->closing) {
|
|
2831
2843
|
if (delimiter_top(reader)->kind == DELIMITER_ARITHMETIC) {
|
|
2832
2844
|
delimiter_copy(reader);
|
|
@@ -2925,6 +2937,10 @@ static void here_document_line(
|
|
|
2925
2937
|
}
|
|
2926
2938
|
}
|
|
2927
2939
|
|
|
2940
|
+
static bool line_complete(const struct Text *line) {
|
|
2941
|
+
return line->count && line->units[line->count - 1].value == '\n';
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2928
2944
|
static bool here_document_end_line(
|
|
2929
2945
|
struct Parser *parser,
|
|
2930
2946
|
const struct Document *here,
|
|
@@ -2939,7 +2955,7 @@ static bool here_document_end_line(
|
|
|
2939
2955
|
bytes->count = 0;
|
|
2940
2956
|
for (size_t i = *first; i < line->count && line->units[i].value != '\n'; i++)
|
|
2941
2957
|
encode(parser, bytes, line->units[i]);
|
|
2942
|
-
bool newline = line
|
|
2958
|
+
bool newline = line_complete(line);
|
|
2943
2959
|
bool source_eof = parser->input.position == parser->input.count &&
|
|
2944
2960
|
parser->input.end == parser->plan->source_end;
|
|
2945
2961
|
bool found = bytes->count == here->delimiter.count &&
|
|
@@ -2965,7 +2981,7 @@ static bool here_document_lines(
|
|
|
2965
2981
|
here_document_line(parser, here, &line);
|
|
2966
2982
|
size_t first;
|
|
2967
2983
|
found = here_document_end_line(parser, here, &line, &first, &bytes);
|
|
2968
|
-
*at_line_start = line
|
|
2984
|
+
*at_line_start = line_complete(&line);
|
|
2969
2985
|
if (found) *boundary = line_start;
|
|
2970
2986
|
else
|
|
2971
2987
|
for (size_t i = first; i < line.count; i++)
|
|
@@ -3006,6 +3022,12 @@ static bool here_document(
|
|
|
3006
3022
|
return at_line_start;
|
|
3007
3023
|
}
|
|
3008
3024
|
|
|
3025
|
+
static void clear_documents(struct Parser *parser) {
|
|
3026
|
+
for (size_t i = 0; i < parser->document_count; i++)
|
|
3027
|
+
ts_free(parser->documents[i].delimiter.units);
|
|
3028
|
+
parser->document_count = 0;
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3009
3031
|
static void documents(struct Parser *parser, bool at_line_start) {
|
|
3010
3032
|
struct Input *input = &parser->input;
|
|
3011
3033
|
size_t body_start = at_line_start ? consumed_offset(input) : input->end;
|
|
@@ -3019,9 +3041,7 @@ static void documents(struct Parser *parser, bool at_line_start) {
|
|
|
3019
3041
|
at_line_start = here_document(parser, here, at_line_start, body_start);
|
|
3020
3042
|
body_start = consumed_offset(input);
|
|
3021
3043
|
}
|
|
3022
|
-
|
|
3023
|
-
ts_free(parser->documents[document].delimiter.units);
|
|
3024
|
-
parser->document_count = 0;
|
|
3044
|
+
clear_documents(parser);
|
|
3025
3045
|
}
|
|
3026
3046
|
|
|
3027
3047
|
static void take(struct Parser *parser) {
|
|
@@ -3250,7 +3270,7 @@ enum RecoveryBoundary {
|
|
|
3250
3270
|
};
|
|
3251
3271
|
|
|
3252
3272
|
static bool redirect_operand(struct Parser *parser, enum Lexeme kind) {
|
|
3253
|
-
if (
|
|
3273
|
+
if (kind == HERE || kind == HERE_STRIP)
|
|
3254
3274
|
declare_here_document(parser, kind == HERE_STRIP);
|
|
3255
3275
|
bool word = look(parser)->kind == WORD;
|
|
3256
3276
|
if (word) take(parser);
|
|
@@ -3843,8 +3863,7 @@ static void parse(struct Parser *parser) {
|
|
|
3843
3863
|
|
|
3844
3864
|
static void clear_parser(struct Parser *parser) {
|
|
3845
3865
|
ts_free(parser->token.text.units);
|
|
3846
|
-
|
|
3847
|
-
ts_free(parser->documents[i].delimiter.units);
|
|
3866
|
+
clear_documents(parser);
|
|
3848
3867
|
ts_free(parser->documents);
|
|
3849
3868
|
}
|
|
3850
3869
|
|