Skip to content

Commit 8393d04

Browse files
committed
Initial commit
0 parents  commit 8393d04

8 files changed

+137
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
[play/fixture]
10+
insert_final_newline = false
11+
12+
[{*.{js,mjs,d.ts,json,md}, .babelrc, .yaml}]
13+
charset = utf-8
14+
indent_style = space
15+
indent_size = 2

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/fixtures/*

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@bablr/eslint-config-base');

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
yarn.lock
3+
pnpm-lock.yaml
4+
package-lock.json

.prettierrc.cjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
printWidth: 100,
3+
trailingComma: 'all',
4+
singleQuote: true,
5+
6+
overrides: [
7+
{
8+
files: '*.md',
9+
options: {
10+
printWidth: 60,
11+
},
12+
},
13+
{
14+
files: 'ARCHITECTURE.md',
15+
options: {
16+
printWidth: 80,
17+
},
18+
},
19+
],
20+
};

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Conrad Buck
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bin/index.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#! /usr/bin/env node
2+
3+
/* global process */
4+
5+
import { program } from 'commander';
6+
import { streamParseAsync as streamParse } from 'bablr';
7+
import { sourceFromReadStream } from '@bablr/helpers/source';
8+
import { printTerminal } from '@bablr/agast-helpers/stream';
9+
10+
program
11+
.option('-l, --language [URL]', 'The URL of the BABLR language to parse with')
12+
.option('-p, --production [type]', 'The top-level type for the parse')
13+
.option('-f, --formatted', 'Whether to pretty-format the CSTML output')
14+
.parse(process.argv);
15+
16+
const options = program.opts();
17+
18+
const language = await import(options.language);
19+
20+
let indentAmt = 0;
21+
22+
for await (const token of streamParse(
23+
language,
24+
options.production,
25+
sourceFromReadStream(process.stdin.setEncoding('utf-8')),
26+
)) {
27+
if (token.type === 'OpenNodeTag') {
28+
indentAmt++;
29+
}
30+
31+
const out = options.formatted
32+
? `${' '.repeat(indentAmt)}${printTerminal(token)}\n`
33+
: printTerminal(token);
34+
35+
if (token.type === 'CloseNodeTag') {
36+
indentAmt--;
37+
}
38+
39+
process.stdout.write(out);
40+
}

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@bablr/cli",
3+
"description": "CLI for running BABLR parsers",
4+
"version": "0.0.0",
5+
"author": "Conrad Buck<[email protected]>",
6+
"type": "module",
7+
"files": [
8+
"bin"
9+
],
10+
"bin": {
11+
"bablr": "./bin/index.js"
12+
},
13+
"exports": {
14+
".": "./bin/index.js"
15+
},
16+
"sideEffects": false,
17+
"dependencies": {
18+
"@bablr/agast-helpers": "github:bablr-lang/agast-helpers#caaa3389b422a03bc0f79e377fb499278bcd9109",
19+
"@bablr/helpers": "github:bablr-lang/bablr-helpers#3092387d0a5833c896ab3e168d546a6d3c896985",
20+
"bablr": "github:bablr-lang/bablr#279a549d0bf730e7d8ed008386ff157fc5b0fecd",
21+
"commander": "12.0.0"
22+
},
23+
"devDependencies": {
24+
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
25+
"enhanced-resolve": "^5.12.0",
26+
"eslint": "^8.32.0",
27+
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
28+
"eslint-plugin-import": "^2.27.5",
29+
"iter-tools-es": "^7.3.1",
30+
"prettier": "^2.6.2"
31+
},
32+
"repository": "github:bablr-lang/bablr-cli",
33+
"homepage": "https://github.com/bablr-lang/bablr-cli",
34+
"license": "MIT"
35+
}

0 commit comments

Comments
 (0)