thrift-parser-ts
Version:
A parser of Thrift , by Antlr4 and antlr4ts
37 lines (36 loc) • 1.56 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThriftData = exports.parse = exports.CommentChannel = exports.ThriftLexer = exports.ThriftParser = void 0;
const antlr4ts_1 = require("antlr4ts");
const antlr4ts_2 = require("antlr4ts");
const ThriftParser_1 = require("./ThriftParser");
Object.defineProperty(exports, "ThriftParser", { enumerable: true, get: function () { return ThriftParser_1.ThriftParser; } });
const ThriftLexer_1 = require("./ThriftLexer");
Object.defineProperty(exports, "ThriftLexer", { enumerable: true, get: function () { return ThriftLexer_1.ThriftLexer; } });
// define in Thrift.g4, comment type's token.channel
exports.CommentChannel = 2;
function parse(inputStream) {
const lexer = new ThriftLexer_1.ThriftLexer(inputStream);
const stream = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ThriftParser_1.ThriftParser(stream);
parser.errorHandler = new antlr4ts_2.BailErrorStrategy();
const ctx = new antlr4ts_1.ParserRuleContext();
parser.enterRule(ctx, 0, 0);
const document = parser.document();
return [lexer, stream, parser, document];
}
exports.parse = parse;
class ThriftData {
tokens;
document;
constructor(inputStream) {
const [, tokens, , document] = parse(inputStream);
this.tokens = tokens;
this.document = document;
}
static fromString(data) {
const inputStream = antlr4ts_1.CharStreams.fromString(data);
return new ThriftData(inputStream);
}
}
exports.ThriftData = ThriftData;
;