bare-script 3.4.0__tar.gz → 3.5.0__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.
Files changed (30) hide show
  1. {bare_script-3.4.0/src/bare_script.egg-info → bare_script-3.5.0}/PKG-INFO +1 -1
  2. {bare_script-3.4.0 → bare_script-3.5.0}/setup.cfg +1 -1
  3. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/model.py +18 -0
  4. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/parser.py +42 -36
  5. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/runtime.py +53 -11
  6. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/value.py +1 -1
  7. {bare_script-3.4.0 → bare_script-3.5.0/src/bare_script.egg-info}/PKG-INFO +1 -1
  8. {bare_script-3.4.0 → bare_script-3.5.0}/LICENSE +0 -0
  9. {bare_script-3.4.0 → bare_script-3.5.0}/README.md +0 -0
  10. {bare_script-3.4.0 → bare_script-3.5.0}/pyproject.toml +0 -0
  11. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/__init__.py +0 -0
  12. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/__main__.py +0 -0
  13. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/bare.py +0 -0
  14. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/baredoc.py +0 -0
  15. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/data.py +0 -0
  16. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/__init__.py +0 -0
  17. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/args.bare +0 -0
  18. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/diff.bare +0 -0
  19. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/forms.bare +0 -0
  20. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/markdownUp.bare +0 -0
  21. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/pager.bare +0 -0
  22. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/unittest.bare +0 -0
  23. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/include/unittestMock.bare +0 -0
  24. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/library.py +0 -0
  25. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script/options.py +0 -0
  26. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script.egg-info/SOURCES.txt +0 -0
  27. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script.egg-info/dependency_links.txt +0 -0
  28. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script.egg-info/entry_points.txt +0 -0
  29. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script.egg-info/requires.txt +0 -0
  30. {bare_script-3.4.0 → bare_script-3.5.0}/src/bare_script.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bare-script
3
- Version: 3.4.0
3
+ Version: 3.5.0
4
4
  Summary: bare-script
5
5
  Home-page: https://github.com/craigahobbs/bare-script
6
6
  Author: Craig A. Hobbs
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = bare-script
3
- version = 3.4.0
3
+ version = 3.5.0
4
4
  url = https://github.com/craigahobbs/bare-script
5
5
  author = Craig A. Hobbs
6
6
  author_email = craigahobbs@gmail.com
@@ -163,6 +163,12 @@ enum BinaryExpressionOperator
163
163
  # Subtraction
164
164
  "-"
165
165
 
166
+ # Bitwise left shift
167
+ "<<"
168
+
169
+ # Bitwise right shift
170
+ ">>"
171
+
166
172
  # Less than or equal
167
173
  "<="
168
174
 
@@ -181,6 +187,15 @@ enum BinaryExpressionOperator
181
187
  # Not equal
182
188
  "!="
183
189
 
190
+ # Bitwise AND
191
+ "&"
192
+
193
+ # Bitwise XOR
194
+ "^"
195
+
196
+ # Bitwise OR
197
+ "|"
198
+
184
199
  # Logical AND
185
200
  "&&"
186
201
 
@@ -207,6 +222,9 @@ enum UnaryExpressionOperator
207
222
  # Logical NOT
208
223
  "!"
209
224
 
225
+ # Bitwise NOT
226
+ "~"
227
+
210
228
 
211
229
  # A function expression
212
230
  struct FunctionExpression
@@ -488,18 +488,23 @@ def _parse_binary_expression(expr_text, bin_left_expr=None):
488
488
 
489
489
  # Binary operator re-order map
