@@ -24,25 +24,43 @@ const POSTFIX_OP_FLAG = RawFlags(3<<3)
2424
2525# The following flags are quite head-specific and may overlap
2626
27- # Set when K"string" or K"cmdstring" was triple-delimited as with """ or ```
27+ """
28+ Set when K"string" or K"cmdstring" was triple-delimited as with \"\"\" or ```
29+ """
2830const TRIPLE_STRING_FLAG = RawFlags (1 << 5 )
29- # Set when a K"string", K"cmdstring" or K"Identifier" needs raw string unescaping
31+
32+ """
33+ Set when a K"string", K"cmdstring" or K"Identifier" needs raw string unescaping
34+ """
3035const RAW_STRING_FLAG = RawFlags (1 << 6 )
3136
32- # Set for K"tuple", K"block" or K"macrocall" which are delimited by parentheses
37+ """
38+ Set for K"tuple", K"block" or K"macrocall" which are delimited by parentheses
39+ """
3340const PARENS_FLAG = RawFlags (1 << 5 )
34- # Set for K"quote" for the short form `:x` as oppsed to long form `quote x end`
41+
42+ """
43+ Set for K"quote" for the short form `:x` as oppsed to long form `quote x end`
44+ """
3545const COLON_QUOTE = RawFlags (1 << 5 )
36- # Set for K"toplevel" which is delimited by parentheses
46+
47+ """
48+ Set for K"toplevel" which is delimited by parentheses
49+ """
3750const TOPLEVEL_SEMICOLONS_FLAG = RawFlags (1 << 5 )
3851
39- # Set for K"struct" when mutable
52+ """
53+ Set for K"struct" when mutable
54+ """
4055const MUTABLE_FLAG = RawFlags (1 << 5 )
4156
42- # Set for K"module" when it's not bare (`module`, not `baremodule`)
57+ """
58+ Set for K"module" when it's not bare (`module`, not `baremodule`)
59+ """
4360const BARE_MODULE_FLAG = RawFlags (1 << 5 )
4461
4562# Flags holding the dimension of an nrow or other UInt8 not held in the source
63+ # TODO : Given this is only used for nrow/ncat, we could actually use all the flags?
4664const NUMERIC_FLAGS = RawFlags (RawFlags (0xff )<< 8 )
4765
4866function set_numeric_flags (n:: Integer )
@@ -65,7 +83,11 @@ function remove_flags(n::RawFlags, fs...)
6583 RawFlags (n & ~ (RawFlags ((| )(fs... ))))
6684end
6785
68- # Return true if any of `test_flags` are set
86+ """
87+ has_flags(x, test_flags)
88+
89+ Return true if any of `test_flags` are set.
90+ """
6991has_flags (flags:: RawFlags , test_flags) = (flags & test_flags) != 0
7092
7193# -------------------------------------------------------------------------------
@@ -145,14 +167,72 @@ flags(x) = flags(head(x))
145167has_flags (x, test_flags) = has_flags (flags (x), test_flags)
146168call_type_flags (x) = call_type_flags (flags (x))
147169
170+ """
171+ is_trivia(x)
172+
173+ Return true for "syntax trivia": tokens in the tree which are either largely
174+ invisible to the parser (eg, whitespace) or implied by the structure of the AST
175+ (eg, reserved words).
176+ """
148177is_trivia (x) = has_flags (x, TRIVIA_FLAG)
178+
179+ """
180+ is_prefix_call(x)
181+
182+ Return true for normal prefix function call syntax such as the `f` call node
183+ parsed from `f(x)`.
184+ """
149185is_prefix_call (x) = call_type_flags (x) == PREFIX_CALL_FLAG
186+
187+ """
188+ is_infix_op_call(x)
189+
190+ Return true for infix operator calls such as the `+` call node parsed from
191+ `x + y`.
192+ """
150193is_infix_op_call (x) = call_type_flags (x) == INFIX_FLAG
194+
195+ """
196+ is_prefix_op_call(x)
197+
198+ Return true for prefix operator calls such as the `+` call node parsed from `+x`.
199+ """
151200is_prefix_op_call (x) = call_type_flags (x) == PREFIX_OP_FLAG
201+
202+ """
203+ is_postfix_op_call(x)
204+
205+ Return true for postfix operator calls such as the `'ᵀ` call node parsed from `x'ᵀ`.
206+ """
152207is_postfix_op_call (x) = call_type_flags (x) == POSTFIX_OP_FLAG
208+
209+ """
210+ is_dotted(x)
211+
212+ Return true for dotted syntax tokens
213+ """
153214is_dotted (x) = has_flags (x, DOTOP_FLAG)
215+
216+ """
217+ is_suffixed(x)
218+
219+ Return true for operators which have sufficies, such as `+₁`
220+ """
154221is_suffixed (x) = has_flags (x, SUFFIXED_FLAG)
222+
223+ """
224+ is_decorated(x)
225+
226+ Return true for operators which are decorated with a dot or suffix.
227+ """
155228is_decorated (x) = is_dotted (x) || is_suffixed (x)
229+
230+ """
231+ numeric_flags(x)
232+
233+ Return the number attached to a `SyntaxHead`. This is only for kinds `K"nrow"`
234+ and `K"ncat"`, for now.
235+ """
156236numeric_flags (x) = numeric_flags (flags (x))
157237
158238# -------------------------------------------------------------------------------
0 commit comments