feat: migrate to antlr4ng (#267)

* feat: replace antlr4ts with antlr4ng

* feat: switch caseInsensitive option on

* feat: recompile all g4 file

* feat:  update parser to fit antlr4ng

* test: update test to fit antlr4ng
This commit is contained in:
Hayden
2024-02-26 20:25:09 +08:00
committed by GitHub
parent 5ce89cb421
commit 195878da9b
112 changed files with 648433 additions and 659067 deletions

View File

@ -21,9 +21,9 @@ describe('PgSQL ErrorStrategy test', () => {
// const statementCount = splitListener.statementsContext.length;
// splitListener.statementsContext.map((item, index) => {
// if(index !== statementCount-1 && index !== statementCount - 2) {
// expect(item.exception).not.toBe(undefined);
// expect(item.exception).not.toBe(null);
// } else {
// expect(item.exception).toBe(undefined);
// expect(item.exception).toBe(null);
// }
// })
// });
@ -38,9 +38,9 @@ describe('PgSQL ErrorStrategy test', () => {
const statementCount = splitListener.statementsContext.length;
splitListener.statementsContext.map((item, index) => {
if (index !== statementCount - 1 && index !== 0) {
expect(item.exception).not.toBe(undefined);
expect(item.exception).not.toBe(null);
} else {
expect(item.exception).toBe(undefined);
expect(item.exception).toBe(null);
}
});
});
@ -54,9 +54,9 @@ describe('PgSQL ErrorStrategy test', () => {
splitListener.statementsContext.map((item, index) => {
if (index !== 0 && index !== 1) {
expect(item.exception).not.toBe(undefined);
expect(item.exception).not.toBe(null);
} else {
expect(item.exception).toBe(undefined);
expect(item.exception).toBe(null);
}
});
});

View File

@ -1,6 +1,6 @@
import PostgresSQL from 'src/parser/pgsql';
import { PostgreSQLParserListener } from 'src/lib/pgsql/PostgreSQLParserListener';
import { ParseTreeListener } from 'antlr4ts/tree/ParseTreeListener';
import { ParseTreeListener } from 'antlr4ng';
describe('PostgresSQL Listener Tests', () => {
const expectTableName = 'user1';
@ -13,8 +13,12 @@ describe('PostgresSQL Listener Tests', () => {
let result = '';
class MyListener implements PostgreSQLParserListener {
enterTable_ref(ctx) {
result = ctx.text.toLowerCase();
result = ctx.getText().toLowerCase();
}
visitTerminal() {}
visitErrorNode() {}
enterEveryRule() {}
exitEveryRule() {}
}
const listenTableName = new MyListener();

View File

@ -1,5 +1,5 @@
import PostgresSQL from 'src/parser/pgsql';
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
import { AbstractParseTreeVisitor } from 'antlr4ng';
import { PostgreSQLParserVisitor } from 'src/lib/pgsql/PostgreSQLParserVisitor';
describe('MySQL Visitor Tests', () => {
@ -8,7 +8,7 @@ describe('MySQL Visitor Tests', () => {
const parser = new PostgresSQL();
const parseTree = parser.parse(sql, (error) => {
console.log('Parse error:', error);
console.error('Parse error:', error);
});
test('Visitor visitTableName', () => {
@ -22,7 +22,7 @@ describe('MySQL Visitor Tests', () => {
}
visitTable_ref(ctx) {
result = ctx.text.toLowerCase();
result = ctx.getText().toLowerCase();
}
}
const visitor: any = new MyVisitor();