bare-script 4.2.7__tar.gz → 4.2.9__tar.gz
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.
- {bare_script-4.2.7/src/bare_script.egg-info → bare_script-4.2.9}/PKG-INFO +1 -1
- {bare_script-4.2.7 → bare_script-4.2.9}/setup.cfg +1 -1
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/markdownUp.bare +1 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/library.py +15 -5
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/parser.py +1 -1
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/runtime.py +104 -1
- {bare_script-4.2.7 → bare_script-4.2.9/src/bare_script.egg-info}/PKG-INFO +1 -1
- {bare_script-4.2.7 → bare_script-4.2.9}/LICENSE +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/README.md +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/pyproject.toml +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/setup.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/__init__.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/__main__.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/bare.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/__init__.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/args.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/baredoc.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/baredocCLI.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/data.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/dataLineChart.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/dataTable.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/dataUtil.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/diff.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/draw.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/elementModel.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/forms.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/markdown.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/markdownElements.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/markdownHighlight.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/markdownParser.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/pager.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/qrcode.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/schemaDoc.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/unittest.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/include/unittestMock.bare +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/model.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/options.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/runtime_c.c +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script/value.py +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script.egg-info/SOURCES.txt +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script.egg-info/entry_points.txt +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-4.2.7 → bare_script-4.2.9}/src/bare_script.egg-info/top_level.txt +0 -0
|
@@ -147,6 +147,7 @@ endfunction
|
|
|
147
147
|
# $doc:
|
|
148
148
|
# $doc: **Note:** Element model "callback" members are a map of event name (e.g., "click") to
|
|
149
149
|
# $doc: event callback function. The following events have callback arguments:
|
|
150
|
+
# $doc: - **click** - For an SVG element, the click's x and y coordinates and the SVG's width and height
|
|
150
151
|
# $doc: - **keydown** - keyCode
|
|
151
152
|
# $doc: - **keypress** - keyCode
|
|
152
153
|
# $doc: - **keyup** - keyCode
|
|
@@ -149,8 +149,6 @@ _ARRAY_GET_ARGS = value_args_model([
|
|
|
149
149
|
# $return: The first index of the value in the array; -1 if not found.
|
|
150
150
|
def _array_index_of(args, options):
|
|
151
151
|
array, value, index = value_args_validate(_ARRAY_INDEX_OF_ARGS, args, -1)
|
|
152
|
-
if index >= len(array):
|
|
153
|
-
raise ValueArgsError('index', index, -1)
|
|
154
152
|
|
|
155
153
|
# Value function?
|
|
156
154
|
if value_type(value) == 'function':
|
|
@@ -196,10 +194,8 @@ _ARRAY_JOIN_ARGS = value_args_model([
|
|
|
196
194
|
# $return: The last index of the value in the array; -1 if not found.
|
|
197
195
|
def _array_last_index_of(args, options):
|
|
198
196
|
array, value, index = value_args_validate(_ARRAY_LAST_INDEX_OF_ARGS, args, -1)
|
|
199
|
-
if index is None:
|
|
197
|
+
if index is None or index >= len(array):
|
|
200
198
|
index = len(array) - 1
|
|
201
|
-
if index >= len(array):
|
|
202
|
-
raise ValueArgsError('index', index, -1)
|
|
203
199
|
|
|
204
200
|
# Value function?
|
|
205
201
|
if value_type(value) == 'function':
|
|
@@ -2208,3 +2204,17 @@ EXPRESSION_FUNCTIONS = dict(
|
|
|
2208
2204
|
(expr_fn_name, SCRIPT_FUNCTIONS[script_fn_name])
|
|
2209
2205
|
for expr_fn_name, script_fn_name in EXPRESSION_FUNCTION_MAP.items()
|
|
2210
2206
|
)
|
|
2207
|
+
|
|
2208
|
+
|
|
2209
|
+
# Library functions with an inline "intrinsic" fast path in the runtime call dispatch. Membership is by
|
|
2210
|
+
# function-object identity, so any override (a user function, an options global, or an unittestMock
|
|
2211
|
+
# systemGlobalSet) is a different object that misses the set and takes the normal call path. Kept small
|
|
2212
|
+
# on purpose: these hot, validation-heavy accessors measured as ~all of the include-test speedup.
|
|
2213
|
+
# Defined here, next to SCRIPT_FUNCTIONS, mirroring the JavaScript implementation.
|
|
2214
|
+
INTRINSICS = frozenset((
|
|
2215
|
+
SCRIPT_FUNCTIONS['arrayGet'],
|
|
2216
|
+
SCRIPT_FUNCTIONS['arrayPush'],
|
|
2217
|
+
SCRIPT_FUNCTIONS['arraySet'],
|
|
2218
|
+
SCRIPT_FUNCTIONS['objectGet'],
|
|
2219
|
+
SCRIPT_FUNCTIONS['objectSet'],
|
|
2220
|
+
))
|
|
@@ -764,7 +764,7 @@ def _parse_unary_expression(expr_text, array_literals):
|
|
|
764
764
|
# BareScript expression regex
|
|
765
765
|
_R_EXPR_BINARY_OP = re.compile(r'^\s*(\*\*|\*|\/|%|\+|-|<<|>>|<=|<|>=|>|==|!=|&&|\|\||&|\^|\|)')
|
|
766
766
|
_R_EXPR_UNARY_OP = re.compile(r'^\s*(!|-|~)')
|
|
767
|
-
_R_EXPR_FUNCTION_OPEN = re.compile(r'^\s*([A-Za-z_]\w
|
|
767
|
+
_R_EXPR_FUNCTION_OPEN = re.compile(r'^\s*([A-Za-z_]\w*)\s*\(')
|
|
768
768
|
_R_EXPR_FUNCTION_SEPARATOR = re.compile(r'^\s*,')
|
|
769
769
|
_R_EXPR_FUNCTION_CLOSE = re.compile(r'^\s*\)')
|
|
770
770
|
_R_EXPR_GROUP_OPEN = re.compile(r'^\s*\(')
|
|
@@ -8,7 +8,7 @@ The BareScript runtime
|
|
|
8
8
|
import datetime
|
|
9
9
|
import functools
|
|
10
10
|
|
|
11
|
-
from .library import EXPRESSION_FUNCTIONS, SCRIPT_FUNCTIONS
|
|
11
|
+
from .library import EXPRESSION_FUNCTIONS, INTRINSICS, SCRIPT_FUNCTIONS
|
|
12
12
|
from .model import lint_script
|
|
13
13
|
from .options import url_file_relative
|
|
14
14
|
from .parser import parse_script
|
|
@@ -315,6 +315,109 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True, script=
|
|
|
315
315
|
if func_value is not None:
|
|
316
316
|
# Call the function
|
|
317
317
|
try:
|
|
318
|
+
# Intrinsic fast path: run the body inline, skipping value_args_validate and the
|
|
319
|
+
# call frame. Bad arguments raise ValueArgsError, handled by the except below exactly
|
|
320
|
+
# as the normal call would; a call reaching one of these under a different name (an
|
|
321
|
+
# alias) matches no branch and falls through to the normal call.
|
|
322
|
+
if func_value in INTRINSICS:
|
|
323
|
+
func_args_length = len(func_args)
|
|
324
|
+
if func_name == 'arrayGet':
|
|
325
|
+
if func_args_length < 1:
|
|
326
|
+
raise ValueArgsError('array', None)
|
|
327
|
+
array_value = func_args[0]
|
|
328
|
+
array_type = type(array_value)
|
|
329
|
+
if array_type is not list:
|
|
330
|
+
raise ValueArgsError('array', array_value)
|
|
331
|
+
if func_args_length < 2:
|
|
332
|
+
raise ValueArgsError('index', None)
|
|
333
|
+
index_value = func_args[1]
|
|
334
|
+
index_type = type(index_value)
|
|
335
|
+
if index_type is float:
|
|
336
|
+
if index_value < 0 or not index_value.is_integer():
|
|
337
|
+
raise ValueArgsError('index', index_value)
|
|
338
|
+
index_value = int(index_value)
|
|
339
|
+
elif index_type is int:
|
|
340
|
+
if index_value < 0:
|
|
341
|
+
raise ValueArgsError('index', index_value)
|
|
342
|
+
else:
|
|
343
|
+
raise ValueArgsError('index', index_value)
|
|
344
|
+
if func_args_length > 2:
|
|
345
|
+
raise ValueArgsError(None, func_args_length)
|
|
346
|
+
if index_value >= len(array_value):
|
|
347
|
+
raise ValueArgsError('index', index_value)
|
|
348
|
+
return array_value[index_value]
|
|
349
|
+
if func_name == 'arrayPush':
|
|
350
|
+
if func_args_length < 1:
|
|
351
|
+
raise ValueArgsError('array', None)
|
|
352
|
+
array_value = func_args[0]
|
|
353
|
+
array_type = type(array_value)
|
|
354
|
+
if array_type is not list:
|
|
355
|
+
raise ValueArgsError('array', array_value)
|
|
356
|
+
array_value.extend(func_args[1:])
|
|
357
|
+
return array_value
|
|
358
|
+
if func_name == 'arraySet':
|
|
359
|
+
if func_args_length < 1:
|
|
360
|
+
raise ValueArgsError('array', None)
|
|
361
|
+
array_value = func_args[0]
|
|
362
|
+
array_type = type(array_value)
|
|
363
|
+
if array_type is not list:
|
|
364
|
+
raise ValueArgsError('array', array_value)
|
|
365
|
+
if func_args_length < 2:
|
|
366
|
+
raise ValueArgsError('index', None)
|
|
367
|
+
index_value = func_args[1]
|
|
368
|
+
index_type = type(index_value)
|
|
369
|
+
if index_type is float:
|
|
370
|
+
if index_value < 0 or not index_value.is_integer():
|
|
371
|
+
raise ValueArgsError('index', index_value)
|
|
372
|
+
index_value = int(index_value)
|
|
373
|
+
elif index_type is int:
|
|
374
|
+
if index_value < 0:
|
|
375
|
+
raise ValueArgsError('index', index_value)
|
|
376
|
+
else:
|
|
377
|
+
raise ValueArgsError('index', index_value)
|
|
378
|
+
if func_args_length > 3:
|
|
379
|
+
raise ValueArgsError(None, func_args_length)
|
|
380
|
+
if index_value >= len(array_value):
|
|
381
|
+
raise ValueArgsError('index', index_value)
|
|
382
|
+
set_value = func_args[2] if func_args_length >= 3 else None
|
|
383
|
+
array_value[index_value] = set_value
|
|
384
|
+
return set_value
|
|
385
|
+
if func_name == 'objectGet':
|
|
386
|
+
default_value = func_args[2] if func_args_length >= 3 else None
|
|
387
|
+
if func_args_length < 1:
|
|
388
|
+
raise ValueArgsError('object', None, default_value)
|
|
389
|
+
object_value = func_args[0]
|
|
390
|
+
object_type = type(object_value)
|
|
391
|
+
if object_type is not dict:
|
|
392
|
+
raise ValueArgsError('object', object_value, default_value)
|
|
393
|
+
if func_args_length < 2:
|
|
394
|
+
raise ValueArgsError('key', None, default_value)
|
|
395
|
+
key_value = func_args[1]
|
|
396
|
+
key_type = type(key_value)
|
|
397
|
+
if key_type is not str:
|
|
398
|
+
raise ValueArgsError('key', key_value, default_value)
|
|
399
|
+
if func_args_length > 3:
|
|
400
|
+
raise ValueArgsError(None, func_args_length, default_value)
|
|
401
|
+
return object_value.get(key_value, default_value)
|
|
402
|
+
if func_name == 'objectSet':
|
|
403
|
+
if func_args_length < 1:
|
|
404
|
+
raise ValueArgsError('object', None)
|
|
405
|
+
object_value = func_args[0]
|
|
406
|
+
object_type = type(object_value)
|
|
407
|
+
if object_type is not dict:
|
|
408
|
+
raise ValueArgsError('object', object_value)
|
|
409
|
+
if func_args_length < 2:
|
|
410
|
+
raise ValueArgsError('key', None)
|
|
411
|
+
key_value = func_args[1]
|
|
412
|
+
key_type = type(key_value)
|
|
413
|
+
if key_type is not str:
|
|
414
|
+
raise ValueArgsError('key', key_value)
|
|
415
|
+
if func_args_length > 3:
|
|
416
|
+
raise ValueArgsError(None, func_args_length)
|
|
417
|
+
set_value = func_args[2] if func_args_length >= 3 else None
|
|
418
|
+
object_value[key_value] = set_value
|
|
419
|
+
return set_value
|
|
420
|
+
|
|
318
421
|
return func_value(func_args, options)
|
|
319
422
|
except BareScriptRuntimeError:
|
|
320
423
|
raise
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|