bare-script 3.5.2 → 3.5.3

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.
Files changed (2) hide show
  1. package/lib/parser.js +26 -17
  2. 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
- '\\s*(?<args>[A-Za-z_]\\w*(?:\\s*,\\s*[A-Za-z_]\\w*)*)?(?<lastArgArray>\\s*\\.\\.\\.)?\\s*\\)\\s*:\\s*$'
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 = /^\s*endfunction\s*$/;
459
- const rScriptLabel = /^\s*(?<name>[A-Za-z_]\w*)\s*:\s*$/;
460
- const rScriptJump = /^(?<jump>\s*(?:jump|jumpif\s*\((?<expr>.+)\)))\s+(?<name>[A-Za-z_]\w*)\s*$/;
461
- const rScriptReturn = /^(?<return>\s*return(?:\s+(?<expr>.+))?)\s*$/;
462
- const rScriptInclude = /^\s*include\s+(?<delim>')(?<url>(?:\\'|[^'])*)'\s*$/;
463
- const rScriptIncludeSystem = /^\s*include\s+(?<delim><)(?<url>[^>]*)>\s*$/;
464
- const rScriptIfBegin = /^\s*if\s+(?<expr>.+)\s*:\s*$/;
465
- const rScriptIfElseIf = /^\s*elif\s+(?<expr>.+)\s*:\s*$/;
466
- const rScriptIfElse = /^\s*else\s*:\s*$/;
467
- const rScriptIfEnd = /^\s*endif\s*$/;
468
- const rScriptForBegin = /^\s*for\s+(?<value>[A-Za-z_]\w*)(?:\s*,\s*(?<index>[A-Za-z_]\w*))?\s+in\s+(?<values>.+)\s*:\s*$/;
469
- const rScriptForEnd = /^\s*endfor\s*$/;
470
- const rScriptWhileBegin = /^\s*while\s+(?<expr>.+)\s*:\s*$/;
471
- const rScriptWhileEnd = /^\s*endwhile\s*$/;
472
- const rScriptBreak = /^\s*break\s*$/;
473
- const rScriptContinue = /^\s*continue\s*$/;
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>.+))?)${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*\(/;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "3.5.2",
4
+ "version": "3.5.3",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",