1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! The bracket classification (REL8-1423): whether a `[` opens a group
//! the normalizer may collapse as one list parameter. The operand
//! vocabulary it derives from is `crate::token::facts`'s — the inherent
//! `TokenType::ends_expression` / `TokenType::introduces_operand`, with
//! [`TokenType::is_relationship_start`] for the pattern heads. The
//! classification's one consumer is the normalizer's list-literal
//! collapse (`normalize::Pass::collapses_as_list_group`), and the
//! collapse algorithm and its history live there.
use crateToken;
/// Whether the `[` that FOLLOWS `before` opens a group the normalizer may
/// **collapse as one list parameter** — the one fact the prefix can
/// support, and the only one the collapse's consumer
/// (`normalize::Pass::collapses_as_list_group`) asks. `before` is the
/// token stream up to (and excluding) the bracket, so the caller's index
/// arithmetic ends at the call; that the next token is a `[` is the
/// caller's contract, asserted at the call site where the token is in
/// hand.
///
/// The answer is the complement of the three predecessor positions whose
/// bracket must keep its brackets — the prefix cannot always name the
/// exact role (a `-` before the bracket is a relationship head OR binary
/// subtraction), but it never needs to: every excluded position keeps
/// brackets whichever role it is, and the exclusion is the decision:
///
/// - a **relationship-pattern head OR subtraction operator** (`-`, `<-`,
/// [`TokenType::is_relationship_start`]): `-[r:T]->`'s bracket is the
/// pattern's own, and `RETURN 1 - [1, 2]`'s is a subtraction's list —
/// the prefix cannot tell them apart, and both keep their brackets
/// (the subtraction's list renders with its brackets and its elements
/// normalize individually — a coarser template, never a broken one).
/// - a token that can **end an expression** ([`ends_expression`]): the
/// bracket is a subscript (`labels(n)[0]`, `xs[0]`, `[1, 2, 3][0]`,
/// `RETURN true[0]`, `RETURN CASE … END[0]`).
/// - a keyword in **operand position** ([`keyword_operand_position`]) —
/// the dialect's keyword-spelled variables (`AS count … RETURN
/// count[0]`, `RETURN RETURN[0]`, ADR-0169): the bracket is a
/// subscript.
///
/// Everything else — a clause word (`RETURN [1, 2]`, `x IN [1, 2]`,
/// `THEN [1]`), an operator, or nothing (the stream start) — leaves the
/// `[` opening a list literal the group scan may collapse.
pub
/// Whether the keyword immediately before the bracket sits in operand
/// position — the keyword-spelled-variable test: the token before the
/// keyword, when there is one, is an operand-INTRODUCING token
/// ([`TokenType::introduces_operand`]), the same names ADR-0169 keeps
/// usable as identifiers. A keyword with nothing before it (the stream
/// start) is in clause position.