@bablr/cli 0.8.0 → 0.9.0
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/README.md +2 -62
- package/bin/index.js +23 -8
- package/lib/syntax.js +12 -13
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -2,26 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
This is the CLI runner for BABLR. If you have a BABLR grammar for a computer language, this tool allows you to use it to do streaming parsing. Parse results are presented in CSTML.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This package has no built-in language support, but rather expects you to supply a valid import specifier referring to a BABLR language. This likely means that you will likely need to start by installing both the parser and the language you wish to use.
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
Usage: bablr [options]
|
|
11
|
-
|
|
12
|
-
Options:
|
|
13
|
-
-l, --language [URL] The URL of the top BABLR language
|
|
14
|
-
-p, --production [type] The name of the top production type
|
|
15
|
-
-f, --format Pretty-format CSTML output (default: true)
|
|
16
|
-
-F, --no-format
|
|
17
|
-
-v, --verbose Prints debugging information to stderr
|
|
18
|
-
-c, --color [WHEN] When to use ANSI escape colors
|
|
19
|
-
WHEN: "auto" | "always" | "never" (default: "auto")
|
|
20
|
-
-e, --embedded Requires quoted input but enables gap parsing
|
|
21
|
-
-h, --help display help for command
|
|
22
|
-
```
|
|
5
|
+
For complete information see the [bablr-cli reference documentation](https://docs.bablr.org/reference/bablr-cli)
|
|
23
6
|
|
|
24
|
-
##
|
|
7
|
+
## Usage
|
|
25
8
|
|
|
26
9
|
```bash
|
|
27
10
|
bablr -l @bablr/language-en-json -p Expression -f << 'EOF'
|
|
@@ -32,46 +15,3 @@ bablr -l @bablr/language-en-json -p Expression -f << 'EOF'
|
|
|
32
15
|
]
|
|
33
16
|
EOF
|
|
34
17
|
```
|
|
35
|
-
|
|
36
|
-
Running the above command produces the following output. Note that this is a stream parse so lines of output will appear one by one as fast as the input can be read and parsed.
|
|
37
|
-
|
|
38
|
-
```cstml
|
|
39
|
-
<!0:cstml bablr-language='https://github.com/bablr-lang/language-en-json'>
|
|
40
|
-
<>
|
|
41
|
-
.:
|
|
42
|
-
<Array>
|
|
43
|
-
openToken: <*Punctuator '[' balanced=']' />
|
|
44
|
-
<#*Space:Space '\n ' />
|
|
45
|
-
separators[]: []
|
|
46
|
-
elements[]: []
|
|
47
|
-
elements[]:
|
|
48
|
-
<Number span='Number'>
|
|
49
|
-
wholePart:
|
|
50
|
-
<Integer>
|
|
51
|
-
signToken: null
|
|
52
|
-
value: <*UnsignedInteger '1' />
|
|
53
|
-
</>
|
|
54
|
-
fractionalSeparatorToken: null
|
|
55
|
-
fractionalPart: null
|
|
56
|
-
exponentSeparatorToken: null
|
|
57
|
-
exponentPart: null
|
|
58
|
-
</>
|
|
59
|
-
separators[]: <*Punctuator ',' />
|
|
60
|
-
<#*Space:Space '\n ' />
|
|
61
|
-
elements[]:
|
|
62
|
-
<Boolean>
|
|
63
|
-
sigilToken: <*Keyword 'true' />
|
|
64
|
-
</>
|
|
65
|
-
separators[]: <*Punctuator ',' />
|
|
66
|
-
<#*Space:Space '\n ' />
|
|
67
|
-
elements[]:
|
|
68
|
-
<String>
|
|
69
|
-
openToken: <*Punctuator '"' balanced='"' balancedSpan='String' />
|
|
70
|
-
content: <*StringContent '3' />
|
|
71
|
-
closeToken: <*Punctuator '"' balancer />
|
|
72
|
-
<#*Space:Space '\n' />
|
|
73
|
-
</>
|
|
74
|
-
closeToken: <*Punctuator ']' balancer />
|
|
75
|
-
</>
|
|
76
|
-
</>
|
|
77
|
-
```
|
package/bin/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* global process */
|
|
4
4
|
|
|
5
5
|
import { program } from 'commander';
|
|
6
|
-
import { streamParse
|
|
6
|
+
import { streamParse } from 'bablr';
|
|
7
7
|
import { embeddedSourceFrom, readFromStream, stripTrailingNewline } from '@bablr/helpers/source';
|
|
8
8
|
import { debugEnhancers } from '@bablr/helpers/enhancers';
|
|
9
9
|
import colorSupport from 'color-support';
|
|
@@ -11,6 +11,7 @@ import { evaluateIO } from '@bablr/io-vm-node';
|
|
|
11
11
|
import { generateCSTML } from '../lib/syntax.js';
|
|
12
12
|
import {
|
|
13
13
|
buildBasicNodeMatcher,
|
|
14
|
+
buildNodeFlags,
|
|
14
15
|
buildOpenNodeMatcher,
|
|
15
16
|
buildPropertyMatcher,
|
|
16
17
|
} from '@bablr/helpers/builders';
|
|
@@ -23,7 +24,10 @@ program
|
|
|
23
24
|
.option('-l, --language [URL]', 'The URL of the top BABLR language')
|
|
24
25
|
.option('-p, --production [type]', 'The name of the top production type')
|
|
25
26
|
.option('-f, --format', 'Pretty-format CSTML output', true)
|
|
26
|
-
.option('-g, --gaps', '
|
|
27
|
+
.option('-g, --gaps', 'Sets hasGap flag on root matcher')
|
|
28
|
+
.option('-r, --fragment', 'Sets fragment flag on root matcher')
|
|
29
|
+
.option('-t --token', 'Sets token flag on root matcher')
|
|
30
|
+
.option('-o --cover', 'Sets cover flag on root matcher')
|
|
27
31
|
.option('-F, --no-format')
|
|
28
32
|
.option('-v, --verbose', 'Prints debugging information to stderr')
|
|
29
33
|
.option(
|
|
@@ -51,9 +55,18 @@ const language = await import(options.language);
|
|
|
51
55
|
|
|
52
56
|
const matcher = buildEmbeddedMatcher(
|
|
53
57
|
buildPropertyMatcher(
|
|
58
|
+
null,
|
|
54
59
|
null,
|
|
55
60
|
buildBasicNodeMatcher(
|
|
56
|
-
buildOpenNodeMatcher(
|
|
61
|
+
buildOpenNodeMatcher(
|
|
62
|
+
buildNodeFlags({
|
|
63
|
+
hasGap: options.gaps,
|
|
64
|
+
fragment: options.fragment,
|
|
65
|
+
token: options.token,
|
|
66
|
+
cover: options.cover,
|
|
67
|
+
}),
|
|
68
|
+
options.production,
|
|
69
|
+
),
|
|
57
70
|
),
|
|
58
71
|
),
|
|
59
72
|
);
|
|
@@ -64,23 +77,25 @@ const logStderr = (...args) => {
|
|
|
64
77
|
|
|
65
78
|
const enhancers = options.verbose ? { ...debugEnhancers, agast: null } : {};
|
|
66
79
|
|
|
67
|
-
const ctx = Context.from(language, enhancers.bablrProduction);
|
|
68
|
-
|
|
69
80
|
const rawStream = process.stdin.setEncoding('utf-8');
|
|
70
81
|
|
|
71
82
|
const output = evaluateIO(() =>
|
|
72
83
|
generateCSTML(
|
|
73
84
|
streamParse(
|
|
74
|
-
|
|
85
|
+
language,
|
|
75
86
|
matcher,
|
|
76
87
|
options.embedded
|
|
77
88
|
? embeddedSourceFrom(readFromStream(rawStream))
|
|
78
89
|
: stripTrailingNewline(readFromStream(rawStream)),
|
|
79
90
|
o({}),
|
|
80
|
-
{
|
|
91
|
+
{
|
|
92
|
+
enhancers,
|
|
93
|
+
emitEffects: true,
|
|
94
|
+
holdShiftedNodes: !options.gaps,
|
|
95
|
+
holdUndefinedAttributes: !options.gaps,
|
|
96
|
+
},
|
|
81
97
|
),
|
|
82
98
|
{
|
|
83
|
-
ctx,
|
|
84
99
|
color: options.color,
|
|
85
100
|
format: options.format,
|
|
86
101
|
emitEffects: true,
|
package/lib/syntax.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import emptyStack from '@iter-tools/imm-stack';
|
|
4
4
|
import * as cstml from '@bablr/language-en-cstml';
|
|
5
5
|
import * as verboseOutput from '@bablr/language-en-bablr-cli-verbose-output';
|
|
6
|
-
import { streamParse
|
|
6
|
+
import { streamParse } from 'bablr/enhanceable';
|
|
7
7
|
import { Coroutine } from '@bablr/coroutine';
|
|
8
8
|
import { StreamIterable, getStreamIterator } from '@bablr/agast-helpers/stream';
|
|
9
9
|
import {
|
|
@@ -20,9 +20,13 @@ import {
|
|
|
20
20
|
import { OpenNodeTag, CloseNodeTag, ReferenceTag, LiteralTag } from '@bablr/agast-helpers/symbols';
|
|
21
21
|
import {
|
|
22
22
|
buildBasicNodeMatcher,
|
|
23
|
+
buildNodeFlags,
|
|
23
24
|
buildOpenNodeMatcher,
|
|
24
25
|
buildPropertyMatcher,
|
|
25
26
|
} from '@bablr/helpers/builders';
|
|
27
|
+
import { getFlagsWithGap, nodeFlags } from '@bablr/agast-helpers/builders';
|
|
28
|
+
|
|
29
|
+
let gapNodeFlags = getFlagsWithGap(nodeFlags);
|
|
26
30
|
|
|
27
31
|
function* __higlightStrategy(tags) {
|
|
28
32
|
const co = new Coroutine(getStreamIterator(tags));
|
|
@@ -59,10 +63,7 @@ function* __higlightStrategy(tags) {
|
|
|
59
63
|
} else {
|
|
60
64
|
yield buildAnsiPushEffect();
|
|
61
65
|
}
|
|
62
|
-
} else if (
|
|
63
|
-
tagType === Symbol.for('Pattern') &&
|
|
64
|
-
tag.value.language !== 'https://bablr.org/languages/core/en/spamex'
|
|
65
|
-
) {
|
|
66
|
+
} else if (tagType === Symbol.for('Pattern')) {
|
|
66
67
|
yield buildAnsiPushEffect('bold orange');
|
|
67
68
|
} else if (tagType === Symbol.for('EscapeSequence')) {
|
|
68
69
|
yield buildAnsiPushEffect('bold cyan');
|
|
@@ -119,30 +120,28 @@ export const higlightStrategy = (tags) => {
|
|
|
119
120
|
};
|
|
120
121
|
|
|
121
122
|
export const generateCSTML = (tags, options = {}) => {
|
|
122
|
-
const strategyOptions = { ctx: options.ctx };
|
|
123
123
|
const outputInstructions = options.format
|
|
124
|
-
? writePrettyCSTMLStrategy(tags
|
|
125
|
-
: writeCSTMLStrategy(tags
|
|
124
|
+
? writePrettyCSTMLStrategy(tags)
|
|
125
|
+
: writeCSTMLStrategy(tags);
|
|
126
126
|
|
|
127
127
|
if (options.color) {
|
|
128
128
|
const input = generateAllOutput(outputInstructions);
|
|
129
129
|
const language = options.emitEffects ? verboseOutput : cstml;
|
|
130
130
|
const type = options.emitEffects ? 'Output' : 'Document';
|
|
131
131
|
|
|
132
|
-
const context = Context.from(language);
|
|
133
|
-
|
|
134
132
|
const tags = streamParse(
|
|
135
|
-
|
|
133
|
+
language,
|
|
136
134
|
buildEmbeddedMatcher(
|
|
137
135
|
buildPropertyMatcher(
|
|
138
136
|
null,
|
|
139
|
-
|
|
137
|
+
null,
|
|
138
|
+
buildBasicNodeMatcher(buildOpenNodeMatcher(buildNodeFlags(gapNodeFlags), type)),
|
|
140
139
|
),
|
|
141
140
|
),
|
|
142
141
|
input,
|
|
143
142
|
);
|
|
144
143
|
|
|
145
|
-
return higlightStrategy(tags
|
|
144
|
+
return higlightStrategy(tags);
|
|
146
145
|
} else {
|
|
147
146
|
return outputInstructions;
|
|
148
147
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/cli",
|
|
3
3
|
"description": "CLI for running BABLR parsers",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@bablr/agast-helpers": "0.
|
|
21
|
-
"@bablr/agast-vm-helpers": "0.
|
|
20
|
+
"@bablr/agast-helpers": "0.8.0",
|
|
21
|
+
"@bablr/agast-vm-helpers": "0.8.0",
|
|
22
22
|
"@bablr/io-vm-node": "0.7.0",
|
|
23
|
-
"@bablr/boot": "0.
|
|
23
|
+
"@bablr/boot": "0.9.0",
|
|
24
24
|
"@bablr/coroutine": "0.1.0",
|
|
25
|
-
"@bablr/helpers": "0.
|
|
26
|
-
"@bablr/language-en-cstml": "0.
|
|
27
|
-
"@bablr/language-en-bablr-cli-verbose-output": "0.
|
|
25
|
+
"@bablr/helpers": "0.23.0",
|
|
26
|
+
"@bablr/language-en-cstml": "0.10.0",
|
|
27
|
+
"@bablr/language-en-bablr-cli-verbose-output": "0.8.0",
|
|
28
28
|
"@iter-tools/imm-stack": "1.1.0",
|
|
29
|
-
"bablr": "0.
|
|
29
|
+
"bablr": "0.9.0",
|
|
30
30
|
"color-support": "1.1.3",
|
|
31
31
|
"commander": "^12.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#
|
|
34
|
+
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#c97bfa4b3663f8378e9b3e42bb5a41e685406cf9",
|
|
35
35
|
"enhanced-resolve": "^5.12.0",
|
|
36
36
|
"eslint": "^8.32.0",
|
|
37
37
|
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
|