Registry / serialization / thrift-parser-typescript

thrift-parser-typescript

JSON →
library0.0.5jsnpmunverified

A TypeScript library for parsing Apache Thrift IDL files into an AST. Current stable version is 0.0.5, with irregular releases. It provides a complete ANTLR-based parser for .thrift files and exports the generated visitor, parser, lexer, and listener. This package is one of the few TypeScript-first Thrift parsers, ships its own type definitions, and is suitable for tooling like code generation or linting.

npm install thrift-parser-typescript
INSTALL
IMPORT
SIG · THRIFT-PARSER-TYPE
T
thrift-parser-typescript
serializationjavascriptv0.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ThriftLexer
import { ThriftLexer } from 'thrift-parser-typescript'
const ThriftLexer = require('thrift-parser-typescript').ThriftLexer
The package exports ANTLR-generated lexer; use named import for TypeScript/ESM.
ThriftParser
import { ThriftParser } from 'thrift-parser-typescript'
import ThriftParser from 'thrift-parser-typescript'
Default export is not available; only named exports.
ThriftVisitor
import { ThriftVisitor } from 'thrift-parser-typescript'
import { ThriftVisitor } from 'thrift-parser-typescript/dist/ThriftVisitor'
Direct import from dist/ is unnecessary; all exports are at package root.
ThriftListener
import { ThriftListener } from 'thrift-parser-typescript'
const ThriftListener = require('thrift-parser-typescript').ThriftListener
While require works in CJS, import is preferred for TypeScript and ESM.

Parses a Thrift IDL string into an AST and visits it using a custom visitor.

import { ThriftLexer, ThriftParser, ThriftVisitor } from 'thrift-parser-typescript'; const input = `struct User { 1: required string name; 2: optional i32 age; }`; const chars = new (require('antlr4ts').ANTLRInputStream)(input); const lexer = new ThriftLexer(chars); const tokens = new (require('antlr4ts').CommonTokenStream)(lexer); const parser = new ThriftParser(tokens); const tree = parser.document(); class MyVisitor extends ThriftVisitor<string> { visitStruct(ctx: any): string { return `struct ${ctx.name}`; } } const result = new MyVisitor().visit(tree); console.log(result);
Debug
Known issues
gotchaThe package requires antlr4ts as a peer dependency; not installing it leads to runtime errors.
fix
Install antlr4ts: npm install antlr4ts
affects: >=0.0.1
breakingIn v0.0.4, exports were reorganized; ThriftLexer and ThriftParser moved from subpaths to root.
fix
Update imports to use root package path.
affects: <0.0.4
gotchaThe package does not export a 'parse' convenience function; users must manually wire ANTLRInputStream, lexer, tokens, and parser.
fix
Write boilerplate to create the parser pipeline as shown in quickstart.
affects: >=0.0.1
deprecatedImporting from 'thrift-parser-typescript/dist/*' is deprecated but still works; prefer root imports.
fix
Use import { ... } from 'thrift-parser-typescript'.
affects: >=0.0.4
Errors
Common errors & fixes
Cannot find module 'antlr4ts'
Missing peer dependency antlr4ts.
fix
Run 'npm install antlr4ts' in your project.
TypeError: Class extends value undefined is not a constructor or null
Importing ThriftVisitor incorrectly or missing import.
fix
Use 'import { ThriftVisitor } from 'thrift-parser-typescript'.
Module not found: Can't resolve 'thrift-parser-typescript'
Package not installed or import path incorrect.
fix
Run 'npm install thrift-parser-typescript' and check import path.
Cannot read property 'document' of undefined
Parser not instantiated correctly (missing tokens or input).
fix
Ensure you create CommonTokenStream and pass to ThriftParser constructor.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
thrift-parser-typescript — npm install thrift-parser-typescript · libregistry