490
490
  BINARY_REORDER = {
491
- '**': {'*', '/', '%', '+', '-', '<=', '<', '>=', '>', '==', '!=', '&&', '||'},
492
- '*': {'+', '-', '<=', '<', '>=', '>', '==', '!=', '&&', '||'},
493
- '/': {'+', '-', '<=', '<', '>=', '>', '==', '!=', '&&', '||'},
494
- '%': {'+', '-', '<=', '<', '>=', '>', '==', '!=', '&&', '||'},
495
- '+': {'<=', '<', '>=', '>', '==', '!=', '&&', '||'},
496
- '-': {'<=', '<', '>=', '>', '==', '!=', '&&', '||'},
497
- '<=': {'==', '!=', '&&', '||'},
498
- '<': {'==', '!=', '&&', '||'},
499
- '>=': {'==', '!=', '&&', '||'},
500
- '>': {'==', '!=', '&&', '||'},
501
- '==': {'&&', '||'},
502
- '!=': {'&&', '||'},
491
+ '**': {'*', '/', '%', '+', '-', '<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
492
+ '*': {'+', '-', '<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
493
+ '/': {'+', '-', '<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
494
+ '%': {'+', '-', '<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
495
+ '+': {'<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
496
+ '-': {'<<', '>>', '<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
497
+ '<<': {'<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
498
+ '>>': {'<=', '<', '>=', '>', '==', '!=', '&', '^', '|', '&&', '||'},
499
+ '<=': {'==', '!=', '&', '^', '|', '&&', '||'},
500
+ '<': {'==', '!=', '&', '^', '|', '&&', '||'},
501
+ '>=': {'==', '!=', '&', '^', '|', '&&', '||'},
502
+ '>': {'==', '!=', '&', '^', '|', '&&', '||'},
503
+ '==': {'&', '^', '|', '&&', '||'},
504
+ '!=': {'&', '^', '|', '&&', '||'},
505
+ '&': {'^', '|', '&&', '||'},
506
+ '^': {'|', '&&', '||'},
507
+ '|': {'&&', '||'},
503
508
  '&&': {'||'},
504
509
  '||': set()
505
510
  }
@@ -517,6 +522,28 @@ def _parse_unary_expression(expr_text):
517
522
  raise BareScriptParserError('Unmatched parenthesis', expr_text)
518
523
  return [{'group': expr}, next_text[len(match_group_close.group(0)):]]
519
524
 
525
+ # Number?
526
+ match_number = _R_EXPR_NUMBER.match(expr_text)
527
+ if match_number:
528
+ number_str = match_number.group(1)
529
+ number = float(int(number_str, base=16)) if number_str.startswith('0x') else float(number_str)
530
+ expr = {'number': number}
531
+ return [expr, expr_text[len(match_number.group(0)):]]
532
+
533
+ # String?
534
+ match_string = _R_EXPR_STRING.match(expr_text)
535
+ if match_string:
536
+ string = _R_EXPR_STRING_ESCAPE.sub('\\1', match_string.group(1))
537
+ expr = {'string': string}
538
+ return [expr, expr_text[len(match_string.group(0)):]]
539
+
540
+ # String (double quotes)?
541
+ match_string_double = _R_EXPR_STRING_DOUBLE.match(expr_text)
542
+ if match_string_double:
543
+ string = _R_EXPR_STRING_DOUBLE_ESCAPE.sub('\\1', match_string_double.group(1))
544
+ expr = {'string': string}
545
+ return [expr, expr_text[len(match_string_double.group(0)):]]
546
+
520
547
  # Unary operator?
521
548
  match_unary = _R_EXPR_UNARY_OP.match(expr_text)
522
549
  if match_unary:
@@ -552,27 +579,6 @@ def _parse_unary_expression(expr_text):
552
579
  fn_expr = {'function': {'name': match_function_open.group(1), 'args': args}}
553
580
  return [fn_expr, arg_text]
554
581
 
555
- # Number?
556
- match_number = _R_EXPR_NUMBER.match(expr_text)
557
- if match_number:
558
- number = float(match_number.group(1))
559
- expr = {'number': number}
560
- return [expr, expr_text[len(match_number.group(0)):]]
561
-
562
- # String?
563
- match_string = _R_EXPR_STRING.match(expr_text)
564
- if match_string:
565
- string = _R_EXPR_STRING_ESCAPE.sub('\\1', match_string.group(1))
566
- expr = {'string': string}
567
- return [expr, expr_text[len(match_string.group(0)):]]
568
-
569
- # String (double quotes)?
570
- match_string_double = _R_EXPR_STRING_DOUBLE.match(expr_text)
571
- if match_string_double:
572
- string = _R_EXPR_STRING_DOUBLE_ESCAPE.sub('\\1', match_string_double.group(1))
573
- expr = {'string': string}
574
- return [expr, expr_text[len(match_string_double.group(0)):]]
575
-
576
582
  # Variable?
577
583
  match_variable = _R_EXPR_VARIABLE.match(expr_text)
578
584
  if match_variable:
@@ -590,14 +596,14 @@ def _parse_unary_expression(expr_text):
590
596
 
591
597
 
592
598
  # BareScript expression regex
593
- _R_EXPR_BINARY_OP = re.compile(r'^\s*(\*\*|\*|\/|%|\+|-|<=|<|>=|>|==|!=|&&|\|\|)')
594
- _R_EXPR_UNARY_OP = re.compile(r'^\s*(!|-)')
599
+ _R_EXPR_BINARY_OP = re.compile(r'^\s*(\*\*|\*|\/|%|\+|-|<<|>>|<=|<|>=|>|==|!=|&&|\|\||&|\^|\|)')
600
+ _R_EXPR_UNARY_OP = re.compile(r'^\s*(!|-|~)')
595
601
  _R_EXPR_FUNCTION_OPEN = re.compile(r'^\s*([A-Za-z_]\w+)\s*\(')
596
602
  _R_EXPR_FUNCTION_SEPARATOR = re.compile(r'^\s*,')
597
603
  _R_EXPR_FUNCTION_CLOSE = re.compile(r'^\s*\)')
598
604
  _R_EXPR_GROUP_OPEN = re.compile(r'^\s*\(')
599
605
  _R_EXPR_GROUP_CLOSE = re.compile(r'^\s*\)')
600
- _R_EXPR_NUMBER = re.compile(r'^\s*([+-]?\d+(?:\.\d*)?(?:e[+-]\d+)?)')
606
+ _R_EXPR_NUMBER = re.compile(r'^\s*(0x[A-Fa-f0-9]+|[+-]?\d+(?:\.\d*)?(?:e[+-]?\d+)?)')
601
607
  _R_EXPR_STRING = re.compile(r"^\s*'((?:\\\\|\\'|[^'])*)'")
602
608
  _R_EXPR_STRING_ESCAPE = re.compile(r'\\([\\\'])')
603
609
  _R_EXPR_STRING_DOUBLE = re.compile(r'^\s*"((?:\\\\|\\"|[^"])*)"')
@@ -269,7 +269,8 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True):
269
269
  right_value = evaluate_expression(expr['binary']['right'], options, locals_, builtins)
270
270
  if bin_op == '+':
271
271
  # number + number
272
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
272
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
273
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
273
274
  return left_value + right_value
274
275
 
275
276
  # string + string
@@ -283,16 +284,19 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True):
283
284
  return value_string(left_value) + right_value
284
285
 
285
286
  # datetime + number
286
- elif isinstance(left_value, datetime.date) and isinstance(right_value, (int, float)):
287
+ elif (isinstance(left_value, datetime.date) and
288
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
287
289
  left_dt = value_normalize_datetime(left_value)
288
290
  return left_dt + datetime.timedelta(milliseconds=right_value)
289
- elif isinstance(left_value, (int, float)) and isinstance(right_value, datetime.date):
291
+ elif (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
292
+ isinstance(right_value, datetime.date)):
290
293
  right_dt = value_normalize_datetime(right_value)
291
294
  return right_dt + datetime.timedelta(milliseconds=left_value)
292
295
 
293
296
  elif bin_op == '-':
294
297
  # number - number
295
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
298
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
299
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
296
300
  return left_value - right_value
297
301
 
298
302
  # datetime - datetime
@@ -303,12 +307,14 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True):
303
307
 
304
308
  elif bin_op == '*':
305
309
  # number * number
306
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
310
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
311
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
307
312
  return left_value * right_value
308
313
 
309
314
  elif bin_op == '/':
310
315
  # number / number
311
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
316
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
317
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
312
318
  return left_value / right_value
313
319
 
314
320
  elif bin_op == '==':
@@ -331,14 +337,46 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True):
331
337
 
332
338
  elif bin_op == '%':
333
339
  # number % number
334
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
340
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
341
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
335
342
  return left_value % right_value
336
343
 
337
- else: # bin_op == '**'
344
+ elif bin_op == '**':
338
345
  # number ** number
339
- if isinstance(left_value, (int, float)) and isinstance(right_value, (int, float)):
346
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and
347
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool)):
340
348
  return left_value ** right_value
341
349
 
350
+ elif bin_op == '&':
351
+ # int & int
352
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and int(left_value) == left_value and
353
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool) and int(right_value) == right_value):
354
+ return int(left_value) & int(right_value)
355
+
356
+ elif bin_op == '|':
357
+ # int & int
358
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and int(left_value) == left_value and
359
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool) and int(right_value) == right_value):
360
+ return int(left_value) | int(right_value)
361
+
362
+ elif bin_op == '^':
363
+ # int & int
364
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and int(left_value) == left_value and
365
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool) and int(right_value) == right_value):
366
+ return int(left_value) ^ int(right_value)
367
+
368
+ elif bin_op == '<<':
369
+ # int & int
370
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and int(left_value) == left_value and
371
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool) and int(right_value) == right_value):
372
+ return int(left_value) << int(right_value)
373
+
374
+ else: # bin_op == '>>':
375
+ # int & int
376
+ if (isinstance(left_value, (int, float)) and not isinstance(left_value, bool) and int(left_value) == left_value and
377
+ isinstance(right_value, (int, float)) and not isinstance(right_value, bool) and int(right_value) == right_value):
378
+ return int(left_value) >> int(right_value)
379
+
342
380
  # Invalid operation values
