bare-script 3.5.2 → 3.5.4
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/lib/parser.js +26 -17
- package/package.json +1 -1
package/lib/parser.js
CHANGED
|
@@ -450,27 +450,30 @@ const rScriptLineSplit = /\r?\n/;
|
|
|
450
450
|
const rScriptContinuation = /\\\s*$/;
|
|
451
451
|
const rScriptComment = /^\s*(?:#.*)?$/;
|
|
452
452
|
const rScriptAssignment = /^\s*(?<name>[A-Za-z_]\w*)\s*=\s*(?<expr>.+)$/;
|
|
453
|
+
const rPartComment = '\\s*(#.*)?$';
|
|
453
454
|
const rScriptFunctionBegin = new RegExp(
|
|
454
455
|
'^(?<async>\\s*async)?\\s*function\\s+(?<name>[A-Za-z_]\\w*)\\s*\\(' +
|
|
455
|
-
|
|
456
|
+
`\\s*(?<args>[A-Za-z_]\\w*(?:\\s*,\\s*[A-Za-z_]\\w*)*)?(?<lastArgArray>\\s*\\.\\.\\.)?\\s*\\)\\s*:${rPartComment}`
|
|
456
457
|
);
|
|
457
458
|
const rScriptFunctionArgSplit = /\s*,\s*/;
|
|
458
|
-
const rScriptFunctionEnd =
|
|
459
|
-
const rScriptLabel =
|
|
460
|
-
const rScriptJump =
|
|
461
|
-
const rScriptReturn =
|
|
462
|
-
const rScriptInclude =
|
|
463
|
-
const rScriptIncludeSystem =
|
|
464
|
-
const rScriptIfBegin =
|
|
465
|
-
const rScriptIfElseIf =
|
|
466
|
-
const rScriptIfElse =
|
|
467
|
-
const rScriptIfEnd =
|
|
468
|
-
const rScriptForBegin =
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
const
|
|
459
|
+
const rScriptFunctionEnd = new RegExp(`^\\s*endfunction${rPartComment}`);
|
|
460
|
+
const rScriptLabel = new RegExp(`^\\s*(?<name>[A-Za-z_]\\w*)\\s*:${rPartComment}`);
|
|
461
|
+
const rScriptJump = new RegExp(`^(?<jump>\\s*(?:jump|jumpif\\s*\\((?<expr>.+)\\)))\\s+(?<name>[A-Za-z_]\\w*)${rPartComment}`);
|
|
462
|
+
const rScriptReturn = new RegExp(`^(?<return>\\s*return(?:\\s+(?<expr>[^#\\s].*))?)${rPartComment}`);
|
|
463
|
+
const rScriptInclude = new RegExp(`^\\s*include\\s+(?<delim>')(?<url>(?:\\'|[^'])*)'${rPartComment}`);
|
|
464
|
+
const rScriptIncludeSystem = new RegExp(`^\\s*include\\s+(?<delim><)(?<url>[^>]*)>${rPartComment}`);
|
|
465
|
+
const rScriptIfBegin = new RegExp(`^\\s*if\\s+(?<expr>.+)\\s*:${rPartComment}`);
|
|
466
|
+
const rScriptIfElseIf = new RegExp(`^\\s*elif\\s+(?<expr>.+)\\s*:${rPartComment}`);
|
|
467
|
+
const rScriptIfElse = new RegExp(`^\\s*else\\s*:${rPartComment}`);
|
|
468
|
+
const rScriptIfEnd = new RegExp(`^\\s*endif${rPartComment}`);
|
|
469
|
+
const rScriptForBegin = new RegExp(
|
|
470
|
+
`^\\s*for\\s+(?<value>[A-Za-z_]\\w*)(?:\\s*,\\s*(?<index>[A-Za-z_]\\w*))?\\s+in\\s+(?<values>.+)\\s*:${rPartComment}`
|
|
471
|
+
);
|
|
472
|
+
const rScriptForEnd = new RegExp(`^\\s*endfor${rPartComment}`);
|
|
473
|
+
const rScriptWhileBegin = new RegExp(`^\\s*while\\s+(?<expr>.+)\\s*:${rPartComment}`);
|
|
474
|
+
const rScriptWhileEnd = new RegExp(`^\\s*endwhile${rPartComment}`);
|
|
475
|
+
const rScriptBreak = new RegExp(`^\\s*break${rPartComment}`);
|
|
476
|
+
const rScriptContinue = new RegExp(`^\\s*continue${rPartComment}`);
|
|
474
477
|
|
|
475
478
|
|
|
476
479
|
/**
|
|
@@ -509,6 +512,11 @@ function parseBinaryExpression(exprText, binLeftExpr = null) {
|
|
|
509
512
|
// Match a binary operator - if not found, return the left expression
|
|
510
513
|
const matchBinaryOp = binText.match(rExprBinaryOp);
|
|
511
514
|
if (matchBinaryOp === null) {
|
|
515
|
+
// End-of-line comment?
|
|
516
|
+
if (binText.match(rExprComment)) {
|
|
517
|
+
binText = '';
|
|
518
|
+
}
|
|
519
|
+
|
|
512
520
|
return [leftExpr, binText];
|
|
513
521
|
}
|
|
514
522
|
const [, binOp] = matchBinaryOp;
|
|
@@ -671,6 +679,7 @@ function parseUnaryExpression(exprText) {
|
|
|
671
679
|
|
|
672
680
|
|
|
673
681
|
// BareScript expression regex
|
|
682
|
+
const rExprComment = /^\s*#.*$/;
|
|
674
683
|
const rExprBinaryOp = /^\s*(\*\*|\*|\/|%|\+|-|<<|>>|<=|<|>=|>|==|!=|&&|\|\||&|\^|\|)/;
|
|
675
684
|
const rExprUnaryOp = /^\s*(!|-|~)/;
|
|
676
685
|
const rExprFunctionOpen = /^\s*([A-Za-z_]\w+)\s*\(/;
|