bare-script 3.7.1 → 3.7.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.
- package/lib/bare.js +4 -4
- package/lib/include/args.bare +14 -14
- package/lib/include/dataTable.bare +5 -5
- package/lib/include/diff.bare +11 -11
- package/lib/include/forms.bare +28 -28
- package/lib/include/markdownUp.bare +15 -15
- package/lib/include/pager.bare +12 -12
- package/lib/include/unittest.bare +62 -62
- package/lib/include/unittestMock.bare +34 -34
- package/lib/model.js +44 -24
- package/lib/parser.js +68 -27
- package/lib/runtimeAsync.js +1 -1
- package/package.json +1 -1
package/lib/parser.js
CHANGED
|
@@ -78,20 +78,25 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
78
78
|
// Assignment?
|
|
79
79
|
const matchAssignment = line.match(rScriptAssignment);
|
|
80
80
|
if (matchAssignment !== null) {
|
|
81
|
+
// Parse the expression
|
|
82
|
+
let assignmentExpr;
|
|
81
83
|
try {
|
|
82
|
-
|
|
83
|
-
'expr': {
|
|
84
|
-
'name': matchAssignment.groups.name,
|
|
85
|
-
'expr': parseExpression(matchAssignment.groups.expr, lineNumber, scriptName, true),
|
|
86
|
-
...statementBase
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
statements.push(exprStatement);
|
|
90
|
-
continue;
|
|
84
|
+
assignmentExpr = parseExpression(matchAssignment.groups.expr, lineNumber, scriptName, true);
|
|
91
85
|
} catch (error) {
|
|
92
86
|
const columnNumber = line.length - matchAssignment.groups.expr.length + error.columnNumber;
|
|
93
87
|
throw new BareScriptParserError(error.error, line, columnNumber, startLineNumber + ixLine, scriptName);
|
|
94
88
|
}
|
|
89
|
+
|
|
90
|
+
// Add the expression statement
|
|
91
|
+
const exprStatement = {
|
|
92
|
+
'expr': {
|
|
93
|
+
'name': matchAssignment.groups.name,
|
|
94
|
+
'expr': assignmentExpr,
|
|
95
|
+
...statementBase
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
statements.push(exprStatement);
|
|
99
|
+
continue;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
// Function definition begin?
|
|
@@ -147,11 +152,20 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
147
152
|
// If-then begin?
|
|
148
153
|
const matchIfBegin = line.match(rScriptIfBegin);
|
|
149
154
|
if (matchIfBegin !== null) {
|
|
155
|
+
// Parse the if-then expression
|
|
156
|
+
let ifthenExpr;
|
|
157
|
+
try {
|
|
158
|
+
ifthenExpr = parseExpression(matchIfBegin.groups.expr, lineNumber, scriptName, true);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
const columnNumber = matchIfBegin.groups.if.length + error.columnNumber;
|
|
161
|
+
throw new BareScriptParserError(error.error, line, columnNumber, startLineNumber + ixLine, scriptName);
|
|
162
|
+
}
|
|
163
|
+
|
|
150
164
|
// Add the if-then label definition
|
|
151
165
|
const ifthen = {
|
|
152
166
|
'jump': {
|
|
153
167
|
'label': `__bareScriptIf${labelIndex}`,
|
|
154
|
-
'expr': {'unary': {'op': '!', 'expr':
|
|
168
|
+
'expr': {'unary': {'op': '!', 'expr': ifthenExpr}},
|
|
155
169
|
...statementBase
|
|
156
170
|
},
|
|
157
171
|
'done': `__bareScriptDone${labelIndex}`,
|
|
@@ -170,7 +184,7 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
170
184
|
// Else-if-then?
|
|
171
185
|
const matchIfElseIf = line.match(rScriptIfElseIf);
|
|
172
186
|
if (matchIfElseIf !== null) {
|
|
173
|
-
// Get the if-then definition
|
|
187
|
+
// Get the else-if-then definition
|
|
174
188
|
const labelDefDepth = (functionDef !== null ? functionLabelDefDepth : 0);
|
|
175
189
|
const ifthen = (labelDefs.length > labelDefDepth ? (labelDefs[labelDefs.length - 1].if ?? null) : null);
|
|
176
190
|
if (ifthen === null) {
|
|
@@ -182,11 +196,20 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
182
196
|
throw new BareScriptParserError('Elif statement following else statement', line, 1, startLineNumber + ixLine, scriptName);
|
|
183
197
|
}
|
|
184
198
|
|
|
199
|
+
// Parse the else-if-then expression
|
|
200
|
+
let ifElseIfExpr;
|
|
201
|
+
try {
|
|
202
|
+
ifElseIfExpr = parseExpression(matchIfElseIf.groups.expr, lineNumber, scriptName, true);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const columnNumber = matchIfElseIf.groups.elif.length + error.columnNumber;
|
|
205
|
+
throw new BareScriptParserError(error.error, line, columnNumber, startLineNumber + ixLine, scriptName);
|
|
206
|
+
}
|
|
207
|
+
|
|
185
208
|
// Generate the next if-then jump statement
|
|
186
209
|
const prevLabel = ifthen.jump.label;
|
|
187
210
|
ifthen.jump = {
|
|
188
211
|
'label': `__bareScriptIf${labelIndex}`,
|
|
189
|
-
'expr': {'unary': {'op': '!', 'expr':
|
|
212
|
+
'expr': {'unary': {'op': '!', 'expr': ifElseIfExpr}},
|
|
190
213
|
...statementBase
|
|
191
214
|
};
|
|
192
215
|
labelIndex += 1;
|
|
@@ -247,12 +270,21 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
247
270
|
// While-do begin?
|
|
248
271
|
const matchWhileBegin = line.match(rScriptWhileBegin);
|
|
249
272
|
if (matchWhileBegin !== null) {
|
|
273
|
+
// Parse the while-do expression
|
|
274
|
+
let whileBeginExpr;
|
|
275
|
+
try {
|
|
276
|
+
whileBeginExpr = parseExpression(matchWhileBegin.groups.expr, lineNumber, scriptName, true);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
const columnNumber = matchWhileBegin.groups.while.length + error.columnNumber;
|
|
279
|
+
throw new BareScriptParserError(error.error, line, columnNumber, startLineNumber + ixLine, scriptName);
|
|
280
|
+
}
|
|
281
|
+
|
|
250
282
|
// Add the while-do label
|
|
251
283
|
const whiledo = {
|
|
252
284
|
'loop': `__bareScriptLoop${labelIndex}`,
|
|
253
285
|
'continue': `__bareScriptLoop${labelIndex}`,
|
|
254
286
|
'done': `__bareScriptDone${labelIndex}`,
|
|
255
|
-
'expr':
|
|
287
|
+
'expr': whileBeginExpr,
|
|
256
288
|
line,
|
|
257
289
|
'lineNumber': startLineNumber + ixLine
|
|
258
290
|
};
|
|
@@ -303,11 +335,20 @@ export function parseScript(scriptText, startLineNumber = 1, scriptName = null)
|
|
|
303
335
|
labelDefs.push({'for': foreach});
|
|
304
336
|
labelIndex += 1;
|
|
305
337
|
|
|
338
|
+
// Parse the for-each expression
|
|
339
|
+
let forBeginExpr;
|
|
340
|
+
try {
|
|
341
|
+
forBeginExpr = parseExpression(matchForBegin.groups.values, lineNumber, scriptName, true);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
const columnNumber = matchForBegin.groups.for.length + error.columnNumber;
|
|
344
|
+
throw new BareScriptParserError(error.error, line, columnNumber, startLineNumber + ixLine, scriptName);
|
|
345
|
+
}
|
|
346
|
+
|
|
306
347
|
// Add the for-each header statements
|
|
307
348
|
statements.push(
|
|
308
349
|
{'expr': {
|
|
309
350
|
'name': foreach.values,
|
|
310
|
-
'expr':
|
|
351
|
+
'expr': forBeginExpr,
|
|
311
352
|
...statementBase
|
|
312
353
|
}},
|
|
313
354
|
{'expr': {
|
|
@@ -489,15 +530,15 @@ const rScriptJump = new RegExp(`^(?<jump>\\s*(?:jump|jumpif\\s*\\((?<expr>.+)\\)
|
|
|
489
530
|
const rScriptReturn = new RegExp(`^(?<return>\\s*return(?:\\s+(?<expr>[^#\\s].*))?)${rPartComment}`);
|
|
490
531
|
const rScriptInclude = new RegExp(`^\\s*include\\s+(?<delim>')(?<url>(?:\\'|[^'])*)'${rPartComment}`);
|
|
491
532
|
const rScriptIncludeSystem = new RegExp(`^\\s*include\\s+(?<delim><)(?<url>[^>]*)>${rPartComment}`);
|
|
492
|
-
const rScriptIfBegin = new RegExp(
|
|
493
|
-
const rScriptIfElseIf = new RegExp(
|
|
533
|
+
const rScriptIfBegin = new RegExp(`^(?<if>\\s*if\\s+)(?<expr>.+)\\s*:${rPartComment}`);
|
|
534
|
+
const rScriptIfElseIf = new RegExp(`^(?<elif>\\s*elif\\s+)(?<expr>.+)\\s*:${rPartComment}`);
|
|
494
535
|
const rScriptIfElse = new RegExp(`^\\s*else\\s*:${rPartComment}`);
|
|
495
536
|
const rScriptIfEnd = new RegExp(`^\\s*endif${rPartComment}`);
|
|
496
537
|
const rScriptForBegin = new RegExp(
|
|
497
|
-
|
|
538
|
+
`^(?<for>\\s*for\\s+(?<value>[A-Za-z_]\\w*)(?:\\s*,\\s*(?<index>[A-Za-z_]\\w*))?\\s+in\\s+)(?<values>.+)\\s*:${rPartComment}`
|
|
498
539
|
);
|
|
499
540
|
const rScriptForEnd = new RegExp(`^\\s*endfor${rPartComment}`);
|
|
500
|
-
const rScriptWhileBegin = new RegExp(
|
|
541
|
+
const rScriptWhileBegin = new RegExp(`^(?<while>\\s*while\\s+)(?<expr>.+)\\s*:${rPartComment}`);
|
|
501
542
|
const rScriptWhileEnd = new RegExp(`^\\s*endwhile${rPartComment}`);
|
|
502
543
|
const rScriptBreak = new RegExp(`^\\s*break${rPartComment}`);
|
|
503
544
|
const rScriptContinue = new RegExp(`^\\s*continue${rPartComment}`);
|
|
@@ -702,9 +743,9 @@ function parseUnaryExpression(exprText, arrayLiterals) {
|
|
|
702
743
|
break;
|
|
703
744
|
}
|
|
704
745
|
|
|
705
|
-
//
|
|
746
|
+
// Key/value pair separator
|
|
706
747
|
if (args.length !== 0) {
|
|
707
|
-
const matchObjectSeparator = argText.match(
|
|
748
|
+
const matchObjectSeparator = argText.match(rExprObjectSeparator);
|
|
708
749
|
if (matchObjectSeparator === null) {
|
|
709
750
|
throw new BareScriptParserError('Syntax error', argText, 1, null, null);
|
|
710
751
|
}
|
|
@@ -716,13 +757,13 @@ function parseUnaryExpression(exprText, arrayLiterals) {
|
|
|
716
757
|
argText = nextArgText;
|
|
717
758
|
args.push(argKey);
|
|
718
759
|
|
|
719
|
-
//
|
|
760
|
+
// Key/value separator
|
|
720
761
|
if (args.length !== 0) {
|
|
721
|
-
const
|
|
722
|
-
if (
|
|
762
|
+
const matchObjectSeparatorKey = argText.match(rExprObjectSeparatorKey);
|
|
763
|
+
if (matchObjectSeparatorKey === null) {
|
|
723
764
|
throw new BareScriptParserError('Syntax error', argText, 1, null, null);
|
|
724
765
|
}
|
|
725
|
-
argText = argText.slice(
|
|
766
|
+
argText = argText.slice(matchObjectSeparatorKey[0].length);
|
|
726
767
|
}
|
|
727
768
|
|
|
728
769
|
// Get the value
|
|
@@ -802,8 +843,8 @@ const rExprArrayOpen = /^\s*\[/;
|
|
|
802
843
|
const rExprArraySeparator = /^\s*,/;
|
|
803
844
|
const rExprArrayClose = /^\s*\]/;
|
|
804
845
|
const rExprObjectOpen = /^\s*\{/;
|
|
805
|
-
const
|
|
806
|
-
const
|
|
846
|
+
const rExprObjectSeparatorKey = /^\s*:/;
|
|
847
|
+
const rExprObjectSeparator = /^\s*,/;
|
|
807
848
|
const rExprObjectClose = /^\s*\}/;
|
|
808
849
|
const rExprString = /^\s*'((?:\\\\|\\'|[^'])*)'/;
|
|
809
850
|
const rExprStringDouble = /^\s*"((?:\\\\|\\"|[^"])*)"/;
|
|
@@ -842,7 +883,7 @@ const exprStringEscapes = {
|
|
|
842
883
|
* @property {string} line - The line text
|
|
843
884
|
* @property {number} columnNumber - The error column number
|
|
844
885
|
* @property {?number} lineNumber - The error line number
|
|
845
|
-
* @property {?string} scriptName - The
|
|
886
|
+
* @property {?string} scriptName - The script name
|
|
846
887
|
*/
|
|
847
888
|
export class BareScriptParserError extends Error {
|
|
848
889
|
/**
|
package/lib/runtimeAsync.js
CHANGED
|
@@ -173,7 +173,7 @@ async function executeScriptHelperAsync(script, statements, options, locals) {
|
|
|
173
173
|
if (warnings.length) {
|
|
174
174
|
options.logFn(`${warningPrefix} ${warnings.length} warning${warnings.length > 1 ? 's' : ''}:`);
|
|
175
175
|
for (const warning of warnings) {
|
|
176
|
-
options.logFn(`BareScript:
|
|
176
|
+
options.logFn(`BareScript: ${warning}`);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
}
|