Skip to content

Commit 9342c2f

Browse files
sambachasam bacha
authored and
sam bacha
committed
publish
Signed-off-by: sam bacha <sam@manifoldfinance.com>
1 parent 3461abf commit 9342c2f

File tree

11 files changed

+3660
-238
lines changed

11 files changed

+3660
-238
lines changed

.eslintrc.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ module.exports = {
55
es2021: true,
66
node: true,
77
},
8-
extends: [
9-
'airbnb-base',
10-
],
8+
extends: ['airbnb-base'],
119
parserOptions: {
1210
ecmaVersion: 12,
1311
},
14-
rules: {
15-
},
12+
rules: {},
1613
};

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
node-version: ["10", "12", "14"]
13+
node-version: ['10', '12', '14']
1414

1515
steps:
1616
- uses: actions/checkout@v2

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ codecov/
1313
*.xhtml
1414
peggy/
1515
*.peg
16+
.nyc*
17+
lib/solidity-pegis.js

CHANGELOG.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
### Changelog
22

3-
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
3+
All notable changes to this project will be documented in this file. Dates are
4+
displayed in UTC.
45

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

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

910
> 30 October 2020
1011
11-
- fix(npm): fix pathnames, again [`132d1b2`](https://github.com/sambacha/solidity-pegjs-parser/commit/132d1b2fa3c9951befced2c0989a42adc5402b8e)
12-
- revert(solidity.pegjs): solidity.pegjs in rootdir [`fc28601`](https://github.com/sambacha/solidity-pegjs-parser/commit/fc28601af20dad7611c9ebafa39c6a2356de7d84)
13-
- Update README.md [`4bf8cd1`](https://github.com/sambacha/solidity-pegjs-parser/commit/4bf8cd1acc273118f9657fcaa0a6e146d04a0793)
12+
- fix(npm): fix pathnames, again
13+
[`132d1b2`](https://github.com/sambacha/solidity-pegjs-parser/commit/132d1b2fa3c9951befced2c0989a42adc5402b8e)
14+
- revert(solidity.pegjs): solidity.pegjs in rootdir
15+
[`fc28601`](https://github.com/sambacha/solidity-pegjs-parser/commit/fc28601af20dad7611c9ebafa39c6a2356de7d84)
16+
- Update README.md
17+
[`4bf8cd1`](https://github.com/sambacha/solidity-pegjs-parser/commit/4bf8cd1acc273118f9657fcaa0a6e146d04a0793)
1418

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

1721
> 30 October 2020
1822
19-
- chore(npm): fix npm package details [`4e626f3`](https://github.com/sambacha/solidity-pegjs-parser/commit/4e626f395d68e54885fc13f4a1123b2cd14f3085)
20-
- feat(release): v2.0.2 [`36fd9d5`](https://github.com/sambacha/solidity-pegjs-parser/commit/36fd9d563cdfa5e8580eff4c3938d051b3030aa8)
21-
- fix(git): fix git merge [`cd6d2d2`](https://github.com/sambacha/solidity-pegjs-parser/commit/cd6d2d206f8009358e0b3f6bed7e0b443034a5cf)
23+
- chore(npm): fix npm package details
24+
[`4e626f3`](https://github.com/sambacha/solidity-pegjs-parser/commit/4e626f395d68e54885fc13f4a1123b2cd14f3085)
25+
- feat(release): v2.0.2
26+
[`36fd9d5`](https://github.com/sambacha/solidity-pegjs-parser/commit/36fd9d563cdfa5e8580eff4c3938d051b3030aa8)
27+
- fix(git): fix git merge
28+
[`cd6d2d2`](https://github.com/sambacha/solidity-pegjs-parser/commit/cd6d2d206f8009358e0b3f6bed7e0b443034a5cf)
2229

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

2532
> 30 October 2020
2633
27-
- Release 2.0.2 [`84fb0ab`](https://github.com/sambacha/solidity-pegjs-parser/commit/84fb0ab4335478aa9be1e9c88cbeaa329ec15fe7)
34+
- Release 2.0.2
35+
[`84fb0ab`](https://github.com/sambacha/solidity-pegjs-parser/commit/84fb0ab4335478aa9be1e9c88cbeaa329ec15fe7)
2836

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

3139
> 30 October 2020
3240
33-
- fix(npm): npm build directory [`2dad33b`](https://github.com/sambacha/solidity-pegjs-parser/commit/2dad33b73271627adddc74d74c03b19b46c1c588)
34-
- fix(bug): fixes issue wit deps [`d807ba1`](https://github.com/sambacha/solidity-pegjs-parser/commit/d807ba1e7313cb7fc628130ab6abef1d474bae0a)
35-
- test(mocah): fix mocah tests [`4671018`](https://github.com/sambacha/solidity-pegjs-parser/commit/46710187897d4f16f5dec94d76b019124669100f)
41+
- fix(npm): npm build directory
42+
[`2dad33b`](https://github.com/sambacha/solidity-pegjs-parser/commit/2dad33b73271627adddc74d74c03b19b46c1c588)
43+
- fix(bug): fixes issue wit deps
44+
[`d807ba1`](https://github.com/sambacha/solidity-pegjs-parser/commit/d807ba1e7313cb7fc628130ab6abef1d474bae0a)
45+
- test(mocah): fix mocah tests
46+
[`4671018`](https://github.com/sambacha/solidity-pegjs-parser/commit/46710187897d4f16f5dec94d76b019124669100f)
3647

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

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

4354
> 18 August 2021
4455
45-
- feat(refactor): migrate to peggy and various improvements [`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)
46-
- build(refactor): improve build process [`0de7a77`](https://github.com/sambacha/solidity-pegjs-parser/commit/0de7a774bf2edd51b03a865e435b30a02feb5313)
47-
- chore(repo): remove dead and legacy artifacts [`012fec1`](https://github.com/sambacha/solidity-pegjs-parser/commit/012fec1b5000017a6125c38580d76a3299f597cc)
56+
- feat(refactor): migrate to peggy and various improvements
57+
[`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)
58+
- build(refactor): improve build process
59+
[`0de7a77`](https://github.com/sambacha/solidity-pegjs-parser/commit/0de7a774bf2edd51b03a865e435b30a02feb5313)
60+
- chore(repo): remove dead and legacy artifacts
61+
[`012fec1`](https://github.com/sambacha/solidity-pegjs-parser/commit/012fec1b5000017a6125c38580d76a3299f597cc)
4862

4963
#### v1.0.1
5064

5165
> 31 October 2020
5266
53-
- feat(publish): inital github commit [`ef9fd61`](https://github.com/sambacha/solidity-pegjs-parser/commit/ef9fd618cc1d2975f24ab6f387036d869ae76b4d)
54-
- fix(tests): fix tests for coverage [`bbfa7e4`](https://github.com/sambacha/solidity-pegjs-parser/commit/bbfa7e4658cb81ee66c18b0ad37ebc4df910e604)
55-
- feat(v1.2.0): release v1.2.0 [`2e37081`](https://github.com/sambacha/solidity-pegjs-parser/commit/2e37081899cf04ff19cef05f2c58dfb117167836)
67+
- feat(publish): inital github commit
68+
[`ef9fd61`](https://github.com/sambacha/solidity-pegjs-parser/commit/ef9fd618cc1d2975f24ab6f387036d869ae76b4d)
69+
- fix(tests): fix tests for coverage
70+
[`bbfa7e4`](https://github.com/sambacha/solidity-pegjs-parser/commit/bbfa7e4658cb81ee66c18b0ad37ebc4df910e604)
71+
- feat(v1.2.0): release v1.2.0
72+
[`2e37081`](https://github.com/sambacha/solidity-pegjs-parser/commit/2e37081899cf04ff19cef05f2c58dfb117167836)

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ Ideal for AST use-cases
1616

1717
pegis-solidity
1818

19-
> original [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with additional project specific grammar rules
19+
> original
20+
> [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with
21+
> additional project specific grammar rules
2022
2123
### Usage
2224

2325
```js
24-
import { solidityparser } from "pegis-solidity"
26+
import { solidityparser } from 'pegis-solidity';
2527
```
2628

2729
### command line
@@ -91,13 +93,13 @@ Generated output as AST output:
9193
```
9294

9395
```js
94-
var SolidityParser = require("pegis-solidity")
96+
var SolidityParser = require('pegis-solidity');
9597

9698
// Parse Solidity code as a string:
97-
var result = SolidityParser.parse("contract { ... }")
99+
var result = SolidityParser.parse('contract { ... }');
98100

99101
// Or, parse a file:
100-
var result = SolidityParser.parseFile("./path/to/file.sol")
102+
var result = SolidityParser.parseFile('./path/to/file.sol');
101103
```
102104

103105
## Updates to Grammar

cli.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
#!/usr/bin/env node
2-
"use strict";
2+
'use strict';
33

44
/* eslint no-console: 0 */
5-
let argv = require("yargs").argv;
6-
let SolidityParser = require("./index.js");
7-
5+
let argv = require('yargs').argv;
6+
let SolidityParser = require('./index.js');
87

98
let result;
109

1110
try {
12-
13-
if (argv.e) {
14-
result = SolidityParser.parse(argv.e || argv.expression);
15-
} else {
16-
result = SolidityParser.parseFile(argv.f || argv.file || argv._[0]);
17-
}
18-
console.log(JSON.stringify(result, null, 2));
19-
11+
if (argv.e) {
12+
result = SolidityParser.parse(argv.e || argv.expression);
13+
} else {
14+
result = SolidityParser.parseFile(argv.f || argv.file || argv._[0]);
15+
}
16+
console.log(JSON.stringify(result, null, 2));
2017
} catch (e) {
21-
console.error(e.message);
22-
process.exit(1);
23-
}
18+
console.error(e.message);
19+
process.exit(1);
20+
}

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ codecov:
44
coverage:
55
precision: 2
66
round: down
7-
range: "70...100"
7+
range: '70...100'

index.js

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,87 @@
1-
"use strict";
1+
'use strict';
22

3-
const PEG = require("peggy");
4-
const fs = require("fs");
5-
const path = require("path");
3+
const PEG = require('peggy');
4+
const fs = require('fs');
5+
const path = require('path');
66

77
const builtParsers = {
8-
"solidity": require("./build/parser"),
9-
"imports": require("./build/imports_parser")
8+
solidity: require('./build/parser'),
9+
imports: require('./build/imports_parser'),
1010
};
1111

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

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

22-
comments.push({
23-
text,
24-
type: types[text.slice(0, 2)],
25-
start: nextComment.index,
26-
end: nextComment.index + text.length
27-
});
28-
}
23+
comments.push({
24+
text,
25+
type: types[text.slice(0, 2)],
26+
start: nextComment.index,
27+
end: nextComment.index + text.length,
28+
});
29+
}
2930

30-
return comments;
31+
return comments;
3132
}
3233

33-
3434
// TODO: Make all this async.
3535
module.exports = {
36-
getParser: function(parser_name, rebuild) {
37-
if (rebuild == true) {
38-
let parserfile = fs.readFileSync(path.resolve("./" + parser_name + ".pegjs"), {encoding: "utf8"});
39-
return PEG.generate(parserfile);
40-
} else {
41-
return builtParsers[parser_name];
42-
}
43-
},
44-
parse: function(source, options, parser_name, rebuild) {
45-
if (typeof parser_name == "boolean") {
46-
rebuild = parser_name;
47-
parser_name = null;
48-
}
36+
getParser: function (parser_name, rebuild) {
37+
if (rebuild == true) {
38+
let parserfile = fs.readFileSync(
39+
path.resolve('./' + parser_name + '.pegjs'),
40+
{ encoding: 'utf8' },
41+
);
42+
return PEG.generate(parserfile);
43+
} else {
44+
return builtParsers[parser_name];
45+
}
46+
},
47+
parse: function (source, options, parser_name, rebuild) {
48+
if (typeof parser_name == 'boolean') {
49+
rebuild = parser_name;
50+
parser_name = null;
51+
}
4952

50-
if (parser_name == null) {
51-
parser_name = "solidity";
52-
}
53+
if (parser_name == null) {
54+
parser_name = 'solidity';
55+
}
5356

54-
let parser = this.getParser(parser_name, rebuild);
55-
let result;
57+
let parser = this.getParser(parser_name, rebuild);
58+
let result;
5659

57-
try {
58-
result = parser.parse(source);
59-
} catch (e) {
60-
if (e instanceof parser.SyntaxError) {
61-
e.message += " Line: " + e.location.start.line + ", Column: " + e.location.start.column;
62-
}
63-
throw e;
64-
}
60+
try {
61+
result = parser.parse(source);
62+
} catch (e) {
63+
if (e instanceof parser.SyntaxError) {
64+
e.message +=
65+
' Line: ' +
66+
e.location.start.line +
67+
', Column: ' +
68+
e.location.start.column;
69+
}
70+
throw e;
71+
}
6572

66-
if (typeof options === "object" && options.comment === true) {
67-
result.comments = parseComments(source);
68-
}
73+
if (typeof options === 'object' && options.comment === true) {
74+
result.comments = parseComments(source);
75+
}
6976

70-
return result;
71-
},
72-
parseFile: function(file, parser_name, rebuild) {
73-
return this.parse(fs.readFileSync(path.resolve(file), {encoding: "utf8"}), parser_name, rebuild);
74-
},
75-
parseComments
77+
return result;
78+
},
79+
parseFile: function (file, parser_name, rebuild) {
80+
return this.parse(
81+
fs.readFileSync(path.resolve(file), { encoding: 'utf8' }),
82+
parser_name,
83+
rebuild,
84+
);
85+
},
86+
parseComments,
7687
};

0 commit comments

Comments
 (0)