@bablr/cli 0.10.2 → 0.11.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.
Files changed (3) hide show
  1. package/bin/index.js +12 -32
  2. package/lib/syntax.js +40 -35
  3. package/package.json +14 -11
package/bin/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  /* global process */
4
4
 
5
+ import { spam as m } from '@bablr/boot';
5
6
  import { program } from 'commander';
6
7
  import { streamParse } from 'bablr';
7
8
  import { embeddedSourceFrom, readFromStream, stripTrailingNewline } from '@bablr/helpers/source';
@@ -9,25 +10,16 @@ import { debugEnhancers } from '@bablr/helpers/enhancers';
9
10
  import colorSupport from 'color-support';
10
11
  import { evaluateIO } from '@bablr/io-vm-node';
11
12
  import { generateCSTML } from '../lib/syntax.js';
12
- import {
13
- buildBasicNodeMatcher,
14
- buildNodeFlags,
15
- buildOpenNodeMatcher,
16
- buildPropertyMatcher,
17
- } from '@bablr/helpers/builders';
13
+ import { buildIdentifier } from '@bablr/helpers/builders';
18
14
  import { evaluateReturnAsync } from '@bablr/agast-helpers/tree';
19
- import { buildEmbeddedMatcher } from '@bablr/agast-vm-helpers/builders';
20
15
  import { o } from '@bablr/helpers/grammar';
21
16
 
22
17
  program
23
18
  .name('bablr')
24
19
  .option('-l, --language [URL]', 'The URL of the top BABLR language')
25
- .option('-p, --production [type]', 'The name of the top production type')
20
+ .option('-p, --production [name]', 'Shorthand: sets the named node matcher as root matcher')
21
+ .option('-m, --matcher [matcher]', 'Sets the root matcher')
26
22
  .option('-f, --format', 'Pretty-format CSTML output', true)
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')
31
23
  .option('-F, --no-format')
32
24
  .option('-v, --verbose', 'Prints debugging information to stderr')
