Skip to content

Commit

Permalink
Fix load times (#3)
Browse files Browse the repository at this point in the history
* Move peggy js parser generation to build time

* Clean up project folder; Refine yarn scripts

* Add .gitattributes

* Remove generated peggy js parsers

* Add blank lines at end of files
  • Loading branch information
benmurphyy authored Apr 18, 2024
1 parent 6c82976 commit 940ab37
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 31 deletions.
3 changes: 3 additions & 0 deletions ctowasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ output
node_modules
test/temp
.parcel-cache
src/parser/peggyjs/preprocessor.js
src/parser/peggyjs/lexer.js
src/parser/peggyjs/parser.js
10 changes: 7 additions & 3 deletions ctowasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"parcel": "^2.10.1",
"peggy": "^4.0.2",
"prettier": "^3.0.2",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
Expand All @@ -45,7 +46,7 @@
"yargs": "^17.7.2"
},
"scripts": {
"build": "yarn clean-dist && parcel build --no-cache",
"build": "yarn clean-dist && yarn gen-parsers && parcel build --no-cache",
"lint": "eslint . --fix",
"prettify": "prettier . --write",
"compile": "yarn build && node cmd.js compile",
Expand All @@ -57,11 +58,14 @@
"test": "yarn build && NODE_OPTIONS=--experimental-vm-modules jest",
"unit-test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=unit_tests",
"check": "tsc --noEmit",
"clean-dist": "rimraf dist"
"clean-dist": "rimraf dist",
"gen-preprocessor": "peggy ./src/parser/peggyjs/preprocessor.pegjs --cache --allowed-start-rules program",
"gen-lexer": "peggy ./src/parser/peggyjs/lexer.pegjs --cache --allowed-start-rules program",
"gen-parser": "peggy ./src/parser/peggyjs/parser.pegjs --cache --allowed-start-rules program",
"gen-parsers": "yarn gen-preprocessor && yarn gen-lexer && yarn gen-parser"
},
"dependencies": {
"bignumber.js": "^9.1.2",
"peggy": "^3.0.2",
"wabt": "^1.0.32"
}
}
22 changes: 4 additions & 18 deletions ctowasm/src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import preprocessingGrammar from "bundle-text:./preprocessor.pegjs";
import lexerGrammar from "bundle-text:./lexer.pegjs";
import parsingGrammar from "bundle-text:./parser.pegjs";
import peggy from "peggy";
import ModuleRepository from "~src/modules";
import { CAstRoot } from "~src/parser/c-ast/core";
import {
ParserCompilationErrors,
generateCompilationWarningMessage,
} from "~src/errors";
import { Position } from "~src/parser/c-ast/misc";

const preprocessor = peggy.generate(preprocessingGrammar as string, {
allowedStartRules: ["program"],
cache: true,
});

const lexer = peggy.generate(lexerGrammar as string, {
allowedStartRules: ["program"],
cache: true,
});
import preprocessor from "~src/parser/peggyjs/preprocessor"
import lexer from "~src/parser/peggyjs/lexer"
import parser from "~src/parser/peggyjs/parser"
import { Position } from "~src/parser/c-ast/misc";

const parser = peggy.generate(parsingGrammar as string, {
allowedStartRules: ["program"],
cache: true,
});

export interface ParserOutput {
cAstRoot: CAstRoot;
Expand Down
1 change: 1 addition & 0 deletions ctowasm/src/parser/peggyjs/lexer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function parse(input: string): string;
File renamed without changes.
7 changes: 7 additions & 0 deletions ctowasm/src/parser/peggyjs/parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CAstRoot } from "~src/parser/c-ast/core";
import { Position } from "~src/parser/c-ast/misc";
export function parse(input: string): {
rootNode: CAstRoot;
compilationErrors: { message: string; position: Position }[];
warnings: { message: string; position: Position }[];
};
File renamed without changes.
2 changes: 2 additions & 0 deletions ctowasm/src/parser/peggyjs/preprocessor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Position } from "~src/parser/c-ast/misc";
export function parse(input: string): string;
File renamed without changes.
35 changes: 25 additions & 10 deletions ctowasm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,13 @@
"@parcel/utils" "2.10.1"
nullthrows "^1.1.1"

"@peggyjs/[email protected]":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@peggyjs/from-mem/-/from-mem-1.2.1.tgz#b83db5b439f1b02159fe47f5c9684bd1ee244edd"
integrity sha512-qh5zG8WKT36142/FqOYtpF0scRR3ZJ3H5XST1bJ/KV2FvyB5MvUB/tB9ZjihRe1iKjJD4PBOZczzwEx7hJtgMw==
dependencies:
semver "7.6.0"

"@pkgjs/parseargs@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
Expand Down Expand Up @@ -2883,10 +2890,10 @@ color-name@~1.1.4:
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

commander@^10.0.0:
version "10.0.1"
resolved "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==
commander@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-12.0.0.tgz#b929db6df8546080adfd004ab215ed48cf6f2592"
integrity sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==

commander@^7.0.0, commander@^7.2.0:
version "7.2.0"
Expand Down Expand Up @@ -4615,12 +4622,13 @@ path-type@^4.0.0:
resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

peggy@^3.0.2:
version "3.0.2"
resolved "https://registry.npmjs.org/peggy/-/peggy-3.0.2.tgz"
integrity sha512-n7chtCbEoGYRwZZ0i/O3t1cPr6o+d9Xx4Zwy2LYfzv0vjchMBU0tO+qYYyvZloBPcgRgzYvALzGWHe609JjEpg==
peggy@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/peggy/-/peggy-4.0.2.tgz#440b79ff8270668294d877addb3a30bb9e28bad5"
integrity sha512-j4cepPgB20V7honmTAI+7U022y/n/wVi7Rbbd2QrMl2nifFECpngvA6Zhrz/JdmZ5LIBoTdkgHcDzzaA6C4ABg==
dependencies:
commander "^10.0.0"
"@peggyjs/from-mem" "1.2.1"
commander "^12.0.0"
source-map-generator "0.8.0"

picocolors@^1.0.0:
Expand Down Expand Up @@ -4868,6 +4876,13 @@ safe-buffer@^5.0.1:
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==

[email protected]:
version "7.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
dependencies:
lru-cache "^6.0.0"

semver@^6.3.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz"
Expand Down Expand Up @@ -4921,7 +4936,7 @@ slash@^3.0.0:

[email protected]:
version "0.8.0"
resolved "https://registry.npmjs.org/source-map-generator/-/source-map-generator-0.8.0.tgz"
resolved "https://registry.yarnpkg.com/source-map-generator/-/source-map-generator-0.8.0.tgz#10d5ca0651e2c9302ea338739cbd4408849c5d00"
integrity sha512-psgxdGMwl5MZM9S3FWee4EgsEaIjahYV5AzGnwUvPhWeITz/j6rKpysQHlQ4USdxvINlb8lKfWGIXwfkrgtqkA==

[email protected]:
Expand Down

0 comments on commit 940ab37

Please sign in to comment.