Skip to content

Commit

Permalink
publish
Browse files Browse the repository at this point in the history
Signed-off-by: sam bacha <[email protected]>
  • Loading branch information
sambacha authored and sam bacha committed Aug 18, 2021
1 parent 3461abf commit 9342c2f
Show file tree
Hide file tree
Showing 11 changed files with 3,660 additions and 238 deletions.
7 changes: 2 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ module.exports = {
es2021: true,
node: true,
},
extends: [
'airbnb-base',
],
extends: ['airbnb-base'],
parserOptions: {
ecmaVersion: 12,
},
rules: {
},
rules: {},
};
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
node-version: ["10", "12", "14"]
node-version: ['10', '12', '14']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ codecov/
*.xhtml
peggy/
*.peg
.nyc*
lib/solidity-pegis.js
51 changes: 34 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
### Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.
All notable changes to this project will be documented in this file. Dates are
displayed in UTC.

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v2.0.4](https://github.com/sambacha/solidity-pegjs-parser/compare/v2.0.3...v2.0.4)

> 30 October 2020
- fix(npm): fix pathnames, again [`132d1b2`](https://github.com/sambacha/solidity-pegjs-parser/commit/132d1b2fa3c9951befced2c0989a42adc5402b8e)
- revert(solidity.pegjs): solidity.pegjs in rootdir [`fc28601`](https://github.com/sambacha/solidity-pegjs-parser/commit/fc28601af20dad7611c9ebafa39c6a2356de7d84)
- Update README.md [`4bf8cd1`](https://github.com/sambacha/solidity-pegjs-parser/commit/4bf8cd1acc273118f9657fcaa0a6e146d04a0793)
- fix(npm): fix pathnames, again
[`132d1b2`](https://github.com/sambacha/solidity-pegjs-parser/commit/132d1b2fa3c9951befced2c0989a42adc5402b8e)
- revert(solidity.pegjs): solidity.pegjs in rootdir
[`fc28601`](https://github.com/sambacha/solidity-pegjs-parser/commit/fc28601af20dad7611c9ebafa39c6a2356de7d84)
- Update README.md
[`4bf8cd1`](https://github.com/sambacha/solidity-pegjs-parser/commit/4bf8cd1acc273118f9657fcaa0a6e146d04a0793)

#### [v2.0.3](https://github.com/sambacha/solidity-pegjs-parser/compare/2.0.2...v2.0.3)

> 30 October 2020
- chore(npm): fix npm package details [`4e626f3`](https://github.com/sambacha/solidity-pegjs-parser/commit/4e626f395d68e54885fc13f4a1123b2cd14f3085)
- feat(release): v2.0.2 [`36fd9d5`](https://github.com/sambacha/solidity-pegjs-parser/commit/36fd9d563cdfa5e8580eff4c3938d051b3030aa8)
- fix(git): fix git merge [`cd6d2d2`](https://github.com/sambacha/solidity-pegjs-parser/commit/cd6d2d206f8009358e0b3f6bed7e0b443034a5cf)
- chore(npm): fix npm package details
[`4e626f3`](https://github.com/sambacha/solidity-pegjs-parser/commit/4e626f395d68e54885fc13f4a1123b2cd14f3085)
- feat(release): v2.0.2
[`36fd9d5`](https://github.com/sambacha/solidity-pegjs-parser/commit/36fd9d563cdfa5e8580eff4c3938d051b3030aa8)
- fix(git): fix git merge
[`cd6d2d2`](https://github.com/sambacha/solidity-pegjs-parser/commit/cd6d2d206f8009358e0b3f6bed7e0b443034a5cf)

#### [2.0.2](https://github.com/sambacha/solidity-pegjs-parser/compare/2.0.1...2.0.2)

> 30 October 2020
- Release 2.0.2 [`84fb0ab`](https://github.com/sambacha/solidity-pegjs-parser/commit/84fb0ab4335478aa9be1e9c88cbeaa329ec15fe7)
- Release 2.0.2
[`84fb0ab`](https://github.com/sambacha/solidity-pegjs-parser/commit/84fb0ab4335478aa9be1e9c88cbeaa329ec15fe7)

#### [2.0.1](https://github.com/sambacha/solidity-pegjs-parser/compare/2.0.0...2.0.1)

> 30 October 2020
- fix(npm): npm build directory [`2dad33b`](https://github.com/sambacha/solidity-pegjs-parser/commit/2dad33b73271627adddc74d74c03b19b46c1c588)
- fix(bug): fixes issue wit deps [`d807ba1`](https://github.com/sambacha/solidity-pegjs-parser/commit/d807ba1e7313cb7fc628130ab6abef1d474bae0a)
- test(mocah): fix mocah tests [`4671018`](https://github.com/sambacha/solidity-pegjs-parser/commit/46710187897d4f16f5dec94d76b019124669100f)
- fix(npm): npm build directory
[`2dad33b`](https://github.com/sambacha/solidity-pegjs-parser/commit/2dad33b73271627adddc74d74c03b19b46c1c588)
- fix(bug): fixes issue wit deps
[`d807ba1`](https://github.com/sambacha/solidity-pegjs-parser/commit/d807ba1e7313cb7fc628130ab6abef1d474bae0a)
- test(mocah): fix mocah tests
[`4671018`](https://github.com/sambacha/solidity-pegjs-parser/commit/46710187897d4f16f5dec94d76b019124669100f)

#### [2.0.0](https://github.com/sambacha/solidity-pegjs-parser/compare/v2.0.0...2.0.0)

Expand All @@ -42,14 +53,20 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 18 August 2021
- feat(refactor): migrate to peggy and various improvements [`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)
- build(refactor): improve build process [`0de7a77`](https://github.com/sambacha/solidity-pegjs-parser/commit/0de7a774bf2edd51b03a865e435b30a02feb5313)
- chore(repo): remove dead and legacy artifacts [`012fec1`](https://github.com/sambacha/solidity-pegjs-parser/commit/012fec1b5000017a6125c38580d76a3299f597cc)
- feat(refactor): migrate to peggy and various improvements
[`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)
- build(refactor): improve build process
[`0de7a77`](https://github.com/sambacha/solidity-pegjs-parser/commit/0de7a774bf2edd51b03a865e435b30a02feb5313)
- chore(repo): remove dead and legacy artifacts
[`012fec1`](https://github.com/sambacha/solidity-pegjs-parser/commit/012fec1b5000017a6125c38580d76a3299f597cc)

#### v1.0.1

> 31 October 2020
- feat(publish): inital github commit [`ef9fd61`](https://github.com/sambacha/solidity-pegjs-parser/commit/ef9fd618cc1d2975f24ab6f387036d869ae76b4d)
- fix(tests): fix tests for coverage [`bbfa7e4`](https://github.com/sambacha/solidity-pegjs-parser/commit/bbfa7e4658cb81ee66c18b0ad37ebc4df910e604)
- feat(v1.2.0): release v1.2.0 [`2e37081`](https://github.com/sambacha/solidity-pegjs-parser/commit/2e37081899cf04ff19cef05f2c58dfb117167836)
- feat(publish): inital github commit
[`ef9fd61`](https://github.com/sambacha/solidity-pegjs-parser/commit/ef9fd618cc1d2975f24ab6f387036d869ae76b4d)
- fix(tests): fix tests for coverage
[`bbfa7e4`](https://github.com/sambacha/solidity-pegjs-parser/commit/bbfa7e4658cb81ee66c18b0ad37ebc4df910e604)
- feat(v1.2.0): release v1.2.0
[`2e37081`](https://github.com/sambacha/solidity-pegjs-parser/commit/2e37081899cf04ff19cef05f2c58dfb117167836)
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Ideal for AST use-cases

pegis-solidity

> original [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with additional project specific grammar rules
> original
> [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with
> additional project specific grammar rules
### Usage

```js
import { solidityparser } from "pegis-solidity"
import { solidityparser } from 'pegis-solidity';
```

### command line
Expand Down Expand Up @@ -91,13 +93,13 @@ Generated output as AST output:
```

```js
var SolidityParser = require("pegis-solidity")
var SolidityParser = require('pegis-solidity');

// Parse Solidity code as a string:
var result = SolidityParser.parse("contract { ... }")
var result = SolidityParser.parse('contract { ... }');

// Or, parse a file:
var result = SolidityParser.parseFile("./path/to/file.sol")
var result = SolidityParser.parseFile('./path/to/file.sol');
```

## Updates to Grammar
Expand Down
27 changes: 12 additions & 15 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#!/usr/bin/env node
"use strict";
'use strict';

/* eslint no-console: 0 */
let argv = require("yargs").argv;
let SolidityParser = require("./index.js");

let argv = require('yargs').argv;
let SolidityParser = require('./index.js');

let result;

try {

if (argv.e) {
result = SolidityParser.parse(argv.e || argv.expression);
} else {
result = SolidityParser.parseFile(argv.f || argv.file || argv._[0]);
}
console.log(JSON.stringify(result, null, 2));

if (argv.e) {
result = SolidityParser.parse(argv.e || argv.expression);
} else {
result = SolidityParser.parseFile(argv.f || argv.file || argv._[0]);
}
console.log(JSON.stringify(result, null, 2));
} catch (e) {
console.error(e.message);
process.exit(1);
}
console.error(e.message);
process.exit(1);
}
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ codecov:
coverage:
precision: 2
round: down
range: "70...100"
range: '70...100'
125 changes: 68 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,87 @@
"use strict";
'use strict';

const PEG = require("peggy");
const fs = require("fs");
const path = require("path");
const PEG = require('peggy');
const fs = require('fs');
const path = require('path');

const builtParsers = {
"solidity": require("./build/parser"),
"imports": require("./build/imports_parser")
solidity: require('./build/parser'),
imports: require('./build/imports_parser'),
};


function parseComments(sourceCode) {
// for Line comment regexp, the "." doesn't cover line termination chars so we're good :)
const comments = [], commentParser = /(\/\*(\*(?!\/)|[^*])*\*\/)|(\/\/.*)/g;
let nextComment;
// for Line comment regexp, the "." doesn't cover line termination chars so we're good :)
const comments = [],
commentParser = /(\/\*(\*(?!\/)|[^*])*\*\/)|(\/\/.*)/g;
let nextComment;

// eslint-disable-next-line no-cond-assign
while (nextComment = commentParser.exec(sourceCode)) {
const text = nextComment[0], types = { "//": "Line", "/*": "Block" };
// eslint-disable-next-line no-cond-assign
while ((nextComment = commentParser.exec(sourceCode))) {
const text = nextComment[0],
types = { '//': 'Line', '/*': 'Block' };

comments.push({
text,
type: types[text.slice(0, 2)],
start: nextComment.index,
end: nextComment.index + text.length
});
}
comments.push({
text,
type: types[text.slice(0, 2)],
start: nextComment.index,
end: nextComment.index + text.length,
});
}

return comments;
return comments;
}


// TODO: Make all this async.
module.exports = {
getParser: function(parser_name, rebuild) {
if (rebuild == true) {
let parserfile = fs.readFileSync(path.resolve("./" + parser_name + ".pegjs"), {encoding: "utf8"});
return PEG.generate(parserfile);
} else {
return builtParsers[parser_name];
}
},
parse: function(source, options, parser_name, rebuild) {
if (typeof parser_name == "boolean") {
rebuild = parser_name;
parser_name = null;
}
getParser: function (parser_name, rebuild) {
if (rebuild == true) {
let parserfile = fs.readFileSync(
path.resolve('./' + parser_name + '.pegjs'),
{ encoding: 'utf8' },
);
return PEG.generate(parserfile);
} else {
return builtParsers[parser_name];
}
},
parse: function (source, options, parser_name, rebuild) {
if (typeof parser_name == 'boolean') {
rebuild = parser_name;
parser_name = null;
}

if (parser_name == null) {
parser_name = "solidity";
}
if (parser_name == null) {
parser_name = 'solidity';
}

let parser = this.getParser(parser_name, rebuild);
let result;
let parser = this.getParser(parser_name, rebuild);
let result;

try {
result = parser.parse(source);
} catch (e) {
if (e instanceof parser.SyntaxError) {
e.message += " Line: " + e.location.start.line + ", Column: " + e.location.start.column;
}
throw e;
}
try {
result = parser.parse(source);
} catch (e) {
if (e instanceof parser.SyntaxError) {
e.message +=
' Line: ' +
e.location.start.line +
', Column: ' +
e.location.start.column;
}
throw e;
}

if (typeof options === "object" && options.comment === true) {
result.comments = parseComments(source);
}
if (typeof options === 'object' && options.comment === true) {
result.comments = parseComments(source);
}

return result;
},
parseFile: function(file, parser_name, rebuild) {
return this.parse(fs.readFileSync(path.resolve(file), {encoding: "utf8"}), parser_name, rebuild);
},
parseComments
return result;
},
parseFile: function (file, parser_name, rebuild) {
return this.parse(
fs.readFileSync(path.resolve(file), { encoding: 'utf8' }),
parser_name,
rebuild,
);
},
parseComments,
};
Loading

0 comments on commit 9342c2f

Please sign in to comment.