bare-script 3.8.23__tar.gz → 4.0.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.
- {bare_script-3.8.23/src/bare_script.egg-info → bare_script-4.0.0}/PKG-INFO +2 -3
- {bare_script-3.8.23 → bare_script-4.0.0}/README.md +1 -2
- {bare_script-3.8.23 → bare_script-4.0.0}/setup.cfg +1 -2
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/__init__.py +2 -9
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/bare.py +23 -25
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/args.bare +2 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/baredoc.bare +22 -13
- bare_script-4.0.0/src/bare_script/include/baredocCLI.bare +246 -0
- bare_script-4.0.0/src/bare_script/include/data.bare +600 -0
- bare_script-4.0.0/src/bare_script/include/dataLineChart.bare +808 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/dataTable.bare +129 -11
- bare_script-4.0.0/src/bare_script/include/dataUtil.bare +56 -0
- bare_script-4.0.0/src/bare_script/include/draw.bare +443 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/elementModel.bare +2 -2
- bare_script-4.0.0/src/bare_script/include/markdown.bare +292 -0
- bare_script-4.0.0/src/bare_script/include/markdownElements.bare +346 -0
- bare_script-4.0.0/src/bare_script/include/markdownHighlight.bare +1160 -0
- bare_script-4.0.0/src/bare_script/include/markdownParser.bare +839 -0
- bare_script-4.0.0/src/bare_script/include/markdownUp.bare +361 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/pager.bare +1 -1
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/qrcode.bare +2 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/schemaDoc.bare +4 -2
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/unittest.bare +28 -3
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/unittestMock.bare +2 -146
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/library.py +0 -242
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/options.py +21 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/parser.py +12 -12
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/runtime.py +10 -2
- {bare_script-3.8.23 → bare_script-4.0.0/src/bare_script.egg-info}/PKG-INFO +2 -3
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script.egg-info/SOURCES.txt +8 -2
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script.egg-info/entry_points.txt +0 -1
- bare_script-3.8.23/src/bare_script/baredoc.py +0 -180
- bare_script-3.8.23/src/bare_script/data.py +0 -477
- bare_script-3.8.23/src/bare_script/include/dataLineChart.bare +0 -90
- bare_script-3.8.23/src/bare_script/include/markdownUp.bare +0 -644
- {bare_script-3.8.23 → bare_script-4.0.0}/LICENSE +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/pyproject.toml +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/__main__.py +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/__init__.py +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/diff.bare +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/include/forms.bare +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/model.py +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script/value.py +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-3.8.23 → bare_script-4.0.0}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-3.8.23 → bare_script-4.0.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
|
+
Version: 4.0.0
|
|
4
4
|
Summary: bare-script
|
|
5
5
|
Home-page: https://github.com/craigahobbs/bare-script
|
|
6
6
|
Author: Craig A. Hobbs
|
|
@@ -48,7 +48,6 @@ confident that BareScript will execute the same regardless of the underlying run
|
|
|
48
48
|
|
|
49
49
|
- [The BareScript Language](https://craigahobbs.github.io/bare-script-py/language/)
|
|
50
50
|
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
|
|
51
|
-
- [The BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html)
|
|
52
51
|
- [API Documentation](https://craigahobbs.github.io/bare-script-py/)
|
|
53
52
|
- [Source code](https://github.com/craigahobbs/bare-script-py)
|
|
54
53
|
|
|
@@ -118,7 +117,7 @@ print(execute_script(script, {'fetchFn': fetch_http}))
|
|
|
118
117
|
This outputs:
|
|
119
118
|
|
|
120
119
|
```
|
|
121
|
-
The BareScript Library has
|
|
120
|
+
The BareScript Library has 209 functions
|
|
122
121
|
```
|
|
123
122
|
|
|
124
123
|
|
|
@@ -23,7 +23,6 @@ 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 Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html)
|
|
27
26
|
- [API Documentation](https://craigahobbs.github.io/bare-script-py/)
|
|
28
27
|
- [Source code](https://github.com/craigahobbs/bare-script-py)
|
|
29
28
|
|
|
@@ -93,7 +92,7 @@ print(execute_script(script, {'fetchFn': fetch_http}))
|
|
|
93
92
|
This outputs:
|
|
94
93
|
|
|
95
94
|
```
|
|
96
|
-
The BareScript Library has
|
|
95
|
+
The BareScript Library has 209 functions
|
|
97
96
|
```
|
|
98
97
|
|
|
99
98
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = bare-script
|
|
3
|
-
version =
|
|
3
|
+
version = 4.0.0
|
|
4
4
|
url = https://github.com/craigahobbs/bare-script
|
|
5
5
|
author = Craig A. Hobbs
|
|
6
6
|
author_email = craigahobbs@gmail.com
|
|
@@ -32,7 +32,6 @@ install_requires =
|
|
|
32
32
|
[options.entry_points]
|
|
33
33
|
console_scripts =
|
|
34
34
|
bare = bare_script.bare:main
|
|
35
|
-
baredoc = bare_script.baredoc:main
|
|
36
35
|
|
|
37
36
|
[options.package_data]
|
|
38
37
|
bare_script =
|
|
@@ -5,24 +5,17 @@
|
|
|
5
5
|
bare-script package
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from .data import \
|
|
9
|
-
add_calculated_field, \
|
|
10
|
-
aggregate_data, \
|
|
11
|
-
filter_data, \
|
|
12
|
-
join_data, \
|
|
13
|
-
sort_data, \
|
|
14
|
-
top_data, \
|
|
15
|
-
validate_data
|
|
16
|
-
|
|
17
8
|
from .model import \
|
|
18
9
|
lint_script, \
|
|
19
10
|
validate_expression, \
|
|
20
11
|
validate_script
|
|
21
12
|
|
|
22
13
|
from .options import \
|
|
14
|
+
FETCH_SYSTEM_PREFIX, \
|
|
23
15
|
fetch_http, \
|
|
24
16
|
fetch_read_only, \
|
|
25
17
|
fetch_read_write, \
|
|
18
|
+
fetch_system, \
|
|
26
19
|
log_stdout, \
|
|
27
20
|
url_file_relative
|
|
28
21
|
|
|
@@ -7,16 +7,13 @@ bare-script command-line interface (CLI)
|
|
|
7
7
|
|
|
8
8
|
import argparse
|
|
9
9
|
from functools import partial
|
|
10
|
-
import importlib.resources
|
|
11
|
-
import os
|
|
12
10
|
import sys
|
|
13
11
|
import time
|
|
14
12
|
|
|
15
|
-
from .library import SYSTEM_GLOBAL_INCLUDES_NAME
|
|
16
13
|
from .model import lint_script
|
|
17
|
-
from .options import fetch_read_write, log_stdout, url_file_relative
|
|
14
|
+
from .options import FETCH_SYSTEM_PREFIX, fetch_read_write, fetch_system, log_stdout, url_file_relative
|
|
18
15
|
from .parser import parse_expression, parse_script
|
|
19
|
-
from .runtime import evaluate_expression, execute_script
|
|
16
|
+
from .runtime import SYSTEM_GLOBAL_INCLUDES_NAME, evaluate_expression, execute_script
|
|
20
17
|
from .value import value_boolean
|
|
21
18
|
|
|
22
19
|
|
|
@@ -33,7 +30,9 @@ def main(argv=None):
|
|
|
33
30
|
parser.add_argument('file', nargs='*', action=_FileScriptAction, help='files to process')
|
|
34
31
|
parser.add_argument('-c', '--code', action=_InlineScriptAction, help='execute the BareScript code')
|
|
35
32
|
parser.add_argument('-d', '--debug', action='store_true', help='enable debug mode')
|
|
36
|
-
parser.
|
|
33
|
+
markdown_up_group = parser.add_mutually_exclusive_group()
|
|
34
|
+
markdown_up_group.add_argument('-l', '--html', action='store_true', help='run with MarkdownUp HTML output')
|
|
35
|
+
markdown_up_group.add_argument('-m', '--markdown', action='store_true', help='run with MarkdownUp text output')
|
|
37
36
|
parser.add_argument('-s', '--static', dest='static', action='store_const', const='s', help='perform static analysis')
|
|
38
37
|
parser.add_argument('-x', '--staticx', dest='static', action='store_const', const='x', help='perform static analysis with execution')
|
|
39
38
|
parser.add_argument('-v', '--var', nargs=2, action='append', metavar=('VAR', 'EXPR'), default = [],
|
|
@@ -54,9 +53,22 @@ def main(argv=None):
|
|
|
54
53
|
# Get the scripts to run
|
|
55
54
|
scripts = args.scripts
|
|
56
55
|
ix_user_script = 0
|
|
57
|
-
if args.
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
if args.html or args.markdown:
|
|
57
|
+
# HTML or Markdown Text render?
|
|
58
|
+
if args.html:
|
|
59
|
+
scripts = [
|
|
60
|
+
('code', 'include <markdownUp.bare>'),
|
|
61
|
+
('code', 'markdownUpHTMLBegin()'),
|
|
62
|
+
*scripts,
|
|
63
|
+
('code', 'markdownUpHTMLEnd()')
|
|
64
|
+
]
|
|
65
|
+
ix_user_script = 2
|
|
66
|
+
else:
|
|
67
|
+
scripts = [
|
|
68
|
+
('code', 'include <markdownUp.bare>'),
|
|
69
|
+
*scripts
|
|
70
|
+
]
|
|
71
|
+
ix_user_script = 1
|
|
60
72
|
|
|
61
73
|
# Add unittest.bare argument globals
|
|
62
74
|
globals_['vUnittestReport'] = True
|
|
@@ -101,10 +113,10 @@ def main(argv=None):
|
|
|
101
113
|
time_begin = time.time()
|
|
102
114
|
result = execute_script(script, {
|
|
103
115
|
'debug': args.debug or False,
|
|
104
|
-
'fetchFn':
|
|
116
|
+
'fetchFn': lambda request: fetch_system(fetch_read_write, request),
|
|
105
117
|
'globals': static_globals,
|
|
106
118
|
'logFn': log_stdout,
|
|
107
|
-
'systemPrefix':
|
|
119
|
+
'systemPrefix': FETCH_SYSTEM_PREFIX,
|
|
108
120
|
'urlFn': partial(url_file_relative, script_value) if script_type == 'file' else None
|
|
109
121
|
})
|
|
110
122
|
if isinstance(result, (int, float)) and int(result) == result and 0 <= result <= 255:
|
|
@@ -140,20 +152,6 @@ def main(argv=None):
|
|
|
140
152
|
sys.exit(status_code)
|
|
141
153
|
|
|
142
154
|
|
|
143
|
-
def _fetch_include(request):
|
|
144
|
-
# Is this a bare system include?
|
|
145
|
-
url = request['url']
|
|
146
|
-
if url.startswith(_FETCH_INCLUDE_PREFIX):
|
|
147
|
-
path = url[len(_FETCH_INCLUDE_PREFIX):]
|
|
148
|
-
with importlib.resources.files('bare_script.include').joinpath(path).open('rb') as cm_inc:
|
|
149
|
-
return cm_inc.read().decode(encoding='utf-8')
|
|
150
|
-
|
|
151
|
-
return fetch_read_write(request)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
_FETCH_INCLUDE_PREFIX = f':bare-include:{os.sep}'
|
|
155
|
-
|
|
156
|
-
|
|
157
155
|
class _InlineScriptAction(argparse.Action):
|
|
158
156
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
159
157
|
if 'scripts' not in namespace:
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
# https://github.com/craigahobbs/bare-script/blob/main/LICENSE
|
|
3
3
|
|
|
4
4
|
include <args.bare>
|
|
5
|
+
include <markdown.bare>
|
|
6
|
+
include <dataUtil.bare>
|
|
7
|
+
include <dataTable.bare>
|
|
5
8
|
include <schemaDoc.bare>
|
|
6
9
|
|
|
7
10
|
|
|
@@ -23,7 +26,7 @@ async function baredocMain(url, title, menuLinks, groupURLs):
|
|
|
23
26
|
# Render library JSON documentation page?
|
|
24
27
|
if objectGet(args, 'doc'):
|
|
25
28
|
documentSetTitle('Library')
|
|
26
|
-
markdownPrint(schemaDocMarkdown(baredocTypes, '
|
|
29
|
+
markdownPrint(schemaDocMarkdown(baredocTypes, 'BaredocLibrary'))
|
|
27
30
|
return
|
|
28
31
|
endif
|
|
29
32
|
|
|
@@ -32,7 +35,7 @@ async function baredocMain(url, title, menuLinks, groupURLs):
|
|
|
32
35
|
urls = if(systemType(url) == 'array', url, [url])
|
|
33
36
|
for libraryJSON, ixLibrary in systemFetch(urls):
|
|
34
37
|
libraryPart = if(libraryJSON != null, jsonParse(libraryJSON))
|
|
35
|
-
libraryPart = if(libraryPart != null, schemaValidate(baredocTypes, '
|
|
38
|
+
libraryPart = if(libraryPart != null, schemaValidate(baredocTypes, 'BaredocLibrary', libraryPart))
|
|
36
39
|
if libraryPart == null:
|
|
37
40
|
libraryURL = arrayGet(urls, ixLibrary)
|
|
38
41
|
markdownPrint('**Error:** Failed to fetch library documentation resource "' + markdownEscape(libraryURL) + '"')
|
|
@@ -294,38 +297,44 @@ endfunction
|
|
|
294
297
|
|
|
295
298
|
# The library documentation schema
|
|
296
299
|
baredocTypes = schemaParse( \
|
|
300
|
+
'group "baredoc.bare"', \
|
|
301
|
+
'', \
|
|
302
|
+
'', \
|
|
297
303
|
'# A library documentation model', \
|
|
298
|
-
'struct
|
|
304
|
+
'struct BaredocLibrary', \
|
|
299
305
|
'', \
|
|
300
306
|
' # The library functions', \
|
|
301
|
-
'
|
|
307
|
+
' BaredocFunction[] functions', \
|
|
302
308
|
'', \
|
|
303
309
|
'', \
|
|
304
310
|
'# A library function', \
|
|
305
|
-
'struct
|
|
311
|
+
'struct BaredocFunction', \
|
|
306
312
|
'', \
|
|
307
313
|
' # The function name', \
|
|
308
|
-
' string
|
|
314
|
+
' string name', \
|
|
309
315
|
'', \
|
|
310
316
|
' # The function group (e.g. "Math")', \
|
|
311
|
-
' string
|
|
317
|
+
' string group', \
|
|
312
318
|
'', \
|
|
313
319
|
" # The function's documentation Markdown lines", \
|
|
314
|
-
' string[
|
|
320
|
+
' string[] doc', \
|
|
315
321
|
'', \
|
|
316
322
|
' # The function arguments', \
|
|
317
|
-
' optional
|
|
323
|
+
' optional BaredocFunctionArgument[] args', \
|
|
318
324
|
'', \
|
|
319
325
|
" # The function return's documentation Markdown lines", \
|
|
320
|
-
' optional string[
|
|
326
|
+
' optional string[] return', \
|
|
327
|
+
'', \
|
|
328
|
+
' # If true, ignore the function', \
|
|
329
|
+
' optional bool ignore', \
|
|
321
330
|
'', \
|
|
322
331
|
'', \
|
|
323
332
|
'# A function argument', \
|
|
324
|
-
'struct
|
|
333
|
+
'struct BaredocFunctionArgument', \
|
|
325
334
|
'', \
|
|
326
335
|
' # The argument name', \
|
|
327
|
-
' string
|
|
336
|
+
' string name', \
|
|
328
337
|
'', \
|
|
329
338
|
" # The argument's documentation Markdown lines", \
|
|
330
|
-
' string[
|
|
339
|
+
' string[] doc' \
|
|
331
340
|
)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Licensed under the MIT License
|
|
2
|
+
# https://github.com/craigahobbs/bare-script/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
include <args.bare>
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# $function: baredocCLIMain
|
|
8
|
+
# $group: baredocCLI.bare
|
|
9
|
+
# $doc: The BareScript documentation tool main entry point
|
|
10
|
+
# $return: The exit status code
|
|
11
|
+
async function baredocCLIMain():
|
|
12
|
+
# Command line arguments
|
|
13
|
+
args = argsParse(baredocCLIMainArguments)
|
|
14
|
+
if objectGet(args, 'help'):
|
|
15
|
+
markdownPrint(argsHelp(baredocCLIMainArguments))
|
|
16
|
+
return 1
|
|
17
|
+
endif
|
|
18
|
+
output = objectGet(args, 'output')
|
|
19
|
+
files = jsonParse(objectGet(args, 'files'))
|
|
20
|
+
if files == null || systemType(files) != 'array':
|
|
21
|
+
markdownPrint('**Error:** Invalid input file list JSON')
|
|
22
|
+
return 1
|
|
23
|
+
endif
|
|
24
|
+
|
|
25
|
+
# Parse each source file
|
|
26
|
+
functions = {}
|
|
27
|
+
errors = []
|
|
28
|
+
for filename in files:
|
|
29
|
+
# Read the source file
|
|
30
|
+
source = systemFetch(filename)
|
|
31
|
+
if source == null:
|
|
32
|
+
arrayPush(errors, 'Failed to load "' + filename + '"')
|
|
33
|
+
continue
|
|
34
|
+
endif
|
|
35
|
+
|
|
36
|
+
# Parse documentation comments
|
|
37
|
+
arrayExtend(errors, baredocCLIParse(functions, source, filename))
|
|
38
|
+
endfor
|
|
39
|
+
|
|
40
|
+
# Create the library documentation model - sort functions by name
|
|
41
|
+
libraryFunctions = []
|
|
42
|
+
for funcName in arraySort(objectKeys(functions)):
|
|
43
|
+
arrayPush(libraryFunctions, objectGet(functions, funcName))
|
|
44
|
+
endfor
|
|
45
|
+
library = {'functions': libraryFunctions}
|
|
46
|
+
libraryJSON = jsonStringify(library)
|
|
47
|
+
|
|
48
|
+
# No library functions?
|
|
49
|
+
if !libraryFunctions:
|
|
50
|
+
arrayPush(errors, 'error: No library functions')
|
|
51
|
+
endif
|
|
52
|
+
|
|
53
|
+
# Errors?
|
|
54
|
+
if errors:
|
|
55
|
+
markdownPrint('```', arrayJoin(errors, '\n'), '```')
|
|
56
|
+
return 1
|
|
57
|
+
endif
|
|
58
|
+
|
|
59
|
+
# Output to stdout?
|
|
60
|
+
status = 0
|
|
61
|
+
if output == '-':
|
|
62
|
+
systemLog(libraryJSON)
|
|
63
|
+
else:
|
|
64
|
+
# Output to file
|
|
65
|
+
if !systemFetch({'url': output, 'body': libraryJSON}):
|
|
66
|
+
markdownPrint('**Error:** Failed to write "' + output + '"')
|
|
67
|
+
status = 1
|
|
68
|
+
endif
|
|
69
|
+
endif
|
|
70
|
+
return status
|
|
71
|
+
endfunction
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# baredocCLI application arguments
|
|
75
|
+
baredocCLIMainArguments = argsValidate([ \
|
|
76
|
+
{'name': 'files', 'type': 'string', 'default': '[]', 'description': 'The JSON-encoded list of input source code filenames'}, \
|
|
77
|
+
{'name': 'help', 'type': 'bool', 'description': 'Show argument help'}, \
|
|
78
|
+
{'name': 'output', 'type': 'string', 'default': '-', 'description': 'The output file'} \
|
|
79
|
+
])
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# $function: baredocCLIParse
|
|
83
|
+
# $group: baredocCLI.bare
|
|
84
|
+
# $doc: Parse source code for baredoc documentation comments
|
|
85
|
+
# $arg functions: The map of function name to [function documentation model](model.html#var.vName='BaredocFunction')
|
|
86
|
+
# $arg source: The source code string
|
|
87
|
+
# $arg filename: The source filename string
|
|
88
|
+
# $return: The array of errors
|
|
89
|
+
function baredocCLIParse(functions, source, filename):
|
|
90
|
+
errors = []
|
|
91
|
+
|
|
92
|
+
# Process documentation comments line-by-line
|
|
93
|
+
func = null
|
|
94
|
+
for line, ixLine in stringSplitLines(source):
|
|
95
|
+
# function/group/doc/return documentation keywords?
|
|
96
|
+
matchKey = regexMatch(baredocCLIMainRegexKey, line)
|
|
97
|
+
if matchKey != null:
|
|
98
|
+
groupsKey = objectGet(matchKey, 'groups')
|
|
99
|
+
key = objectGet(groupsKey, 'key')
|
|
100
|
+
text = objectGet(groupsKey, 'text')
|
|
101
|
+
textTrim = stringTrim(text)
|
|
102
|
+
|
|
103
|
+
# Keyword used outside of function?
|
|
104
|
+
if key != 'function' && func == null:
|
|
105
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': ' + key + ' keyword outside function')
|
|
106
|
+
continue
|
|
107
|
+
endif
|
|
108
|
+
|
|
109
|
+
# Process the keyword
|
|
110
|
+
if key == 'group':
|
|
111
|
+
if textTrim == '':
|
|
112
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Invalid function group name "' + textTrim + '"')
|
|
113
|
+
continue
|
|
114
|
+
endif
|
|
115
|
+
if objectHas(func, 'group'):
|
|
116
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Function "' + objectGet(func, 'name') + '" group redefinition')
|
|
117
|
+
continue
|
|
118
|
+
endif
|
|
119
|
+
|
|
120
|
+
# Set the function group
|
|
121
|
+
objectSet(func, 'group', textTrim)
|
|
122
|
+
|
|
123
|
+
elif key == 'doc' || key == 'return':
|
|
124
|
+
# Add the documentation line - don't add leading blank lines
|
|
125
|
+
funcDoc = objectGet(func, key)
|
|
126
|
+
if funcDoc != null || textTrim != '':
|
|
127
|
+
if funcDoc == null:
|
|
128
|
+
funcDoc = []
|
|
129
|
+
objectSet(func, key, funcDoc)
|
|
130
|
+
endif
|
|
131
|
+
arrayPush(funcDoc, text)
|
|
132
|
+
endif
|
|
133
|
+
|
|
134
|
+
elif key == 'ignore':
|
|
135
|
+
# Ignore the function?
|
|
136
|
+
if textTrim != 'true' && textTrim != 'false':
|
|
137
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Invalid ignore value "' + textTrim + '"')
|
|
138
|
+
continue
|
|
139
|
+
endif
|
|
140
|
+
objectSet(func, key, text == 'true')
|
|
141
|
+
|
|
142
|
+
else:
|
|
143
|
+
# key == 'function'
|
|
144
|
+
if textTrim == '':
|
|
145
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Invalid function name "' + textTrim + '"')
|
|
146
|
+
continue
|
|
147
|
+
endif
|
|
148
|
+
if objectHas(functions, textTrim):
|
|
149
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Function "' + textTrim + '" redefinition')
|
|
150
|
+
continue
|
|
151
|
+
endif
|
|
152
|
+
|
|
153
|
+
# Add the function
|
|
154
|
+
func = {'name': textTrim}
|
|
155
|
+
objectSet(functions, textTrim, func)
|
|
156
|
+
endif
|
|
157
|
+
|
|
158
|
+
continue
|
|
159
|
+
endif
|
|
160
|
+
|
|
161
|
+
# arg keyword?
|
|
162
|
+
matchArg = regexMatch(baredocCLIMainRegexArg, line)
|
|
163
|
+
if matchArg != null:
|
|
164
|
+
groupsArg = objectGet(matchArg, 'groups')
|
|
165
|
+
name = objectGet(groupsArg, 'name')
|
|
166
|
+
text = objectGet(groupsArg, 'text')
|
|
167
|
+
textTrim = stringTrim(text)
|
|
168
|
+
|
|
169
|
+
# Keyword used outside of function?
|
|
170
|
+
if func == null:
|
|
171
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Function argument "' + name + '" outside function')
|
|
172
|
+
continue
|
|
173
|
+
endif
|
|
174
|
+
|
|
175
|
+
# Get the function argument model, if it exists
|
|
176
|
+
funcArgs = objectGet(func, 'args')
|
|
177
|
+
funcArg = null
|
|
178
|
+
if funcArgs != null:
|
|
179
|
+
for findArg in funcArgs:
|
|
180
|
+
if objectGet(findArg, 'name') == name:
|
|
181
|
+
funcArg = findArg
|
|
182
|
+
break
|
|
183
|
+
endif
|
|
184
|
+
endfor
|
|
185
|
+
endif
|
|
186
|
+
|
|
187
|
+
# Ignore leading argument documentation blank lines
|
|
188
|
+
if funcArg == null && textTrim == '':
|
|
189
|
+
continue
|
|
190
|
+
endif
|
|
191
|
+
|
|
192
|
+
# Add the function model arguments member, if necessary
|
|
193
|
+
if funcArgs == null:
|
|
194
|
+
funcArgs = []
|
|
195
|
+
objectSet(func, 'args', funcArgs)
|
|
196
|
+
endif
|
|
197
|
+
|
|
198
|
+
# Add the function argument model, if necessary
|
|
199
|
+
if funcArg == null:
|
|
200
|
+
funcArg = {'name': name, 'doc': []}
|
|
201
|
+
arrayPush(funcArgs, funcArg)
|
|
202
|
+
endif
|
|
203
|
+
|
|
204
|
+
# Add the function argument documentation line
|
|
205
|
+
arrayPush(objectGet(funcArg, 'doc'), text)
|
|
206
|
+
continue
|
|
207
|
+
endif
|
|
208
|
+
|
|
209
|
+
# Unknown documentation comment?
|
|
210
|
+
matchUnknown = regexMatch(baredocCLIMainRegexUnknown, line)
|
|
211
|
+
if matchUnknown != null:
|
|
212
|
+
groupsUnknown = objectGet(matchUnknown, 'groups')
|
|
213
|
+
unknown = objectGet(groupsUnknown, 'unknown')
|
|
214
|
+
arrayPush(errors, filename + ':' + (ixLine + 1) + ': Invalid documentation comment "' + unknown + '"')
|
|
215
|
+
continue
|
|
216
|
+
endif
|
|
217
|
+
endfor
|
|
218
|
+
|
|
219
|
+
# Create the sorted function model array
|
|
220
|
+
libraryFunctions = []
|
|
221
|
+
for funcName in arraySort(objectKeys(functions)):
|
|
222
|
+
arrayPush(libraryFunctions, objectGet(functions, funcName))
|
|
223
|
+
endfor
|
|
224
|
+
|
|
225
|
+
# Validate the library documentation model
|
|
226
|
+
for funcObj in libraryFunctions:
|
|
227
|
+
funcName = objectGet(funcObj, 'name')
|
|
228
|
+
if !objectHas(funcObj, 'group'):
|
|
229
|
+
arrayPush(errors, 'error: Function "' + funcName + '" missing group')
|
|
230
|
+
endif
|
|
231
|
+
if !objectHas(funcObj, 'doc'):
|
|
232
|
+
arrayPush(errors, 'error: Function "' + funcName + '" missing documentation')
|
|
233
|
+
endif
|
|
234
|
+
if objectGet(funcObj, 'ignore'):
|
|
235
|
+
objectDelete(functions, funcName)
|
|
236
|
+
endif
|
|
237
|
+
endfor
|
|
238
|
+
|
|
239
|
+
return errors
|
|
240
|
+
endfunction
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# baredocCLIParse regular expressions
|
|
244
|
+
baredocCLIMainRegexKey = regexNew('^\\s*(?:\\/\\/|#)\\s*\\$(?<key>function|group|doc|return|ignore):\\s?(?<text>.*)$')
|
|
245
|
+
baredocCLIMainRegexArg = regexNew('^\\s*(?:\\/\\/|#)\\s*\\$arg\\s+(?<name>[A-Za-z_][A-Za-z0-9_]*(?:\\.\\.\\.)?):\\s?(?<text>.*)$')
|
|
246
|
+
baredocCLIMainRegexUnknown = regexNew('^\\s*(?:\\/\\/|#)\\s*\\$(?<unknown>[^:]+):')
|