bare-script 5.1.2__tar.gz → 5.1.5__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-5.1.2/src/bare_script.egg-info → bare_script-5.1.5}/PKG-INFO +124 -57
- {bare_script-5.1.2 → bare_script-5.1.5}/README.md +123 -56
- {bare_script-5.1.2 → bare_script-5.1.5}/pyproject.toml +1 -1
- bare_script-5.1.5/src/bare_script/include_source.py +4527 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/library.py +130 -32
- {bare_script-5.1.2 → bare_script-5.1.5/src/bare_script.egg-info}/PKG-INFO +124 -57
- bare_script-5.1.2/src/bare_script/include_source.py +0 -5344
- {bare_script-5.1.2 → bare_script-5.1.5}/LICENSE +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/setup.cfg +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/setup.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/__init__.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/__main__.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/bare.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/include.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/options.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/runtime.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/runtime_c.c +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script/value.py +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script.egg-info/SOURCES.txt +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script.egg-info/entry_points.txt +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-5.1.2 → bare_script-5.1.5}/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: 5.1.
|
|
3
|
+
Version: 5.1.5
|
|
4
4
|
Summary: BareScript; a lightweight scripting and expression language
|
|
5
5
|
Author-email: "Craig A. Hobbs" <craigahobbs@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -49,11 +49,19 @@ confident that BareScript will execute the same regardless of the underlying run
|
|
|
49
49
|
|
|
50
50
|
- [The BareScript Language](https://craigahobbs.github.io/bare-script-py/language/)
|
|
51
51
|
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
|
|
52
|
-
- [The BareScript Include Library Tests](https://craigahobbs.github.io/bare-script/include/test/)
|
|
53
52
|
- [API Documentation](https://craigahobbs.github.io/bare-script-py/)
|
|
54
53
|
- [Source code](https://github.com/craigahobbs/bare-script-py)
|
|
55
54
|
|
|
56
55
|
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
Install the bare-script package with pip — it includes the `bare` command-line interface:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
pip install bare-script
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
57
65
|
## Executing BareScript Scripts
|
|
58
66
|
|
|
59
67
|
To execute a BareScript script, parse the script using the
|
|
@@ -62,7 +70,7 @@ function. Then execute the script using the
|
|
|
62
70
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
63
71
|
function. For example:
|
|
64
72
|
|
|
65
|
-
```
|
|
73
|
+
```python
|
|
66
74
|
from bare_script import barescript_parse_script, execute_script
|
|
67
75
|
|
|
68
76
|
# Parse the script
|
|
@@ -87,20 +95,22 @@ This outputs:
|
|
|
87
95
|
```
|
|
88
96
|
|
|
89
97
|
|
|
90
|
-
|
|
98
|
+
## The BareScript Library
|
|
91
99
|
|
|
92
100
|
[The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
documents the built-in functions available to every script and the include libraries loaded with
|
|
102
|
+
the [include statement](https://craigahobbs.github.io/bare-script-py/language/#include-statements).
|
|
103
|
+
Built-in functions cover mathematical operations, object and array manipulation, regular
|
|
104
|
+
expressions, HTTP fetch, and more. Angle-bracket includes (`include <markdown.bare>`) load libraries
|
|
105
|
+
bundled with the runtime. Quoted includes (`include 'util.bare'`) load a local file or URL.
|
|
106
|
+
|
|
107
|
+
The following example uses the built-in
|
|
96
108
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch),
|
|
97
109
|
[objectGet](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='object'&objectget), and
|
|
98
110
|
[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='array'&arraylength)
|
|
99
|
-
functions
|
|
100
|
-
|
|
101
|
-
``` python
|
|
102
|
-
import urllib.request
|
|
111
|
+
functions:
|
|
103
112
|
|
|
113
|
+
```python
|
|
104
114
|
from bare_script import barescript_parse_script, execute_script, fetch_http
|
|
105
115
|
|
|
106
116
|
# Parse the script
|
|
@@ -119,47 +129,51 @@ print(execute_script(script, {'fetchFn': fetch_http}))
|
|
|
119
129
|
This outputs:
|
|
120
130
|
|
|
121
131
|
```
|
|
122
|
-
The BareScript Library has
|
|
132
|
+
The BareScript Library has 100 builtin functions
|
|
123
133
|
```
|
|
124
134
|
|
|
135
|
+
Include libraries are loaded before use:
|
|
125
136
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
To evaluate a
|
|
129
|
-
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
130
|
-
parse the expression using the
|
|
131
|
-
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
132
|
-
function. Then evaluate the expression using the
|
|
133
|
-
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
134
|
-
function.
|
|
135
|
-
|
|
136
|
-
Expression evaluation includes the
|
|
137
|
-
[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),
|
|
138
|
-
a set of built-in, spreadsheet-like functions.
|
|
139
|
-
|
|
140
|
-
For example:
|
|
137
|
+
```python
|
|
138
|
+
from bare_script import barescript_parse_script, execute_script
|
|
141
139
|
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
# Parse the script
|
|
141
|
+
script = barescript_parse_script('''\
|
|
142
|
+
include <markdownParser.bare>
|
|
143
|
+
include <markdown.bare>
|
|
144
144
|
|
|
145
|
-
#
|
|
146
|
-
|
|
145
|
+
markdown = markdownParse('# Hello, Markdown!')
|
|
146
|
+
return markdownTitle(markdown)
|
|
147
|
+
''')
|
|
147
148
|
|
|
148
|
-
#
|
|
149
|
-
|
|
150
|
-
print(evaluate_expression(expr, None, variables))
|
|
149
|
+
# Execute the script
|
|
150
|
+
print(execute_script(script))
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
This outputs:
|
|
154
154
|
|
|
155
155
|
```
|
|
156
|
-
|
|
156
|
+
Hello, Markdown!
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Quoted includes and
|
|
160
|
+
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
161
|
+
calls with a non-URL path need a filesystem-aware fetch function. Pass
|
|
162
|
+
[fetch_read_only](https://craigahobbs.github.io/bare-script-py/options.html#bare_script.fetch_read_only)
|
|
163
|
+
or
|
|
164
|
+
[fetch_read_write](https://craigahobbs.github.io/bare-script-py/options.html#bare_script.fetch_read_write):
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from bare_script import barescript_parse_script, execute_script, fetch_read_write
|
|
168
|
+
|
|
169
|
+
script = barescript_parse_script("include 'util.bare'")
|
|
170
|
+
execute_script(script, {'fetchFn': fetch_read_write})
|
|
157
171
|
```
|
|
158
172
|
|
|
159
173
|
|
|
160
|
-
|
|
174
|
+
### Stub Functions
|
|
161
175
|
|
|
162
|
-
|
|
176
|
+
Include library functions are also callable directly from Python using the native stub functions
|
|
163
177
|
exported by the
|
|
164
178
|
[include module](https://craigahobbs.github.io/bare-script-py/include.html) — for example,
|
|
165
179
|
[data_aggregate](https://craigahobbs.github.io/bare-script-py/include.html#data-aggregate),
|
|
@@ -171,7 +185,7 @@ exported by the
|
|
|
171
185
|
Each stub function executes its corresponding include library function using the BareScript
|
|
172
186
|
runtime. For example:
|
|
173
187
|
|
|
174
|
-
```
|
|
188
|
+
```python
|
|
175
189
|
from bare_script.include import markdown_parse, markdown_title
|
|
176
190
|
|
|
177
191
|
# Parse the Markdown text
|
|
@@ -192,16 +206,57 @@ Hello, Markdown!
|
|
|
192
206
|
```
|
|
193
207
|
|
|
194
208
|
|
|
209
|
+
## Evaluating BareScript Expressions
|
|
210
|
+
|
|
211
|
+
To evaluate a
|
|
212
|
+
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
213
|
+
parse the expression using the
|
|
214
|
+
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
215
|
+
function. Then evaluate the expression using the
|
|
216
|
+
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
217
|
+
function.
|
|
218
|
+
|
|
219
|
+
Expression evaluation includes the
|
|
220
|
+
[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),
|
|
221
|
+
a set of built-in, spreadsheet-like functions.
|
|
222
|
+
|
|
223
|
+
For example:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from bare_script import barescript_parse_expression, evaluate_expression
|
|
227
|
+
|
|
228
|
+
# Parse the expression
|
|
229
|
+
expr = barescript_parse_expression('2 * max(a, b, c)')
|
|
230
|
+
|
|
231
|
+
# Evaluate the expression
|
|
232
|
+
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
233
|
+
print(evaluate_expression(expr, None, variables))
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
This outputs:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
6
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
|
|
195
243
|
## The BareScript Command-Line Interface (CLI)
|
|
196
244
|
|
|
197
245
|
You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script
|
|
198
246
|
files use the ".bare" file extension.
|
|
199
247
|
|
|
200
248
|
```
|
|
201
|
-
bare script.bare
|
|
249
|
+
bare script.bare # run a script
|
|
250
|
+
bare -c 'systemLog("Hello, World!")' # execute inline code
|
|
251
|
+
bare -v N 10 script.bare # set the global N to 10
|
|
252
|
+
bare -d script.bare # debug mode
|
|
253
|
+
bare -m app.bare # MarkdownUp text output
|
|
254
|
+
bare -l app.bare # MarkdownUp HTML output
|
|
255
|
+
bare -s script.bare # parse and lint only
|
|
256
|
+
bare -x script.bare # lint with execution
|
|
202
257
|
```
|
|
203
258
|
|
|
204
|
-
**Note:** In the BareScript CLI,
|
|
259
|
+
**Note:** In the BareScript CLI, include statements and the
|
|
205
260
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
206
261
|
function read non-URL paths from the local file system.
|
|
207
262
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
@@ -219,11 +274,16 @@ dynamically rendering Markdown text, drawing SVG images, etc. For example:
|
|
|
219
274
|
|
|
220
275
|
This is a Markdown document with embedded BareScript:
|
|
221
276
|
|
|
222
|
-
```
|
|
277
|
+
```markdown-script
|
|
223
278
|
markdownPrint('Hello, Markdown!')
|
|
224
279
|
```
|
|
225
280
|
~~~
|
|
226
281
|
|
|
282
|
+
To run a MarkdownUp script (`.bare`) from this package, use `bare -m` (Markdown text) or `bare -l`
|
|
283
|
+
(HTML). To view a MarkdownUp document (`.md` with `markdown-script` blocks), install the
|
|
284
|
+
[markdown-up](https://github.com/craigahobbs/markdown-up-py#readme) viewer or open the file in the
|
|
285
|
+
[MarkdownUp web app](https://craigahobbs.github.io/markdown-up/).
|
|
286
|
+
|
|
227
287
|
|
|
228
288
|
## C Runtime
|
|
229
289
|
|
|
@@ -251,21 +311,21 @@ without a native Python equivalent are omitted.
|
|
|
251
311
|
|
|
252
312
|
| Test | Language | Time (ms) | Multiple |
|
|
253
313
|
| ---------------- | ---------------- | --------: | -------: |
|
|
254
|
-
| mandelbrot | Python |
|
|
255
|
-
| | BareScript (PyC) |
|
|
256
|
-
| | BareScript (Py) |
|
|
257
|
-
| schemaValidate | Python |
|
|
258
|
-
| | BareScript (PyC) |
|
|
259
|
-
| | BareScript (Py) |
|
|
314
|
+
| mandelbrot | Python | 4630.9 | |
|
|
315
|
+
| | BareScript (PyC) | 10900.0 | 2.4x |
|
|
316
|
+
| | BareScript (Py) | 341300.0 | 73.7x |
|
|
317
|
+
| schemaValidate | Python | 20.7 | |
|
|
318
|
+
| | BareScript (PyC) | 105.6 | 5.1x |
|
|
319
|
+
| | BareScript (Py) | 1433.2 | 69.2x |
|
|
260
320
|
| urlEncode | Python | 1.1 | |
|
|
261
|
-
| | BareScript (PyC) | 5.
|
|
262
|
-
| | BareScript (Py) | 39.
|
|
263
|
-
| schemaParse | Python | 17.
|
|
264
|
-
| | BareScript (PyC) |
|
|
265
|
-
| | BareScript (Py) |
|
|
321
|
+
| | BareScript (PyC) | 5.7 | 5.4x |
|
|
322
|
+
| | BareScript (Py) | 39.6 | 37.5x |
|
|
323
|
+
| schemaParse | Python | 17.2 | |
|
|
324
|
+
| | BareScript (PyC) | 123.6 | 7.2x |
|
|
325
|
+
| | BareScript (Py) | 904.8 | 52.7x |
|
|
266
326
|
| urlDecode | Python | 1.2 | |
|
|
267
|
-
| | BareScript (PyC) | 13.
|
|
268
|
-
| | BareScript (Py) | 68.
|
|
327
|
+
| | BareScript (PyC) | 13.2 | 11.2x |
|
|
328
|
+
| | BareScript (Py) | 68.8 | 58.3x |
|
|
269
329
|
|
|
270
330
|
|
|
271
331
|
## Using BareScript with an AI Assistant
|
|
@@ -274,7 +334,8 @@ This repository ships a
|
|
|
274
334
|
[`SKILL.md`](https://github.com/craigahobbs/bare-script-py/blob/main/SKILL.md)
|
|
275
335
|
file that teaches an AI coding assistant how to write idiomatic BareScript — language syntax, the
|
|
276
336
|
built-in and include libraries, the MarkdownUp application pattern, and the unit-test conventions.
|
|
277
|
-
It is plain Markdown and applies to either BareScript implementation.
|
|
337
|
+
It is plain Markdown and applies to either BareScript implementation. Assistants that discover
|
|
338
|
+
`SKILL.md` at the repository root can use it without copying.
|
|
278
339
|
|
|
279
340
|
For [Claude Code](https://claude.com/claude-code) and other tools that follow the
|
|
280
341
|
[Agent Skills](https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview)
|
|
@@ -295,18 +356,24 @@ claude "Build a MarkdownUp application that plays tic-tac-toe against the user,
|
|
|
295
356
|
```
|
|
296
357
|
|
|
297
358
|
To run the resulting MarkdownUp application locally, install the
|
|
298
|
-
[markdown-up](https://
|
|
359
|
+
[markdown-up](https://github.com/craigahobbs/markdown-up-py#readme) viewer and point it at the Markdown file:
|
|
299
360
|
|
|
300
361
|
```
|
|
301
362
|
pip install markdown-up
|
|
302
363
|
markdown-up ticTacToe.md
|
|
303
364
|
```
|
|
304
365
|
|
|
305
|
-
The BareScript
|
|
366
|
+
The BareScript documentation is also published as plain Markdown, which can be fetched directly
|
|
306
367
|
into an assistant's context alongside `SKILL.md`:
|
|
307
368
|
|
|
369
|
+
- [The BareScript Language](https://craigahobbs.github.io/bare-script-py/language/README.md)
|
|
308
370
|
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/barescript-library.md)
|
|
309
371
|
- [The BareScript Library Models](https://craigahobbs.github.io/bare-script-py/library/barescript-library-model.md)
|
|
372
|
+
- [The BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/barescript-expression-library.md)
|
|
373
|
+
- [The BareScript Runtime Model](https://craigahobbs.github.io/bare-script-py/model/barescript-model.md)
|
|
374
|
+
|
|
375
|
+
`SKILL.md` itself is published at <https://craigahobbs.github.io/bare-script-py/SKILL.md>, and
|
|
376
|
+
<https://craigahobbs.github.io/bare-script-py/llms.txt> indexes all of the fetchable documentation.
|
|
310
377
|
|
|
311
378
|
|
|
312
379
|
## Development
|
|
@@ -23,11 +23,19 @@ confident that BareScript will execute the same regardless of the underlying run
|
|
|
23
23
|
|
|
24
24
|
- [The BareScript Language](https://craigahobbs.github.io/bare-script-py/language/)
|
|
25
25
|
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
|
|
26
|
-
- [The BareScript Include Library Tests](https://craigahobbs.github.io/bare-script/include/test/)
|
|
27
26
|
- [API Documentation](https://craigahobbs.github.io/bare-script-py/)
|
|
28
27
|
- [Source code](https://github.com/craigahobbs/bare-script-py)
|
|
29
28
|
|
|
30
29
|
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Install the bare-script package with pip — it includes the `bare` command-line interface:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
pip install bare-script
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
31
39
|
## Executing BareScript Scripts
|
|
32
40
|
|
|
33
41
|
To execute a BareScript script, parse the script using the
|
|
@@ -36,7 +44,7 @@ function. Then execute the script using the
|
|
|
36
44
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
37
45
|
function. For example:
|
|
38
46
|
|
|
39
|
-
```
|
|
47
|
+
```python
|
|
40
48
|
from bare_script import barescript_parse_script, execute_script
|
|
41
49
|
|
|
42
50
|
# Parse the script
|
|
@@ -61,20 +69,22 @@ This outputs:
|
|
|
61
69
|
```
|
|
62
70
|
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
## The BareScript Library
|
|
65
73
|
|
|
66
74
|
[The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
documents the built-in functions available to every script and the include libraries loaded with
|
|
76
|
+
the [include statement](https://craigahobbs.github.io/bare-script-py/language/#include-statements).
|
|
77
|
+
Built-in functions cover mathematical operations, object and array manipulation, regular
|
|
78
|
+
expressions, HTTP fetch, and more. Angle-bracket includes (`include <markdown.bare>`) load libraries
|
|
79
|
+
bundled with the runtime. Quoted includes (`include 'util.bare'`) load a local file or URL.
|
|
80
|
+
|
|
81
|
+
The following example uses the built-in
|
|
70
82
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch),
|
|
71
83
|
[objectGet](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='object'&objectget), and
|
|
72
84
|
[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='array'&arraylength)
|
|
73
|
-
functions
|
|
74
|
-
|
|
75
|
-
``` python
|
|
76
|
-
import urllib.request
|
|
85
|
+
functions:
|
|
77
86
|
|
|
87
|
+
```python
|
|
78
88
|
from bare_script import barescript_parse_script, execute_script, fetch_http
|
|
79
89
|
|
|
80
90
|
# Parse the script
|
|
@@ -93,47 +103,51 @@ print(execute_script(script, {'fetchFn': fetch_http}))
|
|
|
93
103
|
This outputs:
|
|
94
104
|
|
|
95
105
|
```
|
|
96
|
-
The BareScript Library has
|
|
106
|
+
The BareScript Library has 100 builtin functions
|
|
97
107
|
```
|
|
98
108
|
|
|
109
|
+
Include libraries are loaded before use:
|
|
99
110
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
To evaluate a
|
|
103
|
-
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
104
|
-
parse the expression using the
|
|
105
|
-
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
106
|
-
function. Then evaluate the expression using the
|
|
107
|
-
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
108
|
-
function.
|
|
109
|
-
|
|
110
|
-
Expression evaluation includes the
|
|
111
|
-
[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),
|
|
112
|
-
a set of built-in, spreadsheet-like functions.
|
|
113
|
-
|
|
114
|
-
For example:
|
|
111
|
+
```python
|
|
112
|
+
from bare_script import barescript_parse_script, execute_script
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
# Parse the script
|
|
115
|
+
script = barescript_parse_script('''\
|
|
116
|
+
include <markdownParser.bare>
|
|
117
|
+
include <markdown.bare>
|
|
118
118
|
|
|
119
|
-
#
|
|
120
|
-
|
|
119
|
+
markdown = markdownParse('# Hello, Markdown!')
|
|
120
|
+
return markdownTitle(markdown)
|
|
121
|
+
''')
|
|
121
122
|
|
|
122
|
-
#
|
|
123
|
-
|
|
124
|
-
print(evaluate_expression(expr, None, variables))
|
|
123
|
+
# Execute the script
|
|
124
|
+
print(execute_script(script))
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
This outputs:
|
|
128
128
|
|
|
129
129
|
```
|
|
130
|
-
|
|
130
|
+
Hello, Markdown!
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Quoted includes and
|
|
134
|
+
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
135
|
+
calls with a non-URL path need a filesystem-aware fetch function. Pass
|
|
136
|
+
[fetch_read_only](https://craigahobbs.github.io/bare-script-py/options.html#bare_script.fetch_read_only)
|
|
137
|
+
or
|
|
138
|
+
[fetch_read_write](https://craigahobbs.github.io/bare-script-py/options.html#bare_script.fetch_read_write):
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from bare_script import barescript_parse_script, execute_script, fetch_read_write
|
|
142
|
+
|
|
143
|
+
script = barescript_parse_script("include 'util.bare'")
|
|
144
|
+
execute_script(script, {'fetchFn': fetch_read_write})
|
|
131
145
|
```
|
|
132
146
|
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
### Stub Functions
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
Include library functions are also callable directly from Python using the native stub functions
|
|
137
151
|
exported by the
|
|
138
152
|
[include module](https://craigahobbs.github.io/bare-script-py/include.html) — for example,
|
|
139
153
|
[data_aggregate](https://craigahobbs.github.io/bare-script-py/include.html#data-aggregate),
|
|
@@ -145,7 +159,7 @@ exported by the
|
|
|
145
159
|
Each stub function executes its corresponding include library function using the BareScript
|
|
146
160
|
runtime. For example:
|
|
147
161
|
|
|
148
|
-
```
|
|
162
|
+
```python
|
|
149
163
|
from bare_script.include import markdown_parse, markdown_title
|
|
150
164
|
|
|
151
165
|
# Parse the Markdown text
|
|
@@ -166,16 +180,57 @@ Hello, Markdown!
|
|
|
166
180
|
```
|
|
167
181
|
|
|
168
182
|
|
|
183
|
+
## Evaluating BareScript Expressions
|
|
184
|
+
|
|
185
|
+
To evaluate a
|
|
186
|
+
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
187
|
+
parse the expression using the
|
|
188
|
+
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
189
|
+
function. Then evaluate the expression using the
|
|
190
|
+
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
191
|
+
function.
|
|
192
|
+
|
|
193
|
+
Expression evaluation includes the
|
|
194
|
+
[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),
|
|
195
|
+
a set of built-in, spreadsheet-like functions.
|
|
196
|
+
|
|
197
|
+
For example:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from bare_script import barescript_parse_expression, evaluate_expression
|
|
201
|
+
|
|
202
|
+
# Parse the expression
|
|
203
|
+
expr = barescript_parse_expression('2 * max(a, b, c)')
|
|
204
|
+
|
|
205
|
+
# Evaluate the expression
|
|
206
|
+
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
207
|
+
print(evaluate_expression(expr, None, variables))
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
This outputs:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
6
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
|
|
169
217
|
## The BareScript Command-Line Interface (CLI)
|
|
170
218
|
|
|
171
219
|
You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script
|
|
172
220
|
files use the ".bare" file extension.
|
|
173
221
|
|
|
174
222
|
```
|
|
175
|
-
bare script.bare
|
|
223
|
+
bare script.bare # run a script
|
|
224
|
+
bare -c 'systemLog("Hello, World!")' # execute inline code
|
|
225
|
+
bare -v N 10 script.bare # set the global N to 10
|
|
226
|
+
bare -d script.bare # debug mode
|
|
227
|
+
bare -m app.bare # MarkdownUp text output
|
|
228
|
+
bare -l app.bare # MarkdownUp HTML output
|
|
229
|
+
bare -s script.bare # parse and lint only
|
|
230
|
+
bare -x script.bare # lint with execution
|
|
176
231
|
```
|
|
177
232
|
|
|
178
|
-
**Note:** In the BareScript CLI,
|
|
233
|
+
**Note:** In the BareScript CLI, include statements and the
|
|
179
234
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
180
235
|
function read non-URL paths from the local file system.
|
|
181
236
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='system'&systemfetch)
|
|
@@ -193,11 +248,16 @@ dynamically rendering Markdown text, drawing SVG images, etc. For example:
|
|
|
193
248
|
|
|
194
249
|
This is a Markdown document with embedded BareScript:
|
|
195
250
|
|
|
196
|
-
```
|
|
251
|
+
```markdown-script
|
|
197
252
|
markdownPrint('Hello, Markdown!')
|
|
198
253
|
```
|
|
199
254
|
~~~
|
|
200
255
|
|
|
256
|
+
To run a MarkdownUp script (`.bare`) from this package, use `bare -m` (Markdown text) or `bare -l`
|
|
257
|
+
(HTML). To view a MarkdownUp document (`.md` with `markdown-script` blocks), install the
|
|
258
|
+
[markdown-up](https://github.com/craigahobbs/markdown-up-py#readme) viewer or open the file in the
|
|
259
|
+
[MarkdownUp web app](https://craigahobbs.github.io/markdown-up/).
|
|
260
|
+
|
|
201
261
|
|
|
202
262
|
## C Runtime
|
|
203
263
|
|
|
@@ -225,21 +285,21 @@ without a native Python equivalent are omitted.
|
|
|
225
285
|
|
|
226
286
|
| Test | Language | Time (ms) | Multiple |
|
|
227
287
|
| ---------------- | ---------------- | --------: | -------: |
|
|
228
|
-
| mandelbrot | Python |
|
|
229
|
-
| | BareScript (PyC) |
|
|
230
|
-
| | BareScript (Py) |
|
|
231
|
-
| schemaValidate | Python |
|
|
232
|
-
| | BareScript (PyC) |
|
|
233
|
-
| | BareScript (Py) |
|
|
288
|
+
| mandelbrot | Python | 4630.9 | |
|
|
289
|
+
| | BareScript (PyC) | 10900.0 | 2.4x |
|
|
290
|
+
| | BareScript (Py) | 341300.0 | 73.7x |
|
|
291
|
+
| schemaValidate | Python | 20.7 | |
|
|
292
|
+
| | BareScript (PyC) | 105.6 | 5.1x |
|
|
293
|
+
| | BareScript (Py) | 1433.2 | 69.2x |
|
|
234
294
|
| urlEncode | Python | 1.1 | |
|
|
235
|
-
| | BareScript (PyC) | 5.
|
|
236
|
-
| | BareScript (Py) | 39.
|
|
237
|
-
| schemaParse | Python | 17.
|
|
238
|
-
| | BareScript (PyC) |
|
|
239
|
-
| | BareScript (Py) |
|
|
295
|
+
| | BareScript (PyC) | 5.7 | 5.4x |
|
|
296
|
+
| | BareScript (Py) | 39.6 | 37.5x |
|
|
297
|
+
| schemaParse | Python | 17.2 | |
|
|
298
|
+
| | BareScript (PyC) | 123.6 | 7.2x |
|
|
299
|
+
| | BareScript (Py) | 904.8 | 52.7x |
|
|
240
300
|
| urlDecode | Python | 1.2 | |
|
|
241
|
-
| | BareScript (PyC) | 13.
|
|
242
|
-
| | BareScript (Py) | 68.
|
|
301
|
+
| | BareScript (PyC) | 13.2 | 11.2x |
|
|
302
|
+
| | BareScript (Py) | 68.8 | 58.3x |
|
|
243
303
|
|
|
244
304
|
|
|
245
305
|
## Using BareScript with an AI Assistant
|
|
@@ -248,7 +308,8 @@ This repository ships a
|
|
|
248
308
|
[`SKILL.md`](https://github.com/craigahobbs/bare-script-py/blob/main/SKILL.md)
|
|
249
309
|
file that teaches an AI coding assistant how to write idiomatic BareScript — language syntax, the
|
|
250
310
|
built-in and include libraries, the MarkdownUp application pattern, and the unit-test conventions.
|
|
251
|
-
It is plain Markdown and applies to either BareScript implementation.
|
|
311
|
+
It is plain Markdown and applies to either BareScript implementation. Assistants that discover
|
|
312
|
+
`SKILL.md` at the repository root can use it without copying.
|
|
252
313
|
|
|
253
314
|
For [Claude Code](https://claude.com/claude-code) and other tools that follow the
|
|
254
315
|
[Agent Skills](https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview)
|
|
@@ -269,18 +330,24 @@ claude "Build a MarkdownUp application that plays tic-tac-toe against the user,
|
|
|
269
330
|
```
|
|
270
331
|
|
|
271
332
|
To run the resulting MarkdownUp application locally, install the
|
|
272
|
-
[markdown-up](https://
|
|
333
|
+
[markdown-up](https://github.com/craigahobbs/markdown-up-py#readme) viewer and point it at the Markdown file:
|
|
273
334
|
|
|
274
335
|
```
|
|
275
336
|
pip install markdown-up
|
|
276
337
|
markdown-up ticTacToe.md
|
|
277
338
|
```
|
|
278
339
|
|
|
279
|
-
The BareScript
|
|
340
|
+
The BareScript documentation is also published as plain Markdown, which can be fetched directly
|
|
280
341
|
into an assistant's context alongside `SKILL.md`:
|
|
281
342
|
|
|
343
|
+
- [The BareScript Language](https://craigahobbs.github.io/bare-script-py/language/README.md)
|
|
282
344
|
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/barescript-library.md)
|
|
283
345
|
- [The BareScript Library Models](https://craigahobbs.github.io/bare-script-py/library/barescript-library-model.md)
|
|
346
|
+
- [The BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/barescript-expression-library.md)
|
|
347
|
+
- [The BareScript Runtime Model](https://craigahobbs.github.io/bare-script-py/model/barescript-model.md)
|
|
348
|
+
|
|
349
|
+
`SKILL.md` itself is published at <https://craigahobbs.github.io/bare-script-py/SKILL.md>, and
|
|
350
|
+
<https://craigahobbs.github.io/bare-script-py/llms.txt> indexes all of the fetchable documentation.
|
|
284
351
|
|
|
285
352
|
|
|
286
353
|
## Development
|