@bablr/cli 0.6.4 → 0.7.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.
Files changed (3) hide show
  1. package/bin/index.js +21 -11
  2. package/lib/syntax.js +49 -41
  3. package/package.json +13 -10
package/bin/index.js CHANGED
@@ -3,13 +3,18 @@
3
3
  /* global process */
4
4
 
5
5
  import { program } from 'commander';
6
- import { streamParse, Context, AgastContext } from 'bablr';
6
+ import { streamParse, Context } 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
- import { createPrintCSTMLStrategy } from '../lib/syntax.js';
12
- import { buildFullyQualifiedSpamMatcher } from '@bablr/helpers/builders';
11
+ import { generateCSTML } from '../lib/syntax.js';
12
+ import {
13
+ buildBasicNodeMatcher,
14
+ buildOpenNodeMatcher,
15
+ buildPropertyMatcher,
16
+ } from '@bablr/helpers/builders';
17
+ import { buildEmbeddedMatcher, evaluateReturnAsync } from '@bablr/agast-helpers/tree';
13
18
 
14
19
  program
15
20
  .name('bablr')
@@ -42,10 +47,13 @@ const options = {
42
47
 
43
48
  const language = await import(options.language);
44
49
 
45
- const matcher = buildFullyQualifiedSpamMatcher(
46
- { hasGap: options.gaps },
47
- language.canonicalURL,
48
- options.production,
50
+ const matcher = buildEmbeddedMatcher(
51
+ buildPropertyMatcher(
52
+ null,
53
+ buildBasicNodeMatcher(
54
+ buildOpenNodeMatcher({ hasGap: options.gaps }, language.canonicalURL, options.production),
55
+ ),
56
+ ),
49
57
  );
50
58
 
51
59
  const logStderr = (...args) => {
@@ -54,12 +62,12 @@ const logStderr = (...args) => {
54
62
 
55
63
  const enhancers = options.verbose ? { ...debugEnhancers, agast: null } : {};
56
64
 
57
- const ctx = Context.from(AgastContext.create(), language, enhancers.bablrProduction);
65
+ const ctx = Context.from(language, enhancers.bablrProduction);
58
66
 
59
67
  const rawStream = process.stdin.setEncoding('utf-8');
60
68
 
61
- await evaluateIO(
62
- createPrintCSTMLStrategy(
69
+ const output = evaluateIO(() =>
70
+ generateCSTML(
63
71
  streamParse(
64
72
  ctx,
65
73
  matcher,
@@ -71,9 +79,11 @@ await evaluateIO(
71
79
  ),
72
80
  {
73
81
  ctx,
74
- emitEffects: !!options.verbose,
75
82
  color: options.color,
76
83
  format: options.format,
84
+ emitEffects: true,
77
85
  },
78
86
  ),
79
87
  );
88
+
89
+ await evaluateReturnAsync(output);
package/lib/syntax.js CHANGED
@@ -3,23 +3,30 @@
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, Context, AgastContext } from 'bablr/enhanceable';
6
+ import { streamParse, Context } from 'bablr/enhanceable';
7
7
  import { Coroutine } from '@bablr/coroutine';
8
- import { StreamIterable, getStreamIterator, generateAllOutput } from '@bablr/agast-helpers/stream';
9
8
  import {
10
- generatePrettyCSTMLStrategy,
11
- generateCSTMLStrategy as generatePlainCSTMLStrategy,
12
- } from '@bablr/helpers/stream';
9
+ StreamIterable,
10
+ generateAllOutput,
11
+ getStreamIterator,
12
+ writeCSTMLStrategy,
13
+ writePrettyCSTMLStrategy,
14
+ } from '@bablr/agast-helpers/stream';
13
15
  import {
14
16
  buildWriteEffect,
15
17
  buildAnsiPushEffect,
16
18
  buildAnsiPopEffect,
19
+ buildEmbeddedMatcher,
17
20
  } from '@bablr/agast-helpers/builders';
18
- import { buildFullyQualifiedSpamMatcher } from '@bablr/helpers/builders';
19
21
  import { OpenNodeTag, CloseNodeTag, ReferenceTag, LiteralTag } from '@bablr/agast-helpers/symbols';
22
+ import {
23
+ buildBasicNodeMatcher,
24
+ buildOpenNodeMatcher,
25
+ buildPropertyMatcher,
26
+ } from '@bablr/helpers/builders';
20
27
 
21
- function* __higlightStrategy(tokens, options) {
22
- const co = new Coroutine(getStreamIterator(tokens));
28
+ function* __higlightStrategy(tags) {
29
+ const co = new Coroutine(getStreamIterator(tags));
23
30
 
24
31
  let types = emptyStack;
25
32
 
@@ -77,7 +84,7 @@ function* __higlightStrategy(tokens, options) {
77
84
  (currentRef?.name === 'sigilToken' &&
78
85
  (currentType === Symbol.for('ExecSpamexInstructionLine') ||
79
86
  currentType === Symbol.for('ExecCSTMLInstructionLine'))) ||
80
- (currentType === Symbol.for('Tuple') &&
87
+ (currentType === Symbol.for('Call') &&
81
88
  (currentRef.name === 'openToken' || currentRef.name === 'closeToken'))
82
89
  ) {
83
90
  yield buildAnsiPushEffect('magenta bold');
@@ -102,41 +109,42 @@ function* __higlightStrategy(tokens, options) {
102
109
  yield buildAnsiPopEffect();
103
110
  }
104
111
 
112
+ yield tag;
113
+
105
114
  co.advance();
106
115
  }
107
116
  }
108
117
 
109
- export const higlightStrategy = (tokens, options) => {
110
- return new StreamIterable(__higlightStrategy(tokens, options));
118
+ export const higlightStrategy = (tags) => {
119
+ return new StreamIterable(__higlightStrategy(tags));
111
120
  };
112
121
 
113
- export const createPrintCSTMLStrategy =
114
- (tokens, options = {}) =>
115
- () => {
116
- const strategyOptions = {
117
- ctx: options.ctx,
118
- emitEffects: options.emitEffects,
119
- };
120
- const outputInstructions = options.format
121
- ? generatePrettyCSTMLStrategy(tokens, strategyOptions)
122
- : generatePlainCSTMLStrategy(tokens, strategyOptions);
123
-
124
- if (options.color) {
125
- const input = generateAllOutput(outputInstructions);
126
-
127
- const language = options.emitEffects ? verboseOutput : cstml;
128
- const type = options.emitEffects ? 'Output' : 'Document';
129
-
130
- const context = Context.from(AgastContext.create(), language);
131
-
132
- const tokens = streamParse(
133
- context,
134
- buildFullyQualifiedSpamMatcher({}, language.canonicalURL, type),
135
- input,
136
- );
137
-
138
- return higlightStrategy(tokens, { ctx: context });
139
- } else {
140
- return outputInstructions;
141
- }
142
- };
122
+ export const generateCSTML = (tags, options = {}) => {
123
+ const strategyOptions = { ctx: options.ctx };
124
+ const outputInstructions = options.format
125
+ ? writePrettyCSTMLStrategy(tags, strategyOptions)
126
+ : writeCSTMLStrategy(tags, strategyOptions);
127
+
128
+ if (options.color) {
129
+ const input = generateAllOutput(outputInstructions);
130
+ const language = options.emitEffects ? verboseOutput : cstml;
131
+ const type = options.emitEffects ? 'Output' : 'Document';
132
+
133
+ const context = Context.from(language);
134
+
135
+ const tags = streamParse(
136
+ context,
137
+ buildEmbeddedMatcher(
138
+ buildPropertyMatcher(
139
+ null,
140
+ buildBasicNodeMatcher(buildOpenNodeMatcher({}, language.canonicalURL, type)),
141
+ ),
142
+ ),
143
+ input,
144
+ );
145
+
146
+ return higlightStrategy(tags, { ctx: context });
147
+ } else {
148
+ return outputInstructions;
149
+ }
150
+ };
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@bablr/cli",
3
3
  "description": "CLI for running BABLR parsers",
4
- "version": "0.6.4",
4
+ "version": "0.7.0",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
- "files": ["bin", "lib"],
7
+ "files": [
8
+ "bin",
9
+ "lib"
10
+ ],
8
11
  "bin": {
9
12
  "bablr": "./bin/index.js"
10
13
  },
@@ -14,16 +17,16 @@
14
17
  },
15
18
  "sideEffects": false,
16
19
  "dependencies": {
17
- "@bablr/agast-helpers": "^0.5.0",
18
- "@bablr/agast-vm-helpers": "^0.5.0",
19
- "@bablr/io-vm-node": "^0.5.0",
20
- "@bablr/boot": "^0.6.0",
20
+ "@bablr/agast-helpers": "0.6.0",
21
+ "@bablr/agast-vm-helpers": "0.6.0",
22
+ "@bablr/io-vm-node": "0.6.0",
23
+ "@bablr/boot": "0.7.0",
21
24
  "@bablr/coroutine": "0.1.0",
22
- "@bablr/helpers": "^0.20.0",
23
- "@bablr/language-en-cstml": "^0.6.0",
24
- "@bablr/language-en-bablr-cli-verbose-output": "^0.5.0",
25
+ "@bablr/helpers": "0.21.1",
26
+ "@bablr/language-en-cstml": "0.8.0",
27
+ "@bablr/language-en-bablr-cli-verbose-output": "0.6.0",
25
28
  "@iter-tools/imm-stack": "1.1.0",
26
- "bablr": "^0.6.0",
29
+ "bablr": "0.7.0",
27
30
  "color-support": "1.1.3",
28
31
  "commander": "^12.0.0"
29
32
  },