@bablr/cli 0.3.1 → 0.4.1
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/bin/index.js +10 -4
- package/lib/syntax.js +26 -11
- package/package.json +10 -8
package/bin/index.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
/* global process */
|
|
4
4
|
|
|
5
5
|
import { program } from 'commander';
|
|
6
|
-
import { streamParse } from 'bablr';
|
|
6
|
+
import { streamParse, Context, AgastContext } 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';
|
|
10
10
|
import { evaluateIO } from '@bablr/io-vm-node';
|
|
11
11
|
import { createPrintCSTMLStrategy } from '../lib/syntax.js';
|
|
12
|
+
import { buildFullyQualifiedSpamMatcher } from '@bablr/agast-vm-helpers';
|
|
12
13
|
|
|
13
14
|
program
|
|
14
15
|
.option('-l, --language [URL]', 'The URL of the top BABLR language')
|
|
@@ -39,26 +40,31 @@ const options = {
|
|
|
39
40
|
|
|
40
41
|
const language = await import(options.language);
|
|
41
42
|
|
|
43
|
+
const matcher = buildFullyQualifiedSpamMatcher({}, language.canonicalURL, options.production);
|
|
44
|
+
|
|
42
45
|
const logStderr = (...args) => {
|
|
43
46
|
process.stderr.write(args.join(' ') + '\n');
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
const enhancers = options.verbose ? { ...debugEnhancers, agast: null } : {};
|
|
47
50
|
|
|
51
|
+
const ctx = Context.from(AgastContext.create(), language, enhancers.bablrProduction);
|
|
52
|
+
|
|
48
53
|
const rawStream = process.stdin.setEncoding('utf-8');
|
|
49
54
|
|
|
50
55
|
await evaluateIO(
|
|
51
56
|
createPrintCSTMLStrategy(
|
|
52
57
|
streamParse(
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
ctx,
|
|
59
|
+
matcher,
|
|
55
60
|
options.embedded
|
|
56
61
|
? embeddedSourceFrom(readFromStream(rawStream))
|
|
57
62
|
: stripTrailingNewline(readFromStream(rawStream)),
|
|
58
63
|
{},
|
|
59
64
|
{ enhancers, emitEffects: true },
|
|
60
|
-
)
|
|
65
|
+
),
|
|
61
66
|
{
|
|
67
|
+
ctx,
|
|
62
68
|
emitEffects: !!options.verbose,
|
|
63
69
|
color: options.color,
|
|
64
70
|
format: options.format,
|
package/lib/syntax.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/* global process Promise */
|
|
2
2
|
|
|
3
|
+
import emptyStack from '@iter-tools/imm-stack';
|
|
3
4
|
import * as cstml from '@bablr/language-en-cstml';
|
|
4
5
|
import * as verboseOutput from '@bablr/language-en-bablr-cli-verbose-output';
|
|
5
|
-
import { streamParse } from 'bablr/enhanceable';
|
|
6
|
+
import { streamParse, Context, AgastContext } from 'bablr/enhanceable';
|
|
6
7
|
import { Coroutine } from '@bablr/coroutine';
|
|
8
|
+
import { StreamIterable, getStreamIterator, generateAllOutput } from '@bablr/agast-helpers/stream';
|
|
7
9
|
import {
|
|
8
|
-
StreamIterable,
|
|
9
|
-
getStreamIterator,
|
|
10
|
-
generateCSTMLStrategy as generatePlainCSTMLStrategy,
|
|
11
10
|
generatePrettyCSTMLStrategy,
|
|
12
|
-
|
|
13
|
-
} from '@bablr/
|
|
11
|
+
generateCSTMLStrategy as generatePlainCSTMLStrategy,
|
|
12
|
+
} from '@bablr/helpers/stream';
|
|
14
13
|
import {
|
|
15
14
|
buildWriteEffect,
|
|
16
15
|
buildAnsiPushEffect,
|
|
17
16
|
buildAnsiPopEffect,
|
|
18
17
|
} from '@bablr/agast-helpers/builders';
|
|
18
|
+
import { buildFullyQualifiedSpamMatcher } from '@bablr/agast-vm-helpers';
|
|
19
19
|
|
|
20
20
|
function* __higlightStrategy(context, tokens) {
|
|
21
21
|
const co = new Coroutine(getStreamIterator(tokens));
|
|
22
22
|
|
|
23
|
+
let types = emptyStack;
|
|
24
|
+
|
|
23
25
|
let currentRef;
|
|
24
26
|
|
|
25
27
|
co.advance();
|
|
@@ -35,7 +37,9 @@ function* __higlightStrategy(context, tokens) {
|
|
|
35
37
|
|
|
36
38
|
if (token.type === 'OpenNodeTag') {
|
|
37
39
|
const tagType = token.value.type;
|
|
38
|
-
const currentType =
|
|
40
|
+
const currentType = types.value;
|
|
41
|
+
|
|
42
|
+
types = types.push(tagType);
|
|
39
43
|
|
|
40
44
|
if (tagType === 'Literal' || (tagType === 'String' && currentRef.name === 'intrinsicValue')) {
|
|
41
45
|
if (tagType === 'Literal' || currentType === 'OpenNodeTag') {
|
|
@@ -77,6 +81,7 @@ function* __higlightStrategy(context, tokens) {
|
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
if (token.type === 'CloseNodeTag') {
|
|
84
|
+
types = types.pop();
|
|
80
85
|
yield buildAnsiPopEffect();
|
|
81
86
|
}
|
|
82
87
|
|
|
@@ -98,7 +103,10 @@ export const higlightStrategy = (context, tokens) => {
|
|
|
98
103
|
export const createPrintCSTMLStrategy =
|
|
99
104
|
(tokens, options = {}) =>
|
|
100
105
|
() => {
|
|
101
|
-
const strategyOptions = {
|
|
106
|
+
const strategyOptions = {
|
|
107
|
+
ctx: options.ctx,
|
|
108
|
+
emitEffects: options.emitEffects,
|
|
109
|
+
};
|
|
102
110
|
const outputInstructions = options.format
|
|
103
111
|
? generatePrettyCSTMLStrategy(tokens, strategyOptions)
|
|
104
112
|
: generatePlainCSTMLStrategy(tokens, strategyOptions);
|
|
@@ -106,9 +114,16 @@ export const createPrintCSTMLStrategy =
|
|
|
106
114
|
if (options.color) {
|
|
107
115
|
const input = generateAllOutput(outputInstructions);
|
|
108
116
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
const language = options.emitEffects ? verboseOutput : cstml;
|
|
118
|
+
const type = options.emitEffects ? 'Output' : 'Document';
|
|
119
|
+
|
|
120
|
+
const context = Context.from(AgastContext.create(), language);
|
|
121
|
+
|
|
122
|
+
const tokens = streamParse(
|
|
123
|
+
context,
|
|
124
|
+
buildFullyQualifiedSpamMatcher({}, language.canonicalURL, type),
|
|
125
|
+
input,
|
|
126
|
+
);
|
|
112
127
|
|
|
113
128
|
return higlightStrategy(context, tokens);
|
|
114
129
|
} else {
|
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.4.1",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -17,14 +17,16 @@
|
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@bablr/agast-helpers": "0.2
|
|
21
|
-
"@bablr/
|
|
22
|
-
"@bablr/
|
|
20
|
+
"@bablr/agast-helpers": "0.3.2",
|
|
21
|
+
"@bablr/agast-vm-helpers": "0.3.1",
|
|
22
|
+
"@bablr/io-vm-node": "0.3.0",
|
|
23
|
+
"@bablr/boot": "0.4.0",
|
|
23
24
|
"@bablr/coroutine": "0.1.0",
|
|
24
|
-
"@bablr/helpers": "0.
|
|
25
|
-
"@bablr/language-en-cstml": "0.4.
|
|
26
|
-
"@bablr/language-en-bablr-cli-verbose-output": "0.
|
|
27
|
-
"
|
|
25
|
+
"@bablr/helpers": "0.18.0",
|
|
26
|
+
"@bablr/language-en-cstml": "0.4.1",
|
|
27
|
+
"@bablr/language-en-bablr-cli-verbose-output": "0.3.0",
|
|
28
|
+
"@iter-tools/imm-stack": "1.1.0",
|
|
29
|
+
"bablr": "0.4.0",
|
|
28
30
|
"color-support": "1.1.3",
|
|
29
31
|
"commander": "12.0.0"
|
|
30
32
|
},
|