343
381
  return None
344
382
 
@@ -348,8 +386,12 @@ def evaluate_expression(expr, options=None, locals_=None, builtins=True):
348
386
  value = evaluate_expression(expr['unary']['expr'], options, locals_, builtins)
349
387
  if unary_op == '!':
350
388
  return not value_boolean(value)
351
- elif unary_op == '-' and isinstance(value, (int, float)):
352
- return -value
389
+ elif unary_op == '-':
390
+ if isinstance(value, (int, float)) and not isinstance(value, bool):
391
+ return -value
392
+ else: # unary_op == '~':
393
+ if isinstance(value, (int, float)) and not isinstance(value, bool) and int(value) == value:
394
+ return ~int(value)
353
395
 
354
396
  # Invalid operation value
355
397
  return None
@@ -297,7 +297,7 @@ def value_args_validate(fn_args, args, error_return_value=None):
297
297
  continue
298
298
 
299
299
  # Invalid value?
300
- if ((arg_type == 'number' and not isinstance(arg_value, (int, float))) or
300
+ if ((arg_type == 'number' and (not isinstance(arg_value, (int, float)) or isinstance(arg_value, bool))) or
301
301
  (arg_type == 'string' and not isinstance(arg_value, str)) or
302
302
  (arg_type == 'array' and not isinstance(arg_value, list)) or
303
303
  (arg_type == 'object' and not isinstance(arg_value, dict)) or
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bare-script
3
- Version: 3.4.0
3
+ Version: 3.5.0
4
4
  Summary: bare-script
5
5
  Home-page: https://github.com/craigahobbs/bare-script
6
6
  Author: Craig A. Hobbs
File without changes
File without changes
File without changes