@@ -24,25 +24,43 @@ const POSTFIX_OP_FLAG = RawFlags(3<<3)
24
24
25
25
# The following flags are quite head-specific and may overlap
26
26
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
+ """
28
30
const 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
+ """
30
35
const RAW_STRING_FLAG = RawFlags (1 << 6 )
31
36
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
+ """
33
40
const 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
+ """
35
45
const 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
+ """
37
50
const TOPLEVEL_SEMICOLONS_FLAG = RawFlags (1 << 5 )
38
51
39
- # Set for K"struct" when mutable
52
+ """
53
+ Set for K"struct" when mutable
54
+ """
40
55
const MUTABLE_FLAG = RawFlags (1 << 5 )
41
56
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
+ """
43
60
const BARE_MODULE_FLAG = RawFlags (1 << 5 )
44
61
45
62
# 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?
46
64
const NUMERIC_FLAGS = RawFlags (RawFlags (0xff )<< 8 )
47
65
48
66
function set_numeric_flags (n:: Integer )
@@ -65,7 +83,11 @@ function remove_flags(n::RawFlags, fs...)
65
83
RawFlags (n & ~ (RawFlags ((| )(fs... ))))
66
84
end
67
85
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
+ """
69
91
has_flags (flags:: RawFlags , test_flags) = (flags & test_flags) != 0
70
92
71
93
# -------------------------------------------------------------------------------
@@ -145,14 +167,72 @@ flags(x) = flags(head(x))
145
167
has_flags (x, test_flags) = has_flags (flags (x), test_flags)
146
168
call_type_flags (x) = call_type_flags (flags (x))
147
169
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
+ """
148
177
is_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
+ """
149
185
is_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
+ """
150
193
is_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
+ """
151
200
is_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
+ """
152
207
is_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
+ """
153
214
is_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
+ """
154
221
is_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
+ """
155
228
is_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
+ """
156
236
numeric_flags (x) = numeric_flags (flags (x))
157
237
158
238
# -------------------------------------------------------------------------------
0 commit comments