Project Setup
May 30, 2026 ยท View on GitHub
Here you'll find some info for install/setup/directory structure.
Pre-requisites
nvm(Node Version Manager)java(Optional, needed to generate new code ANTLR, Java 22+)
Only if Windows:
Git Bash
๐ Main Techs
- TypeScript - Core language for the parser and API
- Node.js - Uses CommonJS (CJS) for compatibility (as opposed to ESM (ECMAScript Modules))
- ANTLR4 - Grammar-driven lexer and parser generation
- Grammar integration/implementation - Of the ANTLR4-generated lexer/parser in TypeScript
- Jest - Testing framework for all test suites
- CI/CD - GitHub Actions for continuous integration and automated releases
- Prettier / ESLint - Code formatting and linting tools
- cross-env - Environment variable management
Notes:
- The parser currently uses CommonJS (CJS module format) module format for maximum compatibility with Jest and Node.js.
In package.json, this line must be present:
"type": "commonjs"
This means any .js files (config files, etc) must use require() instead of import.
Project Overview
Brief overview of the directory structure in this project:
src/ โ Source code
tests/ โ Unit tests
docs/ โ Documentation files
dist/ โ Build output
package.json โ Node.js dependencies, scripts, etc.
See more in the section, "Project Structure".
Quick Start
To run the parser:
- In
Git BashorBash, go to the root of this project (where you have this project saved on your drive). - Make sure you are running the correct version of Node, it should match or be higher than the version in the file
.nvmrc.- You can check the current version of node by typing:
node -v
- You can check the current version of node by typing:
- In here type (to just run the parser quickly):
npm run start:main
- (Optionally) Runs all (Jest) tests.
npm test
Available npm scripts
Here's a short description of each script (in package.json) in this project.
npm run start:mainโ Runs the local development harness (src/dev/main.ts) directly usingts-node.npm run start:main:devโ Runs the local development harness with the development flag enabled.npm run start:main:dev:debugโ Runs the local development harness with development and debug flags enabled.npm testโ Runs all (Jest) tests.npm run test:smokeโ Runs only the smoke tests (located intests/smoke).npm run antlrโ Runs the ANTLR4 code generation.npm run tscโ (Trans)compiles all.tsfiles into.jsfiles. Normally not needed, since we usets-nodeto run.tsfiles directly. Use only in special cases (e.g. for debugging). Important: any lingering.jsfiles should be cleaned (usingnpm run clean:ts-js) before running again โ otherwise old.jsfiles may cause conflicts.npm run start-w-cleanโ Runs the TypeScript compiler, cleans old.jsfiles, and then starts the project. Useful for clean testing and running the parser.npm run lintโ Runs ESLint on all.tsfiles insrc/to check code style and catch possible errors.npm run clean:ts-jsโ Runsscripts/clean-ts-js.shto remove compiled.jsand.js.mapfiles. Helps keep the working directory clean, since we usets-nodeto run.tsfiles directly.prepublishOnlyโ This is a npm lifecycle script, it runs automatically ONLY when one runsnpm publishornpm pack. This ensures that every time when publishing, the code is linted, tested, and built, just before it goes to npm.
Running All Tests
To run all tests (smoke, unit, integration):
npm test
To Test the Grammar
- In
Git Bash,Bash(or possibly inCMDdepending on your setup). In the root, type:make tokens
Generating Source
Generating source code from grammar files with ANTLR4. Usually this is not needed, only if new or updated grammar files are used.
- Prefferably you can use option A or optionally with option B:
- A. In console:
npm run antlr - B. In
Git Bash,Bash(or possibly inCMDdepending on your setup). In the root, type:make generate
- A. In console:
Project Structure
Here's an overview of the project's directory structure โ to help users understand where things are and how the project is organized.
/
โโโ grammar/ // ANTLR4 grammar source files (.g4)
โ โโโ v1.x.x-beta/ // Versioned grammar snapshots (archived)
โ โโโ ...
|
โโโ src/ // Main source code
โ โโโ config/ // Environment/config-specific code
โ โโโ core/ // All the main building blocks (visitor, builder, internal types, error handling, etc)
โ โโโ grammar/ // ANTLR-generated artifacts: parser/lexer/visitor (.ts)
โ โโโ parsers/ // All code that parses or extracts specific things (header parts, numbers, booleans, etc)
โ โโโ utils/ // All general helpers/utility functions
โ โโโ types/index.ts // Public (user-facing) types goes here
โ โโโ index.ts // Main entry point of this library/package
|
โโโ tests/ // Test code
โ โโโ smoke/ // Smoke tests
โ โโโ unit/ // Unit tests
| โโโ integration/ // Integration tests
โ โโโ golden/ // Golden tests (input/output pairs)
โ โโโ fixed-issues/ // Tests for reported issues.
โ โโโ fixtures/ // ALL test data (**in one place**)
โ โโโ valid/ // Fixture valid data (mostly for integration tests)
โ โโโ invalid/ // Fixture invalid data (mostly for integration tests)
โ โโโ smoke-fixtures/ // More dedicated fixtures for smoke tests
|
โโโ scripts/ // Utility scripts (e.g. clean-ts-js.sh)
โโโ docs/ // Project documentation
โโโ libs/ // Vendored libraries (e.g. antlr4)
โ โโโ antlr4/
โโโ dist/ // Compiled JS artifacts (output local directory)
โโโ .github/ // GitHub workflows (CI/CD)
โ โโโ workflows/
โโโ .husky/ // Git hooks (managed by husky)
โโโ .vscode/ // VSCode project settings (optional)
โโโ Makefile // Build automation (ANTLR4 code generation, etc.)
โโโ package.json // Node.js dependencies, scripts, etc.
โโโ tsconfig.json // Config for TypeScript
โโโ jest.config.js // Config for Jest testing
โโโ .gitignore // Git exclusions
โโโ README.md // Project overview and documentation
Environment Variables
Since this is a library (as opposed to a Web/App), we don't (need) care about a special "development" and "staging" app environments / branches. So there's no "deploy" per environment.
Note:
- There is no
.env.development,.env.stagingetc. - the package scripts sets NODE_ENV as needed, and the code handles the rest. - However, there are test and CI environments, but these are for running tests and builds, not for staging deploys.
NODE_ENV
Defacto Node.js modes (environments). Note: NODE_ENV is global.
| Value | Meaning |
|---|---|
development | Global development mode โ enables debugging and detailed logging. |
production | Global production mode โ enables optimizations, disables debug output. |
test | Global Test mode โ used when running automated tests. |
APP_ENV
More custom envs (more finer-grained control than what only NODE_ENV allows) for this project. Note: APP_ENV is global.
| Value | Meaning |
|---|---|
local | Local development and testing, shows more debug info, etc. |
ci | Running in Continuous Integration pipelines. |
staging | |
production | Deployed in live production environment. |
DEV and DEBUG Flags
During development some flags can be set, these are set and passed as arguments when starting processes.
Note: These flags are local.
| Cmd argument | Function | Meaning |
|---|---|---|
isDev=1 | isDev() | Local development and testing, shows more info, etc. |
isDebug=1 | isDebug() | Local debugging and testing, shows more detailed info, etc. |
Start with Different Environments and Flags
Under development, different environments and flags can be used by starting different scripts in package.json.
Note: This library should never set or modify values in process.env, only read from it. Changing it in the library will cause side effect in users application and other dependencies.
npm run start:debugnpm run start:mainnpm run start:main:devnpm run start:main:dev:debug
Packages
Some of the package used.
ts-node
Used to run .ts files directly, should only be used under "development".
In production, the trans-compiled .js file should be run normally with node.
Normally with Node.js:
tsc # compiles TypeScript to JavaScript
node dist/index.js # runs the compiled JS
With ts-node:
ts-node src/dev/main.ts # runs the local development harness directly
^YINI โก
A simple, structured, and human-friendly configuration format.