solidity-parser
Advanced tools
Comparing version 0.0.6 to 0.0.7
20
index.js
@@ -7,18 +7,14 @@ var PEG = require("pegjs"); | ||
"solidity": require("./build/parser"), | ||
"solidity_imports": require("./build/imports_parser") | ||
"imports": require("./build/imports_parser") | ||
}; | ||
var parser = null; | ||
// TODO: Make all this async. | ||
module.exports = { | ||
buildParser: function(parser_name, rebuild) { | ||
if (parser == null) { | ||
if (rebuild == true) { | ||
var parserfile = fs.readFileSync(path.resolve("./" + parser_name + ".pegjs"), {encoding: "utf8"}); | ||
return PEG.buildParser(parserfile); | ||
} | ||
return builtSolidityParser; | ||
getParser: function(parser_name, rebuild) { | ||
if (rebuild == true) { | ||
var parserfile = fs.readFileSync(path.resolve("./" + parser_name + ".pegjs"), {encoding: "utf8"}); | ||
return PEG.buildParser(parserfile); | ||
} else { | ||
return builtParsers[parser_name]; | ||
} | ||
return parser; | ||
}, | ||
@@ -35,3 +31,3 @@ parse: function(source, parser_name, rebuild) { | ||
var parser = this.buildParser(parser_name, rebuild); | ||
var parser = this.getParser(parser_name, rebuild); | ||
@@ -38,0 +34,0 @@ var result; |
{ | ||
"name": "solidity-parser", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "PEG.js Solidity parser for Javascript", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "./node_modules/.bin/pegjs ./solidity.pegjs ./build/parser.js && ./node_modules/.bin/pegjs ./solidity_imports.pegjs ./build/imports_parser.js", | ||
"build": "./node_modules/.bin/pegjs ./solidity.pegjs ./build/parser.js && ./node_modules/.bin/pegjs ./imports.pegjs ./build/imports_parser.js", | ||
"test": "./node_modules/.bin/mocha --reporter spec" | ||
@@ -9,0 +9,0 @@ }, |
@@ -5,3 +5,3 @@ # Solidity Parser | ||
### ⚠️ WARNING ⚠️ | ||
### ⚠️ WARNING ⚠️ | ||
@@ -26,3 +26,3 @@ This is pre-alpha software. The goal of it is to take Solidity code as input and return an object as output that can be used to correctly describe that Solidity code. The structure of the resultant object is highly likely to change as the parser's features get filled out. **This parser is set to ignore Solidity constructs it's not yet able to handle.** Or, it might just error. So watch out. | ||
// Or, parse a file: | ||
// Or, parse a file: | ||
var result = SolidityParser.parseFile("./path/to/file.sol"); | ||
@@ -38,3 +38,3 @@ ``` | ||
// Or, parse a file: | ||
var result = SolidityParser.parse("./path/to/file.sol", "solidity_imports"); | ||
var result = SolidityParser.parse("./path/to/file.sol", "imports"); | ||
@@ -51,3 +51,3 @@ console.log(result); | ||
``` | ||
$ solidity-parser ./path/to/file.js | ||
$ solidity-parser ./path/to/file.js | ||
``` | ||
@@ -67,3 +67,3 @@ | ||
You'll receiving the following (or something very similar) as output. Note that the structure of mappings could be made more clear, and this will likely be changed in the future. | ||
You'll receiving the following (or something very similar) as output. Note that the structure of mappings could be made more clear, and this will likely be changed in the future. | ||
@@ -70,0 +70,0 @@ ```json |
@@ -11,3 +11,3 @@ var SolidityParser = require('../index.js'); | ||
it("parses documentation exmples using imports parser without throwing an error", function(done) { | ||
var result = SolidityParser.parseFile("./test/doc_examples.sol", "solidity_imports", true); | ||
var result = SolidityParser.parseFile("./test/doc_examples.sol", "imports", true); | ||
//console.log(JSON.stringify(result, null, 2)); | ||
@@ -17,1 +17,15 @@ done(); | ||
}); | ||
describe("Built Parser", function() { | ||
it("parses documentation examples without throwing an error", function(done) { | ||
var result = SolidityParser.parseFile("./test/doc_examples.sol", false); | ||
//console.log(JSON.stringify(result.body.filter(function(i) {return i.type == "ImportStatement"}), null, 2)); | ||
done(); | ||
}); | ||
it("parses documentation exmples using imports parser without throwing an error", function(done) { | ||
var result = SolidityParser.parseFile("./test/doc_examples.sol", "imports", false); | ||
//console.log(JSON.stringify(result, null, 2)); | ||
done(); | ||
}); | ||
}); |
717782
17897