https://github.com/mcchatman8009/antlr4-helper
A NPM library that assists in various Antlr4 parse, language analysis, and language manipulation tasks
https://github.com/mcchatman8009/antlr4-helper
antlr antlr-helper antlr4 antlr4-helper dsl es5 es6 helper language language-manipulation manipulation typescript
Last synced: 4 months ago
JSON representation
A NPM library that assists in various Antlr4 parse, language analysis, and language manipulation tasks
- Host: GitHub
- URL: https://github.com/mcchatman8009/antlr4-helper
- Owner: mcchatman8009
- License: other
- Created: 2018-08-01T19:08:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T10:59:31.000Z (about 7 years ago)
- Last Synced: 2025-05-22T13:28:27.923Z (5 months ago)
- Topics: antlr, antlr-helper, antlr4, antlr4-helper, dsl, es5, es6, helper, language, language-manipulation, manipulation, typescript
- Language: TypeScript
- Homepage:
- Size: 263 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Antlr4 Helper
## Overview
The goal of this project is to provided classes and interfaces that
assist with the interaction of Antlr parsers. Making things like
language manipulation and analysis much easier.## Getting Started
```bash
npm install -S antlr4-helper
```## Antlr4 Helper Documentation
[Documentation (Click Here)](./docs/README.md)
## JavaScript Examples
### Parsing Text
```javascript
const antlrHelper = require('antlr4-helper');
const TinycLexer = require('./parser/TinycLexer').TinycLexer;
const TinycParser = require('./parser/TinycParser').TinycParser;const factory = antlrHelper.createFactoryBuilder()
.lexer((input) => new TinycLexer(input))
.parser(tokenStream => new TinycParser(tokenStream))
.rootRule((parser) => parser.program())
.build();const parser = antlrHelper.createParser(factory);
parser.parse('variable = 100;');
parser.checkForErrors();//
// Find only variables
//
parser.filter((rule) => rule.getName() === 'id')
.forEach((rule) => {
const ruleName = rule.getName();
console.log(ruleName); // id
console.log(rule.getText()); // variable
});
```### Changing Parsed Text
```javascript
const antlrHelper = require('antlr4-helper');
const TinycLexer = require('./parser/TinycLexer').TinycLexer;
const TinycParser = require('./parser/TinycParser').TinycParser;const factory = antlrHelper.createFactoryBuilder()
.lexer((input) => new TinycLexer(input))
.parser(tokenStream => new TinycParser(tokenStream))
.rootRule((parser) => parser.program())
.build();const parser = antlrHelper.createParser(factory);
parser.parse('a = 10;');
parser.checkForErrors(); // No parse errors//
// Find the first rule
//
const rule = parser.findRuleByName('id');rule.setText('var');
console.log("The changed text:");
console.log(parser.getText()); //var = 10;console.log("The replaced variable:");
const varName = rule.getText();
console.log(varName); //var;
```