Skip to content

Commit 42eb98e

Browse files
committed
save these so they don't get lost
1 parent 12b8675 commit 42eb98e

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
metasqlqueryparser.js

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
metasqlqueryparser.js: metasqlqueryparser.peg
2+
node_modules/.bin/pegjs metasqlqueryparser.js
3+
4+
test: metasqlqueryparser.js
5+
node driver.js

driver.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env node
2+
3+
var parser = require('metasqlqueryparser')
4+
, util = require('util')
5+
, fs = require('fs')
6+
, args = process.argv.slice(2)
7+
, ifile, istream
8+
, ofile, ostream
9+
, pfile, pstream
10+
, params
11+
, mql
12+
, sql
13+
;
14+
15+
function printVersion() {
16+
util.puts("mqlparser " + mqlparser.VERSION);
17+
}
18+
19+
function usage() {
20+
util.puts("Usage: mqlparser [ -o outputfile ] [ -p paramsfile ] input_file");
21+
}
22+
23+
function exit(code, showUsage) {
24+
if (isString(code)) {
25+
utils.puts(code);
26+
if (showUsage) usage();
27+
process.exit(1);
28+
} else if (isNumber(code)) {
29+
if (showUsage) usage();
30+
process.exit(code);
31+
} else {
32+
if (showUsage) usage();
33+
process.exit(0);
34+
}
35+
}
36+
37+
while (args.length > 0) {
38+
switch (args[0]) {
39+
case '-o':
40+
if (args.length < 2) {
41+
exit("Missing outputfile", true);
42+
}
43+
ofile = args[1];
44+
args.shift();
45+
break;
46+
case '-p':
47+
if (args.length < 2) {
48+
exit("Missing paramsfile", true);
49+
}
50+
pfile = args[1];
51+
args.shift();
52+
break;
53+
default:
54+
ifile = args[0];
55+
if (args.length > 1) {
56+
utils.puts("ignoring extra args");
57+
args.shift(args.length);
58+
}
59+
break;
60+
}
61+
args.shift();
62+
}
63+
64+
istream = ifile ? fs.createReadStream(ifile) : process.stdin;
65+
ostream = ofile ? fs.createWriteStream(ofile) : process.stdout;
66+
pstream = pfile ? fs.createReadStream(pfile);
67+
68+
istream.on('error', function() { exit('Cannot read from "' + ifile + '"'); });
69+
ostream.on('error', function() { exit('Cannot write to "' + ofile + '"'); });
70+
pstream.on('error', function() { exit('Cannot read from "' + pfile + '"'); });

package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "mql-parser",
3+
"version": "0.0.1",
4+
"description": "A parser for OpenRPT's MetaSQL.",
5+
"keywords": [ "metasql", "openrpt", "query language", "xtuple" ],
6+
"homepage": "http://github.com/gilmoskowitz/mql-parser",
7+
"bugs": "http://github.com/gilmoskowitz/mql-parser/issues",
8+
"repository": {
9+
"type": "git",
10+
"url": "http://github.com/gilmoskowitz/mql-parser"
11+
},
12+
"license": "undecided",
13+
"author": { "name": "Gil Moskowitz",
14+
"email": "[email protected]"
15+
},
16+
"files": [ "metasqlqueryparser.peg", "driver.js" ],
17+
"main": "driver.js",
18+
"bin": "./driver.js",
19+
"devDependencies": { "pegjs": "*" }
20+
}

0 commit comments

Comments
 (0)