Skip to content

Commit a8a552f

Browse files
committed
fix(npm): package
1 parent 5c92f66 commit a8a552f

File tree

6 files changed

+3558
-1
lines changed

6 files changed

+3558
-1
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"pegis",
4+
"pegjs"
5+
]
6+
}

cmd.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
5+
(function() {
6+
var SolidityParser, echo, file, fs, i, len, ref, src;
7+
8+
fs = require('fs');
9+
10+
SolidityParser = require("./index.js");
11+
12+
echo = function(msg) {
13+
return process.stdout.write(JSON.stringify(msg, null, 2) + '\n');
14+
};
15+
16+
if (process.argv.length > 2) {
17+
ref = process.argv.slice(2);
18+
for (i = 0, len = ref.length; i < len; i++) {
19+
file = ref[i];
20+
src = fs.readFileSync(file, 'utf8');
21+
try {
22+
echo(SolidityParser.parse(src));
23+
} catch (err) {
24+
process.stderr.write(
25+
err.name === 'SyntaxError'
26+
? "Location: " + JSON.stringify(err.location, null, 4) + "\n" + err
27+
: err.name + ': ' + err.message
28+
);
29+
}
30+
}
31+
} else {
32+
echo("Solidity Parser: file...");
33+
}
34+
35+
}).call(this);

explore.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var solExplore = require ('sol-explore'),
2+
solparse = require ('pegjs-solidity');
3+
4+
module.exports = {
5+
6+
version: require ('./package.json').version,
7+
8+
findImports: function (sourceCode) {
9+
10+
var importedFiles = [], AST;
11+
12+
try {
13+
AST = solparse.parse (sourceCode);
14+
} catch (e) {
15+
throw new Error (
16+
'An error occured while trying to parse the code:\n' + e
17+
);
18+
}
19+
20+
solExplore.traverse (AST, {
21+
22+
enter: function (node) {
23+
if (node.type === 'ImportStatement') {
24+
importedFiles.push (node.from);
25+
}
26+
}
27+
28+
});
29+
30+
return importedFiles;
31+
32+
}
33+
34+
};

0 commit comments

Comments
 (0)