@konomanoasa/tree-sitter-posix-awk 0.19.0 → 0.20.0
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/README.md +4 -0
- package/grammar.js +538 -704
- package/package.json +5 -3
- package/src/grammar.json +7218 -6579
- package/src/parser.c +56442 -57498
- package/src/scanner.c +2639 -1199
- package/test/bindings.test.rs +183 -448
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -19,6 +19,8 @@ export const EXPRESSION = {
|
|
|
19
19
|
field: { precedence: 24, associativity: "right" },
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
export const FILE_SOURCE_TIER = "additive";
|
|
23
|
+
|
|
22
24
|
export const RESERVED_WORDS = {
|
|
23
25
|
keyword: [
|
|
24
26
|
"BEGIN",
|
|
@@ -67,35 +69,36 @@ export const RESERVED_WORDS = {
|
|
|
67
69
|
],
|
|
68
70
|
};
|
|
69
71
|
|
|
70
|
-
const OPERAND_PRECEDENCE = 2;
|
|
71
|
-
const CLASSIFICATIONS = ["unary", "non_unary"];
|
|
72
|
-
|
|
73
|
-
function nextExpressionTier(tier, comparison) {
|
|
74
|
-
return Object.keys(EXPRESSION)
|
|
75
|
-
.filter(
|
|
76
|
-
(name) =>
|
|
77
|
-
(comparison || name !== "comparison") &&
|
|
78
|
-
EXPRESSION[name].precedence > EXPRESSION[tier].precedence,
|
|
79
|
-
)
|
|
80
|
-
.sort(
|
|
81
|
-
(left, right) =>
|
|
82
|
-
EXPRESSION[left].precedence - EXPRESSION[right].precedence,
|
|
83
|
-
)[0];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const bind = ({ precedence, associativity }, rule) =>
|
|
87
|
-
associativity === "left"
|
|
88
|
-
? prec.left(precedence, rule)
|
|
89
|
-
: associativity === "right"
|
|
90
|
-
? prec.right(precedence, rule)
|
|
91
|
-
: prec(precedence, rule);
|
|
92
|
-
|
|
93
72
|
// Skipping blanks can reach a backslash the external scanner never saw.
|
|
94
73
|
const continuationMarker = () => token.immediate("\\");
|
|
95
74
|
|
|
96
75
|
const signOperator = ($, character) =>
|
|
97
76
|
alias(character === "+" ? $._plus_operator : $._minus_operator, character);
|
|
98
77
|
|
|
78
|
+
const assignmentOperator = ($) =>
|
|
79
|
+
choice(
|
|
80
|
+
"=",
|
|
81
|
+
$.pow_assign,
|
|
82
|
+
$.mod_assign,
|
|
83
|
+
$.mul_assign,
|
|
84
|
+
$.div_assign,
|
|
85
|
+
$.add_assign,
|
|
86
|
+
$.sub_assign,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const binaryOperators = ($) => ({
|
|
90
|
+
additive: [signOperator($, "+"), signOperator($, "-")],
|
|
91
|
+
multiplicative: ["*", alias($._division_slash, "/"), "%"],
|
|
92
|
+
exponentiation: ["^"],
|
|
93
|
+
match: ["~", $.no_match],
|
|
94
|
+
comparison: ["<", ">", $.le, $.ge, $.eq, $.ne],
|
|
95
|
+
logical_and: [$.and],
|
|
96
|
+
logical_or: [$.or],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const oneOf = (members) =>
|
|
100
|
+
members.length === 1 ? members[0] : choice(...members);
|
|
101
|
+
|
|
99
102
|
const twoCharacterTokenRules = Object.fromEntries(
|
|
100
103
|
Object.entries({
|
|
101
104
|
add_assign: "+=",
|
|
@@ -115,11 +118,6 @@ const twoCharacterTokenRules = Object.fromEntries(
|
|
|
115
118
|
}).map(([name, spelling]) => [name, () => spelling]),
|
|
116
119
|
);
|
|
117
120
|
|
|
118
|
-
const trailingUpdateOperators = ($) => [
|
|
119
|
-
alias($.trailing_incr, $.incr),
|
|
120
|
-
alias($.trailing_decr, $.decr),
|
|
121
|
-
];
|
|
122
|
-
|
|
123
121
|
const newlineLayout = ($) => optional($.newline_opt);
|
|
124
122
|
|
|
125
123
|
const afterOptionalNewline = ($, member) => seq(newlineLayout($), member);
|
|
@@ -239,439 +237,522 @@ const controlStatements = ($, body) => [
|
|
|
239
237
|
const parenthesized = (member) => seq("(", member, ")");
|
|
240
238
|
|
|
241
239
|
const parenthesizedPrintStatement = ($, keyword) =>
|
|
242
|
-
seq(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const subscript = (subscripts) => seq("[", subscripts, "]");
|
|
247
|
-
|
|
248
|
-
const redirectedInput = ($, get, source = $.expr) =>
|
|
249
|
-
prec.right(
|
|
250
|
-
EXPRESSION.field.precedence,
|
|
251
|
-
seq(field("get", get), "<", field("source", source)),
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
const pipedInput = ($, source, get) =>
|
|
255
|
-
prec.right(
|
|
256
|
-
EXPRESSION.field.precedence,
|
|
257
|
-
seq(
|
|
258
|
-
field("source", source),
|
|
259
|
-
alias($._getline_pipe, "|"),
|
|
260
|
-
field("get", get),
|
|
261
|
-
),
|
|
240
|
+
seq(
|
|
241
|
+
keyword,
|
|
242
|
+
$._print_arguments,
|
|
243
|
+
parenthesized(field("arguments", $.multiple_expr_list)),
|
|
262
244
|
);
|
|
263
245
|
|
|
264
246
|
const rawNewlines = ($) => repeat1($.newline);
|
|
265
247
|
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
return choice(
|
|
269
|
-
$.getline_keyword,
|
|
270
|
-
keyword($.omitted_getline_keyword),
|
|
271
|
-
keyword($.preferred_omitted_getline_keyword),
|
|
272
|
-
seq(
|
|
273
|
-
choice(
|
|
274
|
-
keyword($.target_getline_keyword),
|
|
275
|
-
keyword($.preferred_target_getline_keyword),
|
|
276
|
-
),
|
|
277
|
-
field("target", $._lvalue),
|
|
278
|
-
),
|
|
279
|
-
prec.dynamic(-1, keyword($.preferred_target_getline_keyword)),
|
|
280
|
-
prec.dynamic(
|
|
281
|
-
-1,
|
|
282
|
-
seq(
|
|
283
|
-
choice(
|
|
284
|
-
keyword($.preferred_omitted_getline_keyword),
|
|
285
|
-
...(sourceContext ? [keyword($.omitted_getline_keyword)] : []),
|
|
286
|
-
),
|
|
287
|
-
field("target", $._lvalue),
|
|
288
|
-
),
|
|
289
|
-
),
|
|
290
|
-
);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const EXPRESSION_CONTEXT = {
|
|
294
|
-
normal: {
|
|
295
|
-
prefix: "normal",
|
|
296
|
-
expression: "expr",
|
|
297
|
-
unaryExpression: "unary_expr",
|
|
298
|
-
nonUnaryExpression: "non_unary_expr",
|
|
299
|
-
comparison: true,
|
|
300
|
-
input: ($) =>
|
|
301
|
-
choice(
|
|
302
|
-
alias($.direct_input_function, $.non_unary_input_function),
|
|
303
|
-
alias($.piped_input_function, $.non_unary_input_function),
|
|
304
|
-
),
|
|
305
|
-
unaryInput: ($) => $.unary_input_function,
|
|
306
|
-
},
|
|
307
|
-
source: {
|
|
308
|
-
prefix: "source",
|
|
309
|
-
expression: "source_expr",
|
|
310
|
-
publicExpression: "expr",
|
|
311
|
-
unaryExpression: "unary_expr",
|
|
312
|
-
nonUnaryExpression: "non_unary_expr",
|
|
313
|
-
comparison: true,
|
|
314
|
-
input: ($) =>
|
|
315
|
-
choice(
|
|
316
|
-
alias($.source_direct_input_function, $.non_unary_input_function),
|
|
317
|
-
alias($.source_piped_input_function, $.non_unary_input_function),
|
|
318
|
-
),
|
|
319
|
-
unaryInput: ($) =>
|
|
320
|
-
alias($.source_unary_input_function, $.unary_input_function),
|
|
321
|
-
},
|
|
322
|
-
print: {
|
|
323
|
-
prefix: "print",
|
|
324
|
-
expression: "print_expr",
|
|
325
|
-
unaryExpression: "unary_print_expr",
|
|
326
|
-
nonUnaryExpression: "non_unary_print_expr",
|
|
327
|
-
comparison: false,
|
|
328
|
-
},
|
|
329
|
-
field: {
|
|
330
|
-
prefix: "field",
|
|
331
|
-
expression: "expr",
|
|
332
|
-
unaryExpression: "unary_expr",
|
|
333
|
-
nonUnaryExpression: "non_unary_expr",
|
|
334
|
-
input: ($) => alias($.direct_input_function, $.non_unary_input_function),
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const classTierName = (context, classification, tier) =>
|
|
339
|
-
`_${context.prefix}_${classification}_${tier}_expr`;
|
|
340
|
-
|
|
341
|
-
// Hidden operand rules leak inner fields into the parent.
|
|
342
|
-
const classOperandName = (context, classification, tier) =>
|
|
343
|
-
`${context.prefix}_${classification}_${tier}_operand`;
|
|
344
|
-
|
|
345
|
-
const anyTierName = (context, tier) => `${context.prefix}_${tier}_expr`;
|
|
346
|
-
|
|
347
|
-
const classTier = ($, context, classification, tier) =>
|
|
348
|
-
$[classTierName(context, classification, tier)];
|
|
349
|
-
|
|
350
|
-
const aliasedClassTier = ($, context, classification, tier) =>
|
|
351
|
-
alias(
|
|
352
|
-
$[classOperandName(context, classification, tier)],
|
|
353
|
-
$[
|
|
354
|
-
classification === "unary"
|
|
355
|
-
? context.unaryExpression
|
|
356
|
-
: context.nonUnaryExpression
|
|
357
|
-
],
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const tierHelpers = (context, rules) => ({
|
|
361
|
-
unary: (tier) => classTierName(context, "unary", tier),
|
|
362
|
-
nonUnary: (tier) => classTierName(context, "non_unary", tier),
|
|
363
|
-
addOperand: (classification, tier) =>
|
|
364
|
-
Object.assign(rules, classOperandRules(context, classification, tier)),
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const aliasedAnyTier = ($, context, tier) =>
|
|
368
|
-
alias(
|
|
369
|
-
$[anyTierName(context, tier)],
|
|
370
|
-
$[context.publicExpression ?? context.expression],
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
const nonUnaryAtom = ($, context, lvalue = $._lvalue) => {
|
|
374
|
-
const atoms = [
|
|
375
|
-
$._parenthesized_expression,
|
|
376
|
-
$.number,
|
|
377
|
-
$.string,
|
|
378
|
-
lvalue,
|
|
379
|
-
$._user_function_call,
|
|
380
|
-
$._builtin_function_call,
|
|
381
|
-
$.builtin_func_name,
|
|
382
|
-
$.ere,
|
|
383
|
-
];
|
|
384
|
-
if (context.input) {
|
|
385
|
-
atoms.push(context.input($));
|
|
386
|
-
}
|
|
387
|
-
return choice(...atoms);
|
|
388
|
-
};
|
|
248
|
+
const listElementTail = ($, element) =>
|
|
249
|
+
seq(",", afterOptionalNewline($, element));
|
|
389
250
|
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
251
|
+
const boundaryKinds = [
|
|
252
|
+
"atom",
|
|
253
|
+
"name",
|
|
254
|
+
"group",
|
|
255
|
+
"call",
|
|
256
|
+
"subscript",
|
|
257
|
+
"get",
|
|
258
|
+
"target_get",
|
|
259
|
+
"file",
|
|
260
|
+
"field",
|
|
261
|
+
"prefix",
|
|
262
|
+
"postfix",
|
|
263
|
+
"binary",
|
|
264
|
+
"concat",
|
|
265
|
+
"assignment",
|
|
266
|
+
"conditional",
|
|
267
|
+
"branches",
|
|
268
|
+
"pipe",
|
|
269
|
+
"membership",
|
|
270
|
+
"tuple",
|
|
271
|
+
];
|
|
272
|
+
const boundaryDigits = [0, 1, 2, 3];
|
|
273
|
+
const boundaryExternals = ($) => [
|
|
274
|
+
$._root,
|
|
275
|
+
$._print_root,
|
|
276
|
+
$._for_in,
|
|
277
|
+
$._print_arguments,
|
|
278
|
+
$._begin_child,
|
|
279
|
+
$._end_child,
|
|
280
|
+
$._resume,
|
|
281
|
+
$._next_argument,
|
|
282
|
+
...boundaryDigits.map((digit) => $[`_save_${digit}`]),
|
|
283
|
+
...boundaryDigits.map((digit) => $[`_restore_${digit}`]),
|
|
284
|
+
$._class_unary,
|
|
285
|
+
$._class_non_unary,
|
|
286
|
+
...boundaryKinds.map((kind) => $[`_select_${kind}`]),
|
|
287
|
+
$._local_root,
|
|
288
|
+
$._local_print_root,
|
|
289
|
+
];
|
|
394
290
|
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
291
|
+
const boundaryRules = {};
|
|
292
|
+
for (const [kind, body] of Object.entries({
|
|
293
|
+
expr: ($) => alias($._boundary_expr, $.expr),
|
|
294
|
+
unary: ($) => $.unary_expr,
|
|
295
|
+
non_unary: ($) => $.non_unary_expr,
|
|
296
|
+
print_expr: ($) => alias($._boundary_print_expr, $.print_expr),
|
|
297
|
+
print_unary: ($) => $.unary_print_expr,
|
|
298
|
+
print_non_unary: ($) => $.non_unary_print_expr,
|
|
299
|
+
name: ($) => seq($._select_name, $.name),
|
|
300
|
+
tuple: ($) =>
|
|
301
|
+
seq(
|
|
302
|
+
$._select_group,
|
|
303
|
+
"(",
|
|
304
|
+
field(
|
|
305
|
+
"left",
|
|
306
|
+
alias($._boundary_multiple_arguments, $.multiple_expr_list),
|
|
307
|
+
),
|
|
308
|
+
")",
|
|
402
309
|
),
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const not = `_${context.prefix}_not_expr`;
|
|
410
|
-
rules[unary("unary")] = ($) =>
|
|
310
|
+
lvalue: ($) => $.lvalue,
|
|
311
|
+
get: ($) => $.simple_get,
|
|
312
|
+
branches: ($) => $._branches,
|
|
313
|
+
print_branches: ($) => $._print_branches,
|
|
314
|
+
})) {
|
|
315
|
+
boundaryRules[`_checkpoint_${kind}`] = ($) =>
|
|
411
316
|
choice(
|
|
412
|
-
...(
|
|
413
|
-
? [classTier($, context, "unary", "exponentiation")]
|
|
414
|
-
: []),
|
|
415
|
-
...["+", "-"].map((operator) =>
|
|
317
|
+
...boundaryDigits.map((digit) =>
|
|
416
318
|
seq(
|
|
417
|
-
|
|
418
|
-
|
|
319
|
+
$[`_save_${digit}`],
|
|
320
|
+
$[`_checkpoint_${kind}`],
|
|
321
|
+
$[`_restore_${digit}`],
|
|
419
322
|
),
|
|
420
323
|
),
|
|
324
|
+
seq($._begin_child, body($), $._end_child),
|
|
421
325
|
);
|
|
422
|
-
|
|
423
|
-
seq(
|
|
424
|
-
|
|
425
|
-
field("operand", aliasedAnyTier($, context, "unary")),
|
|
426
|
-
);
|
|
427
|
-
rules[nonUnary("unary")] = ($) =>
|
|
428
|
-
choice($[nonUnary("exponentiation")], $[not]);
|
|
326
|
+
boundaryRules[`_child_${kind}`] = ($) =>
|
|
327
|
+
seq($[`_checkpoint_${kind}`], $._resume);
|
|
328
|
+
}
|
|
429
329
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
330
|
+
for (const print of [false, true]) {
|
|
331
|
+
const prefix = print ? "print_" : "";
|
|
332
|
+
const expr = ($) => $[`_child_${prefix}expr`];
|
|
333
|
+
for (const unary of [false, true]) {
|
|
334
|
+
const classification = unary ? "unary" : "non_unary";
|
|
335
|
+
const klass = ($) => $[`_child_${prefix}${classification}`];
|
|
336
|
+
boundaryRules[`${classification}_${prefix}expr`] = ($) =>
|
|
337
|
+
seq(
|
|
338
|
+
unary ? $._class_unary : $._class_non_unary,
|
|
339
|
+
choice(
|
|
340
|
+
seq(
|
|
341
|
+
$._select_prefix,
|
|
342
|
+
field(
|
|
343
|
+
"operator",
|
|
344
|
+
unary
|
|
345
|
+
? choice(signOperator($, "+"), signOperator($, "-"))
|
|
346
|
+
: alias($._not_operator, "!"),
|
|
347
|
+
),
|
|
348
|
+
field("operand", expr($)),
|
|
349
|
+
),
|
|
350
|
+
seq(
|
|
351
|
+
$._select_binary,
|
|
352
|
+
field("left", klass($)),
|
|
353
|
+
field(
|
|
354
|
+
"operator",
|
|
355
|
+
choice(
|
|
356
|
+
...Object.entries(binaryOperators($)).flatMap(
|
|
357
|
+
([tier, operators]) =>
|
|
358
|
+
// A unary left operand of ^ is a pipe, which print excludes.
|
|
359
|
+
(print && tier === "comparison") ||
|
|
360
|
+
(print && unary && tier === "exponentiation")
|
|
361
|
+
? []
|
|
362
|
+
: operators,
|
|
363
|
+
),
|
|
364
|
+
),
|
|
365
|
+
),
|
|
366
|
+
newlineLayout($),
|
|
367
|
+
field("right", expr($)),
|
|
368
|
+
),
|
|
369
|
+
seq(
|
|
370
|
+
$._select_concat,
|
|
371
|
+
field("left", klass($)),
|
|
372
|
+
field("right", $[`_child_${prefix}non_unary`]),
|
|
373
|
+
),
|
|
374
|
+
seq(
|
|
375
|
+
$._select_conditional,
|
|
376
|
+
field("condition", klass($)),
|
|
377
|
+
"?",
|
|
378
|
+
$[`_child_${prefix}branches`],
|
|
379
|
+
),
|
|
380
|
+
seq(
|
|
381
|
+
$._select_membership,
|
|
382
|
+
field("left", klass($)),
|
|
383
|
+
$._membership_operator,
|
|
384
|
+
field("right", $._child_name),
|
|
385
|
+
),
|
|
386
|
+
...(!print
|
|
387
|
+
? [unary ? $.unary_input_function : $.non_unary_input_function]
|
|
388
|
+
: []),
|
|
389
|
+
...(unary
|
|
390
|
+
? []
|
|
391
|
+
: [
|
|
392
|
+
seq(
|
|
393
|
+
$._select_tuple,
|
|
394
|
+
$._child_tuple,
|
|
395
|
+
$._membership_operator,
|
|
396
|
+
field("right", $._child_name),
|
|
397
|
+
),
|
|
398
|
+
seq(
|
|
399
|
+
$._select_atom,
|
|
400
|
+
choice($.number, $.string, $.ere, $.builtin_func_name),
|
|
401
|
+
),
|
|
402
|
+
$.lvalue,
|
|
403
|
+
seq($._select_group, "(", $._child_expr, ")"),
|
|
404
|
+
seq(
|
|
405
|
+
$._select_call,
|
|
406
|
+
choice($.func_name, $.builtin_func_name),
|
|
407
|
+
"(",
|
|
408
|
+
optional(alias($._boundary_arguments, $.expr_list)),
|
|
409
|
+
")",
|
|
410
|
+
),
|
|
411
|
+
seq(
|
|
412
|
+
$._select_postfix,
|
|
413
|
+
field("operand", $._child_lvalue),
|
|
414
|
+
field("operator", choice($.incr, $.decr)),
|
|
415
|
+
),
|
|
416
|
+
seq(
|
|
417
|
+
$._select_prefix,
|
|
418
|
+
field("operator", choice($.incr, $.decr)),
|
|
419
|
+
field("operand", $._child_lvalue),
|
|
420
|
+
),
|
|
421
|
+
seq(
|
|
422
|
+
$._select_assignment,
|
|
423
|
+
field("left", $._child_lvalue),
|
|
424
|
+
field("operator", assignmentOperator($)),
|
|
425
|
+
field("right", expr($)),
|
|
426
|
+
),
|
|
427
|
+
]),
|
|
450
428
|
),
|
|
451
429
|
);
|
|
452
430
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
431
|
+
boundaryRules[`_${prefix}branches`] = ($) =>
|
|
432
|
+
seq(
|
|
433
|
+
$._select_branches,
|
|
434
|
+
field("consequence", expr($)),
|
|
435
|
+
":",
|
|
436
|
+
field("alternative", expr($)),
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
Object.assign(boundaryRules, {
|
|
440
|
+
_boundary_expr: ($) => choice($.unary_expr, $.non_unary_expr),
|
|
441
|
+
_boundary_print_expr: ($) =>
|
|
442
|
+
choice($.unary_print_expr, $.non_unary_print_expr),
|
|
443
|
+
lvalue: ($) =>
|
|
458
444
|
choice(
|
|
459
|
-
|
|
460
|
-
$._prefix_update_expr,
|
|
445
|
+
seq($._select_name, $.name),
|
|
461
446
|
seq(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
447
|
+
$._select_subscript,
|
|
448
|
+
$.name,
|
|
449
|
+
"[",
|
|
450
|
+
alias($._boundary_arguments, $.expr_list),
|
|
451
|
+
"]",
|
|
467
452
|
),
|
|
468
453
|
seq(
|
|
469
|
-
|
|
470
|
-
field("operator",
|
|
454
|
+
$._select_field,
|
|
455
|
+
field("operator", alias($._field_operator, "$")),
|
|
456
|
+
field("operand", $._child_expr),
|
|
471
457
|
),
|
|
472
|
-
)
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const tieredExpressionRules = (context) => {
|
|
481
|
-
const rules = {};
|
|
482
|
-
const { unary, nonUnary, addOperand } = tierHelpers(context, rules);
|
|
483
|
-
const conditionalTail = `_${context.prefix}_conditional_tail`;
|
|
484
|
-
const expression = ($) =>
|
|
485
|
-
context.publicExpression
|
|
486
|
-
? alias($[context.expression], $[context.publicExpression])
|
|
487
|
-
: $[context.expression];
|
|
488
|
-
rules[conditionalTail] = ($) =>
|
|
458
|
+
),
|
|
459
|
+
_boundary_arguments: ($) =>
|
|
460
|
+
choice(
|
|
461
|
+
$._child_expr,
|
|
462
|
+
alias($._boundary_multiple_arguments, $.multiple_expr_list),
|
|
463
|
+
),
|
|
464
|
+
_boundary_multiple_arguments: ($) =>
|
|
489
465
|
seq(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
466
|
+
$._child_expr,
|
|
467
|
+
repeat1(seq(",", newlineLayout($), $._next_argument, $._child_expr)),
|
|
468
|
+
),
|
|
469
|
+
simple_get: ($) =>
|
|
470
|
+
choice(
|
|
471
|
+
seq($._select_get, $.getline_keyword),
|
|
472
|
+
seq(
|
|
473
|
+
$._select_target_get,
|
|
474
|
+
$.getline_keyword,
|
|
475
|
+
field("target", $._child_lvalue),
|
|
476
|
+
),
|
|
477
|
+
),
|
|
478
|
+
non_unary_input_function: ($) =>
|
|
479
|
+
choice(
|
|
480
|
+
field("get", $.simple_get),
|
|
481
|
+
seq(
|
|
482
|
+
$._select_file,
|
|
483
|
+
field("get", $._child_get),
|
|
484
|
+
"<",
|
|
485
|
+
field("source", $._child_expr),
|
|
486
|
+
),
|
|
487
|
+
seq(
|
|
488
|
+
$._select_pipe,
|
|
489
|
+
field("source", $._child_non_unary),
|
|
490
|
+
alias($._getline_pipe, "|"),
|
|
491
|
+
field("get", $._child_get),
|
|
492
|
+
),
|
|
493
|
+
),
|
|
494
|
+
unary_input_function: ($) =>
|
|
495
|
+
seq(
|
|
496
|
+
$._select_pipe,
|
|
497
|
+
field("source", $._child_unary),
|
|
498
|
+
alias($._getline_pipe, "|"),
|
|
499
|
+
field("get", $._child_get),
|
|
500
|
+
),
|
|
501
|
+
getline_keyword: ($) => $._getline_word,
|
|
502
|
+
});
|
|
495
503
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
504
|
+
const localRules = {};
|
|
505
|
+
const localNode = ($, name) => alias($[`local_${name}`], $[name]);
|
|
506
|
+
const localAtoms = ($, print, lvalue = localNode($, "lvalue")) =>
|
|
507
|
+
choice(
|
|
508
|
+
$._local_atom,
|
|
509
|
+
lvalue,
|
|
510
|
+
...(!print ? [localNode($, "non_unary_input_function")] : []),
|
|
511
|
+
);
|
|
512
|
+
for (const print of [false, true]) {
|
|
513
|
+
const prefix = print ? "print_" : "";
|
|
514
|
+
const expression = ($) => localNode($, `${prefix}expr`);
|
|
515
|
+
const tiers = Object.keys(EXPRESSION).filter(
|
|
516
|
+
(name) => name !== "field" && (!print || name !== "comparison"),
|
|
517
|
+
);
|
|
518
|
+
const classifications = (name) =>
|
|
519
|
+
name === "atom" || EXPRESSION[name].precedence > EXPRESSION.unary.precedence
|
|
520
|
+
? ["non_unary"]
|
|
521
|
+
: ["unary", "non_unary"];
|
|
522
|
+
const tier = (classification, name) =>
|
|
523
|
+
`_local_${prefix}${classification}_${name}`;
|
|
524
|
+
const operand = (classification, name) =>
|
|
525
|
+
`local_${prefix}${classification}_${name}`;
|
|
526
|
+
const union = (name) => `local_${prefix}${name}`;
|
|
527
|
+
const classified = (classification, name) => ($) =>
|
|
528
|
+
alias(
|
|
529
|
+
$[operand(classification, name)],
|
|
530
|
+
$[`${classification}_${prefix}expr`],
|
|
531
|
+
);
|
|
532
|
+
const referenced = new Set();
|
|
533
|
+
const member = (classification, name) => {
|
|
534
|
+
referenced.add(operand(classification, name));
|
|
535
|
+
return classified(classification, name);
|
|
536
|
+
};
|
|
537
|
+
const any = (name) => {
|
|
538
|
+
referenced.add(union(name));
|
|
539
|
+
for (const classification of classifications(name))
|
|
540
|
+
member(classification, name);
|
|
541
|
+
return ($) => alias($[union(name)], $[`${prefix}expr`]);
|
|
542
|
+
};
|
|
543
|
+
const tierOperations = (classification, name, next) => {
|
|
544
|
+
if (name === "assignment") {
|
|
545
|
+
return ($) =>
|
|
546
|
+
classification === "unary"
|
|
547
|
+
? []
|
|
548
|
+
: [
|
|
549
|
+
seq(
|
|
550
|
+
field("left", localNode($, "lvalue")),
|
|
551
|
+
field("operator", assignmentOperator($)),
|
|
552
|
+
field("right", expression($)),
|
|
553
|
+
),
|
|
554
|
+
];
|
|
555
|
+
}
|
|
556
|
+
if (name === "conditional") {
|
|
557
|
+
const condition = member(classification, next);
|
|
558
|
+
const alternative = any(name);
|
|
559
|
+
return ($) => [
|
|
521
560
|
seq(
|
|
522
|
-
field(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
),
|
|
530
|
-
),
|
|
531
|
-
$[tail],
|
|
532
|
-
);
|
|
533
|
-
rules[classTierName(context, classification, tier)] = ($) =>
|
|
534
|
-
choice(
|
|
535
|
-
classTier($, context, classification, nextTier),
|
|
536
|
-
bind(binding, operation($)),
|
|
537
|
-
);
|
|
561
|
+
field("condition", condition($)),
|
|
562
|
+
"?",
|
|
563
|
+
field("consequence", expression($)),
|
|
564
|
+
":",
|
|
565
|
+
field("alternative", alternative($)),
|
|
566
|
+
),
|
|
567
|
+
];
|
|
538
568
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
569
|
+
if (name === "membership") {
|
|
570
|
+
const left = member(classification, name);
|
|
571
|
+
return ($) => [
|
|
572
|
+
seq(
|
|
573
|
+
field("left", left($)),
|
|
574
|
+
$._membership_operator,
|
|
575
|
+
field("right", $.name),
|
|
576
|
+
),
|
|
577
|
+
...(classification === "non_unary"
|
|
578
|
+
? [
|
|
579
|
+
seq(
|
|
580
|
+
"(",
|
|
581
|
+
field("left", localNode($, "multiple_expr_list")),
|
|
582
|
+
")",
|
|
583
|
+
$._membership_operator,
|
|
584
|
+
field("right", $.name),
|
|
585
|
+
),
|
|
586
|
+
]
|
|
587
|
+
: []),
|
|
588
|
+
];
|
|
589
|
+
}
|
|
590
|
+
if (name === "concatenation") {
|
|
591
|
+
const left = member(classification, name);
|
|
592
|
+
const right = member("non_unary", next);
|
|
593
|
+
return ($) => [seq(field("left", left($)), field("right", right($)))];
|
|
594
|
+
}
|
|
595
|
+
if (name === "unary") {
|
|
596
|
+
const operand = any(name);
|
|
597
|
+
return ($) => [
|
|
548
598
|
seq(
|
|
549
|
-
field("left", $._lvalue),
|
|
550
599
|
field(
|
|
551
600
|
"operator",
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
$.
|
|
555
|
-
$.mul_assign,
|
|
556
|
-
$.div_assign,
|
|
557
|
-
$.add_assign,
|
|
558
|
-
$.sub_assign,
|
|
559
|
-
"=",
|
|
560
|
-
),
|
|
601
|
+
classification === "unary"
|
|
602
|
+
? choice(signOperator($, "+"), signOperator($, "-"))
|
|
603
|
+
: alias($._not_operator, "!"),
|
|
561
604
|
),
|
|
562
|
-
field("
|
|
605
|
+
field("operand", operand($)),
|
|
563
606
|
),
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
for (const classification of CLASSIFICATIONS) {
|
|
569
|
-
addOperand(classification, "logical_or");
|
|
570
|
-
rules[classTierName(context, classification, "conditional")] = ($) =>
|
|
571
|
-
choice(
|
|
572
|
-
classTier($, context, classification, "logical_or"),
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
if (name === "postfix") {
|
|
610
|
+
return ($) => [
|
|
573
611
|
seq(
|
|
574
|
-
field(
|
|
575
|
-
|
|
576
|
-
aliasedClassTier($, context, classification, "logical_or"),
|
|
577
|
-
),
|
|
578
|
-
$[conditionalTail],
|
|
612
|
+
field("operand", alias($.local_postfix_lvalue, $.lvalue)),
|
|
613
|
+
field("operator", choice($.incr, $.decr)),
|
|
579
614
|
),
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
addBinaryTier("logical_or", ($) => $._logical_or_operator, {
|
|
584
|
-
newlineAfterOperator: true,
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
addBinaryTier("logical_and", ($) => $._logical_and_operator, {
|
|
588
|
-
newlineAfterOperator: true,
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
const membershipTail = `_${context.prefix}_membership_tail`;
|
|
592
|
-
rules[membershipTail] = ($) =>
|
|
593
|
-
seq($._membership_operator, field("right", $.name));
|
|
594
|
-
for (const classification of CLASSIFICATIONS) {
|
|
595
|
-
rules[classTierName(context, classification, "membership")] = ($) => {
|
|
596
|
-
const members = [
|
|
597
|
-
classTier($, context, classification, "match"),
|
|
598
|
-
bind(
|
|
599
|
-
EXPRESSION.membership,
|
|
600
|
-
seq(
|
|
601
|
-
field(
|
|
602
|
-
"left",
|
|
603
|
-
aliasedClassTier($, context, classification, "membership"),
|
|
604
|
-
),
|
|
605
|
-
$[membershipTail],
|
|
606
|
-
),
|
|
615
|
+
seq(
|
|
616
|
+
field("operator", choice($.incr, $.decr)),
|
|
617
|
+
field("operand", localNode($, "lvalue")),
|
|
607
618
|
),
|
|
608
619
|
];
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
620
|
+
}
|
|
621
|
+
const left = member(
|
|
622
|
+
classification,
|
|
623
|
+
EXPRESSION[name].associativity === "left" ? name : next,
|
|
624
|
+
);
|
|
625
|
+
const right = any(EXPRESSION[name].rightOperand ?? next);
|
|
626
|
+
return ($) => [
|
|
627
|
+
seq(
|
|
628
|
+
field("left", left($)),
|
|
629
|
+
field("operator", oneOf(binaryOperators($)[name])),
|
|
630
|
+
...(name === "logical_or" || name === "logical_and"
|
|
631
|
+
? [newlineLayout($)]
|
|
632
|
+
: []),
|
|
633
|
+
field("right", right($)),
|
|
634
|
+
),
|
|
635
|
+
];
|
|
636
|
+
};
|
|
637
|
+
const tierRules = {};
|
|
638
|
+
for (const classification of ["unary", "non_unary"]) {
|
|
639
|
+
for (const [index, name] of tiers.entries()) {
|
|
640
|
+
if (!classifications(name).includes(classification)) continue;
|
|
641
|
+
const next = tiers[index + 1] ?? "atom";
|
|
642
|
+
const operations = tierOperations(classification, name, next);
|
|
643
|
+
const fallback = name !== "unary" || classification !== "unary";
|
|
644
|
+
tierRules[tier(classification, name)] = ($) =>
|
|
645
|
+
oneOf([
|
|
646
|
+
...(fallback ? [$[tier(classification, next)]] : []),
|
|
647
|
+
...operations($),
|
|
648
|
+
]);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const assignments = ["unary", "non_unary"].map((classification) =>
|
|
652
|
+
member(classification, "assignment"),
|
|
653
|
+
);
|
|
654
|
+
for (const name of [...tiers, "atom"]) {
|
|
655
|
+
for (const classification of classifications(name)) {
|
|
656
|
+
if (referenced.has(operand(classification, name)))
|
|
657
|
+
localRules[operand(classification, name)] = ($) =>
|
|
658
|
+
prec(
|
|
659
|
+
EXPRESSION[name]?.precedence ?? EXPRESSION.field.precedence,
|
|
660
|
+
$[tier(classification, name)],
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
if (referenced.has(union(name)))
|
|
664
|
+
localRules[union(name)] = ($) =>
|
|
665
|
+
choice(
|
|
666
|
+
...classifications(name).map((classification) =>
|
|
667
|
+
classified(classification, name)($),
|
|
615
668
|
),
|
|
616
669
|
);
|
|
617
|
-
}
|
|
618
|
-
return choice(...members);
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
addBinaryTier("match", ($) => $._match_operator);
|
|
623
|
-
|
|
624
|
-
if (context.comparison) {
|
|
625
|
-
addBinaryTier("comparison", ($) => $._comparison_operator);
|
|
626
670
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
671
|
+
Object.assign(localRules, tierRules);
|
|
672
|
+
localRules[tier("non_unary", "atom")] = ($) => localAtoms($, print);
|
|
673
|
+
localRules[`local_${prefix}expr`] = ($) =>
|
|
674
|
+
choice(...assignments.map((assignment) => assignment($)));
|
|
675
|
+
}
|
|
676
|
+
Object.assign(localRules, {
|
|
677
|
+
_local_atom: ($) =>
|
|
678
|
+
choice(
|
|
679
|
+
$.number,
|
|
680
|
+
$.string,
|
|
681
|
+
$.ere,
|
|
682
|
+
$.builtin_func_name,
|
|
683
|
+
seq("(", localNode($, "expr"), ")"),
|
|
684
|
+
prec(
|
|
685
|
+
1,
|
|
686
|
+
seq(
|
|
687
|
+
choice($.func_name, $.builtin_func_name),
|
|
688
|
+
"(",
|
|
689
|
+
optional(localNode($, "expr_list")),
|
|
690
|
+
")",
|
|
691
|
+
),
|
|
692
|
+
),
|
|
693
|
+
),
|
|
694
|
+
local_lvalue: ($) =>
|
|
695
|
+
choice(
|
|
696
|
+
seq($.name, optional(seq("[", localNode($, "expr_list"), "]"))),
|
|
697
|
+
seq(
|
|
698
|
+
field("operator", alias($._field_operator, "$")),
|
|
699
|
+
field("operand", alias($.local_field_expr, $.expr)),
|
|
700
|
+
),
|
|
701
|
+
),
|
|
702
|
+
local_postfix_lvalue: ($) =>
|
|
703
|
+
prec(
|
|
704
|
+
1,
|
|
640
705
|
choice(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
field(
|
|
646
|
-
"left",
|
|
647
|
-
aliasedClassTier($, context, classification, "concatenation"),
|
|
648
|
-
),
|
|
649
|
-
$[concatenationTail],
|
|
650
|
-
),
|
|
706
|
+
seq($.name, optional(seq("[", localNode($, "expr_list"), "]"))),
|
|
707
|
+
seq(
|
|
708
|
+
field("operator", alias($._field_operator, "$")),
|
|
709
|
+
field("operand", alias($.local_postfix_field_expr, $.expr)),
|
|
651
710
|
),
|
|
652
|
-
)
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
711
|
+
),
|
|
712
|
+
),
|
|
713
|
+
local_postfix_field_expr: ($) =>
|
|
714
|
+
alias($.local_postfix_field_atom, $.non_unary_expr),
|
|
715
|
+
local_postfix_field_atom: ($) =>
|
|
716
|
+
prec(1, localAtoms($, false, alias($.local_postfix_lvalue, $.lvalue))),
|
|
717
|
+
local_field_expr: ($) =>
|
|
718
|
+
choice(
|
|
719
|
+
alias($.local_unary_unary, $.unary_expr),
|
|
720
|
+
alias($.local_field_non_unary, $.non_unary_expr),
|
|
721
|
+
),
|
|
722
|
+
local_field_non_unary: ($) =>
|
|
723
|
+
choice(
|
|
724
|
+
$._local_non_unary_atom,
|
|
725
|
+
seq(
|
|
726
|
+
field("operator", alias($._not_operator, "!")),
|
|
727
|
+
field("operand", alias($.local_unary, $.expr)),
|
|
728
|
+
),
|
|
729
|
+
seq(
|
|
730
|
+
field("operator", choice($.incr, $.decr)),
|
|
731
|
+
field("operand", localNode($, "lvalue")),
|
|
732
|
+
),
|
|
733
|
+
),
|
|
734
|
+
local_expr_list: ($) =>
|
|
735
|
+
choice(localNode($, "expr"), localNode($, "multiple_expr_list")),
|
|
736
|
+
local_multiple_expr_list: ($) =>
|
|
737
|
+
seq(
|
|
738
|
+
localNode($, "expr"),
|
|
739
|
+
repeat1(listElementTail($, localNode($, "expr"))),
|
|
740
|
+
),
|
|
741
|
+
local_non_unary_input_function: ($) =>
|
|
742
|
+
field("get", localNode($, "simple_get")),
|
|
743
|
+
local_simple_get: ($) =>
|
|
744
|
+
prec.right(
|
|
745
|
+
EXPRESSION.field.precedence,
|
|
746
|
+
seq($.getline_keyword, optional(field("target", localNode($, "lvalue")))),
|
|
747
|
+
),
|
|
748
|
+
});
|
|
664
749
|
|
|
665
|
-
|
|
750
|
+
const definition = {
|
|
666
751
|
name: "posix_awk",
|
|
667
752
|
|
|
668
753
|
externals: ($) => [
|
|
754
|
+
...boundaryExternals($),
|
|
669
755
|
$._getline_word,
|
|
670
|
-
$._getline_target_word,
|
|
671
|
-
$._getline_omitted_word,
|
|
672
|
-
$._getline_field_word,
|
|
673
|
-
$._getline_prefer_target_word,
|
|
674
|
-
$._getline_prefer_omitted_word,
|
|
675
756
|
$._func_name_word,
|
|
676
757
|
$._division_slash,
|
|
677
758
|
$._ere_opening_slash,
|
|
@@ -679,6 +760,8 @@ export default globalThis.grammar?.({
|
|
|
679
760
|
$._decr_operator,
|
|
680
761
|
$._plus_operator,
|
|
681
762
|
$._minus_operator,
|
|
763
|
+
$._field_operator,
|
|
764
|
+
$._not_operator,
|
|
682
765
|
$._getline_pipe,
|
|
683
766
|
$._ere_compound_opening,
|
|
684
767
|
$._ere_escaped_compound_opening,
|
|
@@ -727,62 +810,19 @@ export default globalThis.grammar?.({
|
|
|
727
810
|
],
|
|
728
811
|
|
|
729
812
|
inline: ($) => [
|
|
730
|
-
// Shared operator reductions can freeze reused operands after edits.
|
|
731
|
-
$._additive_operator,
|
|
732
|
-
$._multiplicative_operator,
|
|
733
|
-
$._exponentiation_operator,
|
|
734
|
-
$._comparison_operator,
|
|
735
|
-
$._match_operator,
|
|
736
|
-
$._membership_operator,
|
|
737
|
-
$._logical_and_operator,
|
|
738
|
-
$._logical_or_operator,
|
|
739
|
-
$._lvalue,
|
|
740
|
-
$._field_simple_get,
|
|
741
813
|
$._item,
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
$._print_non_unary_update_expr,
|
|
747
|
-
$._field_non_unary_update_expr,
|
|
748
|
-
$._normal_unary_assignment_expr,
|
|
749
|
-
$._normal_unary_update_expr,
|
|
750
|
-
$._print_unary_assignment_expr,
|
|
751
|
-
$._source_non_unary_update_expr,
|
|
752
|
-
$._source_unary_assignment_expr,
|
|
753
|
-
$._source_unary_update_expr,
|
|
754
|
-
$._source_conditional_tail,
|
|
755
|
-
],
|
|
756
|
-
|
|
757
|
-
conflicts: ($) => [
|
|
758
|
-
[$._for_in_clause, $.postfix_lvalue],
|
|
759
|
-
[$.item_list, $._item_list],
|
|
760
|
-
[$.simple_get],
|
|
761
|
-
[$.source_simple_get],
|
|
814
|
+
$._membership_operator,
|
|
815
|
+
...Object.keys(localRules)
|
|
816
|
+
.filter((name) => name.startsWith("_") && name !== "_local_atom")
|
|
817
|
+
.map((name) => $[name]),
|
|
762
818
|
],
|
|
819
|
+
conflicts: ($) => [[$.item_list, $._item_list]],
|
|
763
820
|
|
|
764
821
|
rules: {
|
|
765
822
|
program: ($) => seq(optional($.item_list), optional($._item)),
|
|
766
823
|
|
|
767
|
-
_additive_operator: ($) =>
|
|
768
|
-
field("operator", choice(signOperator($, "+"), signOperator($, "-"))),
|
|
769
|
-
|
|
770
|
-
_multiplicative_operator: ($) =>
|
|
771
|
-
field("operator", choice("*", alias($._division_slash, "/"), "%")),
|
|
772
|
-
|
|
773
|
-
_exponentiation_operator: () => field("operator", "^"),
|
|
774
|
-
|
|
775
|
-
_comparison_operator: ($) =>
|
|
776
|
-
field("operator", choice("<", $.le, $.ne, $.eq, ">", $.ge)),
|
|
777
|
-
|
|
778
|
-
_match_operator: ($) => field("operator", choice("~", $.no_match)),
|
|
779
|
-
|
|
780
824
|
_membership_operator: ($) => field("operator", $.in_keyword),
|
|
781
825
|
|
|
782
|
-
_logical_and_operator: ($) => field("operator", $.and),
|
|
783
|
-
|
|
784
|
-
_logical_or_operator: ($) => field("operator", $.or),
|
|
785
|
-
|
|
786
826
|
item_list: ($) => $._item_list,
|
|
787
827
|
|
|
788
828
|
_item_list: ($) =>
|
|
@@ -877,7 +917,12 @@ export default globalThis.grammar?.({
|
|
|
877
917
|
),
|
|
878
918
|
|
|
879
919
|
_for_in_clause: ($) =>
|
|
880
|
-
seq(
|
|
920
|
+
seq(
|
|
921
|
+
$._for_in,
|
|
922
|
+
field("variable", $.name),
|
|
923
|
+
$.in_keyword,
|
|
924
|
+
field("array", $.name),
|
|
925
|
+
),
|
|
881
926
|
|
|
882
927
|
_for_header: ($) =>
|
|
883
928
|
header(
|
|
@@ -929,7 +974,7 @@ export default globalThis.grammar?.({
|
|
|
929
974
|
seq(
|
|
930
975
|
$.delete_keyword,
|
|
931
976
|
field("array", $.name),
|
|
932
|
-
optional(
|
|
977
|
+
optional(seq("[", field("subscripts", $.expr_list), "]")),
|
|
933
978
|
),
|
|
934
979
|
$.expr,
|
|
935
980
|
$.print_statement,
|
|
@@ -958,242 +1003,6 @@ export default globalThis.grammar?.({
|
|
|
958
1003
|
|
|
959
1004
|
multiple_expr_list: ($) => seq($.expr, repeat1(listElementTail($, $.expr))),
|
|
960
1005
|
|
|
961
|
-
print_expr: ($) => choice($.unary_print_expr, $.non_unary_print_expr),
|
|
962
|
-
|
|
963
|
-
unary_print_expr: ($) => $._print_unary_assignment_expr,
|
|
964
|
-
|
|
965
|
-
non_unary_print_expr: ($) => $._print_non_unary_assignment_expr,
|
|
966
|
-
|
|
967
|
-
expr: ($) => choice($.unary_expr, $.non_unary_expr),
|
|
968
|
-
|
|
969
|
-
unary_expr: ($) => $._normal_unary_assignment_expr,
|
|
970
|
-
|
|
971
|
-
non_unary_expr: ($) => $._normal_non_unary_assignment_expr,
|
|
972
|
-
|
|
973
|
-
_prefix_update_expr: ($) =>
|
|
974
|
-
seq(
|
|
975
|
-
field("operator", choice($.incr, $.decr)),
|
|
976
|
-
field("operand", choice($._lvalue, alias($.prefix_field, $.lvalue))),
|
|
977
|
-
),
|
|
978
|
-
|
|
979
|
-
...tieredExpressionRules(EXPRESSION_CONTEXT.normal),
|
|
980
|
-
|
|
981
|
-
source_expr: ($) =>
|
|
982
|
-
choice(
|
|
983
|
-
alias($.source_full_unary_expr, $.unary_expr),
|
|
984
|
-
alias($.source_full_non_unary_expr, $.non_unary_expr),
|
|
985
|
-
),
|
|
986
|
-
|
|
987
|
-
source_full_unary_expr: ($) => $._source_unary_assignment_expr,
|
|
988
|
-
|
|
989
|
-
source_full_non_unary_expr: ($) => $._source_non_unary_assignment_expr,
|
|
990
|
-
|
|
991
|
-
...tieredExpressionRules(EXPRESSION_CONTEXT.source),
|
|
992
|
-
|
|
993
|
-
...tieredExpressionRules(EXPRESSION_CONTEXT.print),
|
|
994
|
-
|
|
995
|
-
...unaryExpressionRules(EXPRESSION_CONTEXT.field),
|
|
996
|
-
|
|
997
|
-
nonpostfix_field_expr: ($) =>
|
|
998
|
-
choice(
|
|
999
|
-
alias($.normal_unary_field_expr, $.unary_expr),
|
|
1000
|
-
alias($.nonpostfix_non_unary_field_expr, $.non_unary_expr),
|
|
1001
|
-
),
|
|
1002
|
-
|
|
1003
|
-
normal_unary_field_expr: ($) =>
|
|
1004
|
-
prec(EXPRESSION.field.precedence, $._field_unary_unary_expr),
|
|
1005
|
-
|
|
1006
|
-
nonpostfix_non_unary_field_expr: ($) =>
|
|
1007
|
-
prec(
|
|
1008
|
-
EXPRESSION.field.precedence,
|
|
1009
|
-
choice(
|
|
1010
|
-
$._field_not_expr,
|
|
1011
|
-
$._prefix_update_expr,
|
|
1012
|
-
alias($.nonpostfix_lvalue, $.lvalue),
|
|
1013
|
-
alias($.nonpostfix_field_input_function, $.non_unary_input_function),
|
|
1014
|
-
),
|
|
1015
|
-
),
|
|
1016
|
-
|
|
1017
|
-
_parenthesized_expression: ($) => parenthesized($.expr),
|
|
1018
|
-
|
|
1019
|
-
_user_function_call: ($) => seq($.func_name, callArguments($)),
|
|
1020
|
-
|
|
1021
|
-
_builtin_function_call: ($) =>
|
|
1022
|
-
prec(
|
|
1023
|
-
EXPRESSION.field.precedence + 1,
|
|
1024
|
-
seq($.builtin_func_name, callArguments($)),
|
|
1025
|
-
),
|
|
1026
|
-
|
|
1027
|
-
_lvalue: ($) =>
|
|
1028
|
-
choice(
|
|
1029
|
-
alias($.postfix_lvalue, $.lvalue),
|
|
1030
|
-
alias($.nonpostfix_lvalue, $.lvalue),
|
|
1031
|
-
),
|
|
1032
|
-
|
|
1033
|
-
nonpostfix_lvalue: ($) =>
|
|
1034
|
-
seq(
|
|
1035
|
-
field("operator", "$"),
|
|
1036
|
-
field("operand", alias($.nonpostfix_field_expr, $.expr)),
|
|
1037
|
-
),
|
|
1038
|
-
|
|
1039
|
-
postfix_lvalue: ($) =>
|
|
1040
|
-
choice(
|
|
1041
|
-
seq($.name, optional(subscript($.expr_list))),
|
|
1042
|
-
seq(
|
|
1043
|
-
field("operator", "$"),
|
|
1044
|
-
field("operand", alias($.postfix_field_expr, $.expr)),
|
|
1045
|
-
),
|
|
1046
|
-
),
|
|
1047
|
-
|
|
1048
|
-
postfix_field_expr: ($) =>
|
|
1049
|
-
alias($.postfix_non_unary_field_expr, $.non_unary_expr),
|
|
1050
|
-
|
|
1051
|
-
postfix_non_unary_field_expr: ($) =>
|
|
1052
|
-
prec(
|
|
1053
|
-
EXPRESSION.field.precedence,
|
|
1054
|
-
nonUnaryAtom(
|
|
1055
|
-
$,
|
|
1056
|
-
{
|
|
1057
|
-
...EXPRESSION_CONTEXT.field,
|
|
1058
|
-
input: ($) =>
|
|
1059
|
-
alias($.postfix_field_input_function, $.non_unary_input_function),
|
|
1060
|
-
},
|
|
1061
|
-
alias($.postfix_lvalue, $.lvalue),
|
|
1062
|
-
),
|
|
1063
|
-
),
|
|
1064
|
-
|
|
1065
|
-
prefix_field: ($) =>
|
|
1066
|
-
seq(
|
|
1067
|
-
field("operator", "$"),
|
|
1068
|
-
field("operand", alias($.prefix_field_expr, $.expr)),
|
|
1069
|
-
),
|
|
1070
|
-
|
|
1071
|
-
prefix_field_expr: ($) =>
|
|
1072
|
-
alias($.prefix_non_unary_field_expr, $.non_unary_expr),
|
|
1073
|
-
|
|
1074
|
-
prefix_non_unary_field_expr: ($) =>
|
|
1075
|
-
prec(
|
|
1076
|
-
EXPRESSION.field.precedence,
|
|
1077
|
-
choice(
|
|
1078
|
-
alias($.direct_input_function, $.non_unary_input_function),
|
|
1079
|
-
alias($.prefix_field, $.lvalue),
|
|
1080
|
-
),
|
|
1081
|
-
),
|
|
1082
|
-
|
|
1083
|
-
redirected_field: ($) =>
|
|
1084
|
-
seq(
|
|
1085
|
-
field("operator", "$"),
|
|
1086
|
-
field("operand", alias($.redirected_field_expr, $.expr)),
|
|
1087
|
-
),
|
|
1088
|
-
|
|
1089
|
-
redirected_field_expr: ($) =>
|
|
1090
|
-
alias($.redirected_non_unary_field_expr, $.non_unary_expr),
|
|
1091
|
-
|
|
1092
|
-
redirected_non_unary_field_expr: ($) =>
|
|
1093
|
-
prec(
|
|
1094
|
-
EXPRESSION.field.precedence,
|
|
1095
|
-
choice(
|
|
1096
|
-
alias($.redirected_field_input_function, $.non_unary_input_function),
|
|
1097
|
-
alias($.redirected_field, $.lvalue),
|
|
1098
|
-
),
|
|
1099
|
-
),
|
|
1100
|
-
|
|
1101
|
-
redirected_field_input_function: ($) =>
|
|
1102
|
-
choice(
|
|
1103
|
-
prec(1, $._redirected_field_input),
|
|
1104
|
-
field("get", alias($.redirected_field_simple_get, $.simple_get)),
|
|
1105
|
-
),
|
|
1106
|
-
|
|
1107
|
-
redirected_field_simple_get: ($) =>
|
|
1108
|
-
seq(
|
|
1109
|
-
alias($.field_getline_keyword, $.getline_keyword),
|
|
1110
|
-
field("target", alias($.redirected_field, $.lvalue)),
|
|
1111
|
-
),
|
|
1112
|
-
|
|
1113
|
-
_redirected_field_input: ($) =>
|
|
1114
|
-
redirectedInput($, $._field_simple_get, alias($.source_expr, $.expr)),
|
|
1115
|
-
|
|
1116
|
-
nonpostfix_field_input_function: ($) =>
|
|
1117
|
-
choice(
|
|
1118
|
-
field("get", alias($.nonpostfix_field_simple_get, $.simple_get)),
|
|
1119
|
-
$._redirected_field_input,
|
|
1120
|
-
),
|
|
1121
|
-
|
|
1122
|
-
postfix_field_input_function: ($) =>
|
|
1123
|
-
field("get", alias($.postfix_field_simple_get, $.simple_get)),
|
|
1124
|
-
|
|
1125
|
-
_field_simple_get: ($) =>
|
|
1126
|
-
choice(
|
|
1127
|
-
alias($.postfix_field_simple_get, $.simple_get),
|
|
1128
|
-
alias($.nonpostfix_field_simple_get, $.simple_get),
|
|
1129
|
-
),
|
|
1130
|
-
|
|
1131
|
-
nonpostfix_field_simple_get: ($) =>
|
|
1132
|
-
seq(
|
|
1133
|
-
alias($.field_getline_keyword, $.getline_keyword),
|
|
1134
|
-
field("target", alias($.nonpostfix_lvalue, $.lvalue)),
|
|
1135
|
-
),
|
|
1136
|
-
|
|
1137
|
-
postfix_field_simple_get: ($) =>
|
|
1138
|
-
choice(
|
|
1139
|
-
prec(-1, alias($.field_getline_keyword, $.getline_keyword)),
|
|
1140
|
-
seq(
|
|
1141
|
-
alias($.field_getline_keyword, $.getline_keyword),
|
|
1142
|
-
field("target", alias($.postfix_lvalue, $.lvalue)),
|
|
1143
|
-
),
|
|
1144
|
-
),
|
|
1145
|
-
|
|
1146
|
-
direct_input_function: ($) =>
|
|
1147
|
-
choice(field("get", $.simple_get), redirectedInput($, $.simple_get)),
|
|
1148
|
-
|
|
1149
|
-
source_direct_input_function: ($) =>
|
|
1150
|
-
choice(
|
|
1151
|
-
field("get", alias($.source_simple_get, $.simple_get)),
|
|
1152
|
-
redirectedInput(
|
|
1153
|
-
$,
|
|
1154
|
-
alias($.source_simple_get, $.simple_get),
|
|
1155
|
-
alias($.source_expr, $.expr),
|
|
1156
|
-
),
|
|
1157
|
-
),
|
|
1158
|
-
|
|
1159
|
-
source_piped_input_function: ($) =>
|
|
1160
|
-
pipedInput(
|
|
1161
|
-
$,
|
|
1162
|
-
alias($.source_full_non_unary_expr, $.non_unary_expr),
|
|
1163
|
-
alias($.source_simple_get, $.simple_get),
|
|
1164
|
-
),
|
|
1165
|
-
|
|
1166
|
-
source_unary_input_function: ($) =>
|
|
1167
|
-
pipedInput(
|
|
1168
|
-
$,
|
|
1169
|
-
alias($.source_full_unary_expr, $.unary_expr),
|
|
1170
|
-
alias($.source_simple_get, $.simple_get),
|
|
1171
|
-
),
|
|
1172
|
-
|
|
1173
|
-
piped_input_function: ($) => pipedInput($, $.non_unary_expr, $.simple_get),
|
|
1174
|
-
|
|
1175
|
-
unary_input_function: ($) => pipedInput($, $.unary_expr, $.simple_get),
|
|
1176
|
-
|
|
1177
|
-
simple_get: ($) => simpleGet($),
|
|
1178
|
-
|
|
1179
|
-
source_simple_get: ($) => simpleGet($, true),
|
|
1180
|
-
|
|
1181
|
-
trailing_incr: () => "++",
|
|
1182
|
-
|
|
1183
|
-
trailing_decr: () => "--",
|
|
1184
|
-
|
|
1185
|
-
getline_keyword: ($) => $._getline_word,
|
|
1186
|
-
|
|
1187
|
-
target_getline_keyword: ($) => $._getline_target_word,
|
|
1188
|
-
|
|
1189
|
-
omitted_getline_keyword: ($) => $._getline_omitted_word,
|
|
1190
|
-
|
|
1191
|
-
field_getline_keyword: ($) => $._getline_field_word,
|
|
1192
|
-
|
|
1193
|
-
preferred_target_getline_keyword: ($) => $._getline_prefer_target_word,
|
|
1194
|
-
|
|
1195
|
-
preferred_omitted_getline_keyword: ($) => $._getline_prefer_omitted_word,
|
|
1196
|
-
|
|
1197
1006
|
...Object.fromEntries(
|
|
1198
1007
|
[...RESERVED_WORDS.keyword, ...RESERVED_WORDS.membership].map(
|
|
1199
1008
|
(keyword) => [`${keyword.toLowerCase()}_keyword`, () => keyword],
|
|
@@ -1462,5 +1271,30 @@ export default globalThis.grammar?.({
|
|
|
1462
1271
|
terminator: ($) => choice(rawNewlines($), seq(";", repeat($.newline))),
|
|
1463
1272
|
|
|
1464
1273
|
newline: () => "\n",
|
|
1274
|
+
...boundaryRules,
|
|
1275
|
+
...localRules,
|
|
1276
|
+
expr: ($) =>
|
|
1277
|
+
choice(
|
|
1278
|
+
seq($._root, $._boundary_expr),
|
|
1279
|
+
seq($._local_root, alias($.local_unary_assignment, $.unary_expr)),
|
|
1280
|
+
seq(
|
|
1281
|
+
$._local_root,
|
|
1282
|
+
alias($.local_non_unary_assignment, $.non_unary_expr),
|
|
1283
|
+
),
|
|
1284
|
+
),
|
|
1285
|
+
print_expr: ($) =>
|
|
1286
|
+
choice(
|
|
1287
|
+
seq($._print_root, $._boundary_print_expr),
|
|
1288
|
+
seq(
|
|
1289
|
+
$._local_print_root,
|
|
1290
|
+
alias($.local_print_unary_assignment, $.unary_print_expr),
|
|
1291
|
+
),
|
|
1292
|
+
seq(
|
|
1293
|
+
$._local_print_root,
|
|
1294
|
+
alias($.local_print_non_unary_assignment, $.non_unary_print_expr),
|
|
1295
|
+
),
|
|
1296
|
+
),
|
|
1465
1297
|
},
|
|
1466
|
-
}
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
export default globalThis.grammar?.(definition);
|