33
25
  .option(
@@ -51,26 +43,12 @@ const options = {
51
43
  programOpts.color.toLowerCase() === 'always',
52
44
  };
53
45
 
54
- const language = await import(options.language);
46
+ const { default: language } = await import(options.language);
55
47
 
56
- const matcher = options.production
57
- ? buildEmbeddedMatcher(
58
- buildPropertyMatcher(
59
- null,
60
- null,
61
- buildBasicNodeMatcher(
62
- buildOpenNodeMatcher(
63
- buildNodeFlags({
64
- hasGap: options.gaps,
65
- fragment: options.fragment,
66
- token: options.token,
67
- cover: options.cover,
68
- }),
69
- options.production,
70
- ),
71
- ),
72
- ),
73
- )
48
+ const matcher = options.matcher
49
+ ? m({ raw: [options.matcher] })
50
+ : options.production
51
+ ? m`<${buildIdentifier(options.production)} />`
74
52
  : language.defaultMatcher;
75
53
 
76
54
  const logStderr = (...args) => {
@@ -81,6 +59,8 @@ const enhancers = options.verbose ? { ...debugEnhancers, agast: null } : {};
81
59
 
82
60
  const rawStream = process.stdin.setEncoding('utf-8');
83
61
 
62
+ Error.stackTraceLimit = 20;
63
+
84
64
  const output = evaluateIO(() =>
85
65
  generateCSTML(
86
66
  streamParse(
@@ -100,7 +80,7 @@ const output = evaluateIO(() =>
100
80
  {
101
81
  color: options.color,
102
82
  format: options.format,
103
- emitEffects: true,
83
+ verbose: options.verbose,
104
84
  },
105
85
  ),
106
86
  );
package/lib/syntax.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /* global process Promise */
2
2
 
3
3
  import emptyStack from '@iter-tools/imm-stack';
4
- import * as cstml from '@bablr/language-en-cstml';
5
- import * as verboseOutput from '@bablr/language-en-bablr-cli-verbose-output';
4
+ import cstml from '@bablr/language-en-cstml';
5
+ import verboseOutput from '@bablr/language-en-bablr-cli-verbose-output';
6
6
  import { streamParse } from 'bablr/enhanceable';
7
7
  import { Coroutine } from '@bablr/coroutine';
8
- import { StreamIterable, getStreamIterator } from '@bablr/agast-helpers/stream';
8
+ import { StreamIterable, getStreamIterator, wait } from '@bablr/agast-helpers/stream';
9
9
  import {
10
10
  generateAllOutput,
11
11
  writeCSTMLStrategy,
@@ -19,10 +19,11 @@ import {
19
19
  } from '@bablr/agast-vm-helpers/builders';
20
20
  import { OpenNodeTag, CloseNodeTag, ReferenceTag, LiteralTag } from '@bablr/agast-helpers/symbols';
21
21
  import {
22
- buildBasicNodeMatcher,
22
+ buildTreeNodeMatcher,
23
23
  buildNodeFlags,
24
- buildOpenNodeMatcher,
24
+ buildTreeNodeMatcherOpen,
25
25
  buildPropertyMatcher,
26
+ buildBoundNodeMatcher,
26
27
  } from '@bablr/helpers/builders';
27
28
  import { getFlagsWithGap, nodeFlags } from '@bablr/agast-helpers/builders';
28
29
 
@@ -31,7 +32,7 @@ let gapNodeFlags = getFlagsWithGap(nodeFlags);
31
32
  function* __higlightStrategy(tags) {
32
33
  const co = new Coroutine(getStreamIterator(tags));
33
34
 
34
- let types = emptyStack;
35
+ let names = emptyStack;
35
36
 
36
37
  let currentRef;
37
38
 
@@ -39,7 +40,7 @@ function* __higlightStrategy(tags) {
39
40
 
40
41
  for (;;) {
41
42
  if (co.current instanceof Promise) {
42
- co.current = yield co.current;
43
+ co.current = yield wait(co.current);
43
44
  }
44
45
 
45
46
  if (co.done) break;
@@ -47,53 +48,53 @@ function* __higlightStrategy(tags) {
47
48
  const tag = co.value;
48
49
 
49
50
  if (tag.type === OpenNodeTag) {
50
- const tagType = tag.value.type;
51
- const currentType = types.value;
51
+ const tagName = tag.value.name;
52
+ const currentName = names.value;
52
53
 
53
- types = types.push(tagType);
54
+ names = names.push(tagName);
54
55
 
55
56
  if (
56
- tagType === Symbol.for('LiteralTag') ||
57
- (tagType === Symbol.for('String') && currentRef.name === 'literalValue')
57
+ tagName === Symbol.for('LiteralTag') ||
58
+ (tagName === Symbol.for('String') && currentRef.name === 'literalValue')
58
59
  ) {
59
- if (tagType === Symbol.for('LiteralTag') || currentType === Symbol.for('OpenNodeTag')) {
60
+ if (tagName === Symbol.for('LiteralTag') || currentName === Symbol.for('OpenNodeTag')) {
60
61
  yield buildAnsiPushEffect('bold green');
61
- } else if (currentType === Symbol.for('OpenNodeMatcher')) {
62
+ } else if (currentName === Symbol.for('TreeNodeMatcherOpen')) {
62
63
  yield buildAnsiPushEffect('bold orange');
63
64
  } else {
64
65
  yield buildAnsiPushEffect();
65
66
  }
66
- } else if (tagType === Symbol.for('Pattern')) {
67
+ } else if (tagName === Symbol.for('Pattern')) {
67
68
  yield buildAnsiPushEffect('bold orange');
68
- } else if (tagType === Symbol.for('EscapeSequence')) {
69
+ } else if (tagName === Symbol.for('EscapeSequence')) {
69
70
  yield buildAnsiPushEffect('bold cyan');
70
- } else if (tagType === Symbol.for('Punctuator')) {
71
- if (currentType === Symbol.for('ReferenceTag')) {
71
+ } else if (tagName === Symbol.for('Identifier')) {
72
+ if (currentName === Symbol.for('ReferenceTag')) {
72
73
  yield buildAnsiPushEffect('bold gray');
73
- } else {
74
- yield buildAnsiPushEffect();
75
- }
76
- } else if (tagType === Symbol.for('Identifier')) {
77
- if (currentType === Symbol.for('ReferenceTag')) {
78
- yield buildAnsiPushEffect('bold gray');
79
- } else if (currentType === Symbol.for('Call')) {
74
+ } else if (currentName === Symbol.for('Call')) {
80
75
  yield buildAnsiPushEffect('magenta bold');
81
76
  } else {
82
77
  yield buildAnsiPushEffect();
83
78
  }
84
79
  } else if (
85
- tagType === Symbol.for('EnterProductionLine') ||
86
- tagType === Symbol.for('LeaveProductionLine')
80
+ tagName === Symbol.for('EnterProductionLine') ||
81
+ tagName === Symbol.for('LeaveProductionLine')
87
82
  ) {
88
83
  yield buildAnsiPushEffect('blue bold');
89
84
  } else if (
90
85
  (currentRef?.name === 'sigilToken' &&
91
- (currentType === Symbol.for('ExecSpamexInstructionLine') ||
92
- currentType === Symbol.for('ExecCSTMLInstructionLine'))) ||
93
- (currentType === Symbol.for('Call') &&
86
+ (currentName === Symbol.for('ExecSpamexInstructionLine') ||
87
+ currentName === Symbol.for('ExecCSTMLInstructionLine'))) ||
88
+ (currentName === Symbol.for('Call') &&
94
89
  (currentRef.name === 'openToken' || currentRef.name === 'closeToken'))
95
90
  ) {
96
91
  yield buildAnsiPushEffect('magenta bold');
92
+ } else if (tagName === null && tag.value.flags.token) {
93
+ if (currentName === Symbol.for('ReferenceTag')) {
94
+ yield buildAnsiPushEffect('bold gray');
95
+ } else {
96
+ yield buildAnsiPushEffect();
97
+ }
97
98
  } else {
98
99
  yield buildAnsiPushEffect();
99
100
  }
@@ -112,7 +113,7 @@ function* __higlightStrategy(tags) {
112
113
  yield tag;
113
114
 
114
115
  if (tag.type === CloseNodeTag || (tag.type === OpenNodeTag && tag.value.selfClosing)) {
115
- types = types.pop();
116
+ names = names.pop();
116
117
  yield buildAnsiPopEffect();
117
118
  }
118
119
 
@@ -131,16 +132,20 @@ export const generateCSTML = (tags, options = {}) => {
131
132
 
132
133
  if (options.color) {
133
134
  const input = generateAllOutput(outputInstructions);
134
- const language = options.emitEffects ? verboseOutput : cstml;
135
- const type = options.emitEffects ? 'Output' : 'Document';
135
+ const language = options.verbose ? verboseOutput : cstml;
136
+ const name = options.verbose ? 'Output' : 'Document';
136
137
 
137
138
  const tags = streamParse(
138
139
  language,
139
140
  buildEmbeddedMatcher(
140
141
  buildPropertyMatcher(
141
142
  null,
142
- null,
143
- buildBasicNodeMatcher(buildOpenNodeMatcher(buildNodeFlags(gapNodeFlags), type)),
143
+ buildBoundNodeMatcher(
144
+ [],
145
+ buildTreeNodeMatcher(
146
+ buildTreeNodeMatcherOpen(buildNodeFlags(gapNodeFlags), null, name),
147
+ ),
148
+ ),
144
149
  ),
145
150
  ),
146
151
  input,
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.10.2",
4
+ "version": "0.11.1",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -9,7 +9,7 @@
9
9
  "lib"
10
10
  ],
11
11
  "bin": {
12
- "bablr": "./bin/index.js"
12
+ "bablr": "bin/index.js"
13
13
  },
14
14
  "exports": {
15
15
  ".": "./bin/index.js",
@@ -17,16 +17,16 @@
17
17
  },
18
18
  "sideEffects": false,
19
19
  "dependencies": {
20
- "@bablr/agast-helpers": "0.9.0",
21
- "@bablr/agast-vm-helpers": "0.9.0",
22
- "@bablr/io-vm-node": "0.8.0",
23
- "@bablr/boot": "0.10.0",
20
+ "@bablr/agast-helpers": "0.10.0",
21
+ "@bablr/agast-vm-helpers": "0.10.0",
22
+ "@bablr/io-vm-node": "0.9.0",
23
+ "@bablr/boot": "0.11.0",
24
24
  "@bablr/coroutine": "0.1.0",
25
- "@bablr/helpers": "0.24.0",
26
- "@bablr/language-en-cstml": "0.11.0",
27
- "@bablr/language-en-bablr-cli-verbose-output": "0.9.0",
25
+ "@bablr/helpers": "0.25.0",
26
+ "@bablr/language-en-cstml": "0.12.0",
27
+ "@bablr/language-en-bablr-cli-verbose-output": "0.10.0",
28
28
  "@iter-tools/imm-stack": "1.2.0",
29
- "bablr": "0.10.2",
29
+ "bablr": "0.11.1",
30
30
  "color-support": "1.1.3",
31
31
  "commander": "^12.0.0"
32
32
  },
@@ -39,7 +39,10 @@
39
39
  "iter-tools-es": "^7.3.1",
40
40
  "prettier": "^2.6.2"
41
41
  },
42
- "repository": "github:bablr-lang/bablr-cli",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/bablr-lang/bablr-cli.git"
45
+ },
43
46
  "homepage": "https://github.com/bablr-lang/bablr-cli",
44
47
  "license": "MIT"
45
48
  }