lava-oushudb-dt-sql-parser/src/parser/generic.ts

18 lines
695 B
TypeScript
Raw Normal View History

import { CharStreams, CommonTokenStream } from 'antlr4ts';
import { SqlLexer } from '../lib/generic/SqlLexer';
import { SqlParser } from '../lib/generic/SqlParser';
import BasicParser from './common/basicParser';
export default class GenericSQL extends BasicParser {
2023-05-04 10:13:05 +08:00
public createLexer(input: string): SqlLexer {
const chars = CharStreams.fromString(input.toUpperCase()); // Some Lexer only support uppercase token, So you need transform
2023-05-04 10:13:05 +08:00
const lexer = new SqlLexer(chars);
return lexer;
}
public createParserFromLexer(lexer: SqlLexer): SqlParser {
const tokenStream = new CommonTokenStream(lexer);
return new SqlParser(tokenStream);
}
}