fix: rename TrinoSqlParser to TrinoSql

This commit is contained in:
wewoor 2023-05-25 10:53:03 +08:00
parent 46a8a7ab12
commit 8084c7919a
12 changed files with 4251 additions and 4252 deletions

View File

@ -1,4 +1,4 @@
grammar TrinoSqlParser; grammar TrinoSql;
tokens { tokens {
DELIMITER DELIMITER

View File

@ -1,4 +1,4 @@
// Generated from /Users/zhenglin/Documents/parser/dt-sql-parser/src/grammar/trinosql/trinoSqlParser.g4 by ANTLR 4.12.0 // Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/trinosql/TrinoSql.g4 by ANTLR 4.12.0
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
import { import {
ATN, ATN,
@ -11,7 +11,7 @@ import {
PredictionContextCache, PredictionContextCache,
Token Token
} from "antlr4"; } from "antlr4";
export default class trinoSqlParserLexer extends Lexer { export default class TrinoSqlLexer extends Lexer {
public static readonly T__0 = 1; public static readonly T__0 = 1;
public static readonly T__1 = 2; public static readonly T__1 = 2;
public static readonly T__2 = 3; public static readonly T__2 = 3;
@ -569,20 +569,20 @@ export default class trinoSqlParserLexer extends Lexer {
constructor(input: CharStream) { constructor(input: CharStream) {
super(input); super(input);
this._interp = new LexerATNSimulator(this, trinoSqlParserLexer._ATN, trinoSqlParserLexer.DecisionsToDFA, new PredictionContextCache()); this._interp = new LexerATNSimulator(this, TrinoSqlLexer._ATN, TrinoSqlLexer.DecisionsToDFA, new PredictionContextCache());
} }
public get grammarFileName(): string { return "trinoSqlParser.g4"; } public get grammarFileName(): string { return "TrinoSql.g4"; }
public get literalNames(): (string | null)[] { return trinoSqlParserLexer.literalNames; } public get literalNames(): (string | null)[] { return TrinoSqlLexer.literalNames; }
public get symbolicNames(): (string | null)[] { return trinoSqlParserLexer.symbolicNames; } public get symbolicNames(): (string | null)[] { return TrinoSqlLexer.symbolicNames; }
public get ruleNames(): string[] { return trinoSqlParserLexer.ruleNames; } public get ruleNames(): string[] { return TrinoSqlLexer.ruleNames; }
public get serializedATN(): number[] { return trinoSqlParserLexer._serializedATN; } public get serializedATN(): number[] { return TrinoSqlLexer._serializedATN; }
public get channelNames(): string[] { return trinoSqlParserLexer.channelNames; } public get channelNames(): string[] { return TrinoSqlLexer.channelNames; }
public get modeNames(): string[] { return trinoSqlParserLexer.modeNames; } public get modeNames(): string[] { return TrinoSqlLexer.modeNames; }
public static readonly _serializedATN: number[] = [4,0,276,2467,6,-1,2, public static readonly _serializedATN: number[] = [4,0,276,2467,6,-1,2,
0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2, 0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,
@ -1424,13 +1424,13 @@ export default class trinoSqlParserLexer extends Lexer {
private static __ATN: ATN; private static __ATN: ATN;
public static get _ATN(): ATN { public static get _ATN(): ATN {
if (!trinoSqlParserLexer.__ATN) { if (!TrinoSqlLexer.__ATN) {
trinoSqlParserLexer.__ATN = new ATNDeserializer().deserialize(trinoSqlParserLexer._serializedATN); TrinoSqlLexer.__ATN = new ATNDeserializer().deserialize(TrinoSqlLexer._serializedATN);
} }
return trinoSqlParserLexer.__ATN; return TrinoSqlLexer.__ATN;
} }
static DecisionsToDFA = trinoSqlParserLexer._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) ); static DecisionsToDFA = TrinoSqlLexer._ATN.decisionToState.map( (ds: DecisionState, index: number) => new DFA(ds, index) );
} }

View File

@ -1,16 +1,16 @@
import { CharStream, CommonTokenStream, Lexer } from 'antlr4'; import { CharStream, CommonTokenStream, Lexer } from 'antlr4';
import trinoSqlLexer from '../lib/trinosql/trinoSqlParserLexer'; import TrinoSqlLexer from '../lib/trinosql/TrinoSqlLexer';
import trinoSqlParser from '../lib/trinosql/trinoSqlParserParser'; import TrinoSqlParser from '../lib/trinosql/TrinoSqlParser';
import BasicParser from './common/basicParser'; import BasicParser from './common/basicParser';
export default class trinoSQL extends BasicParser { export default class trinoSQL extends BasicParser {
public createLexer(input: string): trinoSqlLexer { public createLexer(input: string): TrinoSqlLexer {
const chars = new CharStream(input.toUpperCase()); // Some Lexer only support uppercase token, So you need transform const chars = new CharStream(input.toUpperCase()); // Some Lexer only support uppercase token, So you need transform
const lexer = new trinoSqlLexer(chars); const lexer = new TrinoSqlLexer(chars);
return lexer; return lexer;
} }
public createParserFromLexer(lexer: Lexer): trinoSqlParser { public createParserFromLexer(lexer: Lexer): TrinoSqlParser {
const tokens = new CommonTokenStream(lexer); const tokens = new CommonTokenStream(lexer);
const parser = new trinoSqlParser(tokens); const parser = new TrinoSqlParser(tokens);
return parser; return parser;
} }
} }

View File

@ -1,6 +1,5 @@
import trinoSQL from '../../../src/parser/trinosql'; import trinoSQL from '../../../src/parser/trinosql';
import trinoSqlParserListener from '../../../src/lib/trinosql/trinoSqlParserListener'; import TrinoSqlParserListener from '../../../src/lib/trinosql/TrinoSqlListener';
import { TableExpressionContext } from '../../../src/lib/trinosql/trinoSqlParser';
describe('trino SQL Listener Tests', () => { describe('trino SQL Listener Tests', () => {
const expectTableName = 'user1'; const expectTableName = 'user1';
@ -11,15 +10,15 @@ describe('trino SQL Listener Tests', () => {
test('Listener enterTableName', async () => { test('Listener enterTableName', async () => {
let result = ''; let result = '';
class MyListener extends trinoSqlParserListener { class MyListener extends TrinoSqlParserListener {
constructor() { constructor() {
super() super()
} }
enterTableExpression = (ctx: TableExpressionContext): void => { enterTableName = (ctx): void => {
result = ctx.getText().toLowerCase(); result = ctx.getText().toLowerCase();
} };
} }
const listenTableName = new MyListener(); const listenTableName = new MyListener();

View File

@ -1,5 +1,5 @@
import trinoSQL from '../../../src/parser/trinosql'; import trinoSQL from '../../../src/parser/trinosql';
import trinoSqlParserVisitor from '../../../src/lib/trinosql/trinoSqlParserVisitor'; import TrinoSqlParserVisitor from '../../../src/lib/trinosql/TrinoSqlVisitor';
describe('trino SQL Visitor Tests', () => { describe('trino SQL Visitor Tests', () => {
const expectTableName = 'user1'; const expectTableName = 'user1';
@ -12,8 +12,8 @@ describe('trino SQL Visitor Tests', () => {
test('Visitor visitTableName', () => { test('Visitor visitTableName', () => {
let result = ''; let result = '';
class MyVisitor extends trinoSqlParserVisitor<any>{ class MyVisitor extends TrinoSqlParserVisitor<any>{
visitTableExpression = (ctx): void => { visitTableName = (ctx): void => {
result = ctx.getText().toLowerCase(); result = ctx.getText().toLowerCase();
} }
} }