Skip to content

Commit e0fabeb

Browse files
sambachawrong7
andauthored
refactor(parser): add esm and umd output (#10)
Co-authored-by: Mario <wrong7@users.noreply.github.com>
1 parent 3a14b04 commit e0fabeb

33 files changed

+112959
-8328
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
21
name: nodejs
32

43
on:
54
push:
65
paths:
7-
- '**/**'
8-
- '!**/docs/**'
9-
6+
- '**/**'
7+
- '!**/docs/**'
108

119
env:
1210
CI: true

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
opt/
2+
.github/
3+
.git/
4+
test/
5+
test_files/
6+
docs/
7+
*.yml
8+
entrypoint.sh
9+
scripts/
10+

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["PeggyJS.peggy-language"]
3+
}

.vscode/settings.json

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

CHANGELOG.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,32 @@ pegis-solidity
2020
> [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with
2121
> additional project specific grammar rules
2222
23-
- Main change is adoption of `peggy` as the `peg.js` framework has been stagnant, this is a drop in replacement.
23+
- Main change is adoption of `peggy` as the `peg.js` framework has been
24+
stagnant, this is a drop in replacement.
25+
26+
## Latest Changelog
27+
28+
- Added support for `gwei` units.
29+
```solidity
30+
uint256 gas = 10 gwei;
31+
```
32+
- Fixed a bug that didn't recognize empty TryCatch statements with a return expresion.
33+
```solidity
34+
try Foo.bar() returns (uint result) {} catch {}
35+
```
36+
- Fixed a bug that didn't recognize Enum declarations
37+
```solidity
38+
enum Foo {
39+
bar
40+
}
41+
```
42+
43+
Thanks to [https://github.com/wrong7](https://github.com/wrong7)
2444
25-
#### TODO
26-
- Typescript support in next release via `ts-peggy`
27-
- Documentation update
2845
2946
## Reference for Changes
3047
31-
> v2 changes start here: 18 August 2021
48+
> v2 changes start here: 18 August 2021
3249
3350
- feat(refactor): migrate to peggy and various improvements
3451
[`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)

build-tracer.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
echo "Building Traeer"
3+
npx peggy --cache -o ./dist/parser.cjs ./src/solidity.pegjs --trace
4+
npx peggy -o ./dist/imports_parser.cjs ./src/imports.pegjs --tracee

build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
6+
check_mark="\033[1;32m✔\033[0m"
7+
header() { echo -e "\n\033[1m$1\033[0m"; }
8+
9+
# TODO - Boilerplate message
10+
header "Loading Nodejs/Browser Parser Buildtool\n"
11+
12+
npx peggy --cache -o ./dist/parser.cjs ./src/solidity.pegjs
13+
npx peggy -o ./dist/imports_parser.cjs ./src/imports.pegjs
14+
echo -e "\033[1A ${check_mark} Builing CommonJS Module... done"
15+
echo -e " \033[1mInitialize parser imports...\033[0m"
16+
sleep 1
17+
npx peggy -o ./dist/imports_parser.cjs ./src/imports.pegjs
18+
echo -e "\033[1A ${check_mark} Building PegJs Imports... done"
19+
20+
npx peggy --cache -o ./dist/parser.mjs ./src/solidity.pegjs --format es
21+
npx peggy -o ./dist/imports_parser.mjs ./src/imports.pegjs --format es
22+
echo -e "\033[1A ${check_mark} Builing ESM Module... done"
23+
echo -e " \033[1mInitialize parser imports...\033[0m"
24+
sleep 1
25+
26+
echo -e "\033[1A ${check_mark} Building ESM Imports... done"
27+
28+
npx peggy --cache -o ./dist/parser.umd.js ./src/solidity.pegjs --format umd
29+
npx peggy -o ./dist/imports_parser.umd.js ./src/imports.pegjs --format umd
30+
echo -e "\033[1A ${check_mark} Builing Browser UMD Module... done"
31+
echo -e " \033[1mInitialize parser imports...\033[0m"
32+
sleep 1
33+
npx peggy -o ./dist/imports_parser.cjs ./src/imports.pegjs
34+
echo -e "\033[1A ${check_mark} Building UMD Imports... done"
35+
36+
sleep 1
37+
header "\n\nSuccessfuly compiled Solidity Pegjs Parsers for NodeJS/Browsers\n"
38+
sleep 1
39+
echo -e ".. exiting successfully"
40+
41+
exit 0

cmd.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env node
22

3-
"use strict";
3+
'use strict';
44

5-
(function() {
5+
(function () {
66
var SolidityParser, echo, file, fs, i, len, ref, src;
77

88
fs = require('fs');
99

10-
SolidityParser = require("./index.js");
10+
SolidityParser = require('./index.js');
1111

12-
echo = function(msg) {
13-
return process.stdout.write(JSON.stringify(msg, null, 2) + '\n');
12+
echo = function (msg) {
13+
return process.stdout.write(`${JSON.stringify(msg, null, 2)}\n`);
1414
};
1515

1616
if (process.argv.length > 2) {
@@ -22,14 +22,13 @@
2222
echo(SolidityParser.parse(src));
2323
} catch (err) {
2424
process.stderr.write(
25-
err.name === 'SyntaxError'
26-
? "Location: " + JSON.stringify(err.location, null, 4) + "\n" + err
27-
: err.name + ': ' + err.message
25+
err.name === 'SyntaxError'
26+
? 'Location: ' + JSON.stringify(err.location, null, 4) + '\n' + err
27+
: err.name + ': ' + err.message,
2828
);
2929
}
3030
}
3131
} else {
32-
echo("Solidity Parser: file...");
32+
echo('Solidity Parser: file...');
3333
}
34-
35-
}).call(this);
34+
}.call(this));

0 commit comments

Comments
 (0)