{"id":26657053,"url":"https://github.com/mcchatman8009/antlr4-tool","last_synced_at":"2025-04-11T11:54:26.592Z","repository":{"id":48031628,"uuid":"140492132","full_name":"mcchatman8009/antlr4-tool","owner":"mcchatman8009","description":"A useful Antlr4 tool with full TypeScript support","archived":false,"fork":false,"pushed_at":"2021-08-10T19:22:48.000Z","size":5936,"stargazers_count":36,"open_issues_count":10,"forks_count":20,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T08:16:38.868Z","etag":null,"topics":["antlr-tool","antlr4","antlr4-grammar","antlr4-tool","antlr4-typescript","cli","command-line","es6","npm","parser","tool","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcchatman8009.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-10T22:09:25.000Z","updated_at":"2024-07-10T08:23:53.000Z","dependencies_parsed_at":"2022-08-12T17:10:23.129Z","dependency_job_id":null,"html_url":"https://github.com/mcchatman8009/antlr4-tool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcchatman8009%2Fantlr4-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcchatman8009%2Fantlr4-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcchatman8009%2Fantlr4-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcchatman8009%2Fantlr4-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcchatman8009","download_url":"https://codeload.github.com/mcchatman8009/antlr4-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248391290,"owners_count":21095987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antlr-tool","antlr4","antlr4-grammar","antlr4-tool","antlr4-typescript","cli","command-line","es6","npm","parser","tool","typescript"],"created_at":"2025-03-25T08:16:43.991Z","updated_at":"2025-04-11T11:54:26.574Z","avatar_url":"https://github.com/mcchatman8009.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# antlr4-tool\n\n## Overview\nThe purpose and intent of this project was to create and generate Typescript declaration files\nfor the [Antlr4](https://www.npmjs.com/package/antlr4) JavaScript target. \nAllowing for generated Antlr Parsers and Lexers that have full **ES5** browser support. This tool also\nallows for pure JavaScript implementations, if needed.\n\n## Requirements\n* Java Runtime Environment 1.6+ (1.8+ recommended)\n\n\n## Getting Stated\n\n* Install *antlr4-tool*,  adding it to your package.json\n\n```bash\nnpm install --save-dev antlr4-tool\n```\n\n* Install the Antlr4 library\n\n```bash\nnpm install -S antlr4\n\n#\n# (TypeScript Only)\n#\nnpm install -S @types/antlr4\n```\n\n* Add a grammar to your project, e.g. path/to/Grammar.g4\n\n```json\n\"scripts\": {\n  \"generate-parser\": \"antlr4-tool -o parser path/to/Grammar.g4\"\n}\n```\n\n* Run the NPM script command\n```bash\nnpm run generate-parser\n```\n\n* Use your generated Parser\n\n**JavaScript**\n```javascript\n\nconst antlr4 = require('antlr4')\nconst InputStream = antlr4.InputStream;\nconst CommonTokenStream = antlr4.CommonTokenStream;\n\nconst GrammarParser = require('./parser/GrammarParser').GrammarParser;\nconst GrammarLexer = require('./parser/GrammarLexer').GrammarLexer;\n\nconst inputStream = new InputStream('int x = 10;');\nconst lexer = new GrammarLexer(inputStream);\nconst tokenStream = new CommonTokenStream(lexer);\nconst parser = new GrammarParser(tokenStream);\n\n// Parse the input, where `compilationUnit` is whatever entry point you defined\nconst tree = parser.compilationUnit();\nconsole.log(tree);\n```\n\n**TypeScript**\n```typescript\nimport {InputStream, CommonTokenStream} from 'antlr4';\nimport {GrammarParser} from './parser/GrammarParser';\nimport {GrammarLexer} from './parser/GrammarLexer';\n\nconst inputStream = new InputStream('enter you grammar here');\nconst lexer = new GrammarLexer(inputStream);\nconst tokenStream = new CommonTokenStream(lexer);\nconst parser = new GrammarParser(tokenStream);\n\n// Parse the input, where `compilationUnit` is whatever entry point you defined\nconst tree = parser.compilationUnit();\nconsole.log(tree);\n```\n\n### TypeScript Notes\nAdd to your **tsconfig.json**:\n```\n\"typeRoots\": [\"types\"],\n```\n\n\n## For Command-Line Use\n\n### Installation For Command-Line Use\n```bash\nnpm install -g antlr4-tool\n```\n\n```\nUsage: antlr4-tool [options] \u003cgrammars...\u003e\n\nOptions:\n\n  -V, --version                 output the version number\n  -o --output-dir [output_dir]  Output Directory (Default: Current Directory)\n  -l --language [language]      Antlr Language Target: ts, typescript, js, javascript (Default: typescript)\n  --listener                    Generate parse tree listener (Default)\n  --no-listener                 Don't generate parse tree listener\n  --visitor                     Generate parse tree visitor (Default)\n  --no-visitor                  Don't generate parse tree visitor\n  -h, --help                    output usage information\n\n```\n\n### Finding the Version\n```bash\nantlr4-tool -V\n```\n\n\n### Example Creating a C Parser for TypeScript\n```bash\nantlr4-tool -l ts -o c-parser samples/c/C.g4\n```\n\n### Example Creating a C Parser for JavaScript\n```bash\nantlr4-tool -l js -o c-parser samples/c/C.g4\n```\n\n\n![Example](./docs/c-parser.png)\n\n\n## Using antlr4-tool as a Library\n```javascript\nconst tool = require('antlr4-tool');\n\nconst opts = {\n   language: 'TypeScript', // Only support for JavaScript \u0026 TypeScript\n   grammarFiles:  ['samples/c/C.g4'],\n   outputDirectory: 'c-parser'\n};\n\nconst compiledResults = tool.compile(opts);\n\nconsole.log(compiledResults);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcchatman8009%2Fantlr4-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcchatman8009%2Fantlr4-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcchatman8009%2Fantlr4-tool/lists"}