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('SparkSQL 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);
// }
// })
// });
@ -39,9 +39,9 @@ describe('SparkSQL 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);
// }
// })
// });
@ -55,9 +55,9 @@ describe('SparkSQL 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 SparkSQL from 'src/parser/spark';
import { SparkSqlParserListener } from 'src/lib/spark/SparkSqlParserListener';
import { ParseTreeListener } from 'antlr4ts/tree/ParseTreeListener';
import { ParseTreeListener } from 'antlr4ng';
describe('Spark SQL Listener Tests', () => {
const expectTableName = 'user1';
@ -13,8 +13,12 @@ describe('Spark SQL Listener Tests', () => {
let result = '';
class MyListener implements SparkSqlParserListener {
exitRelationPrimary = (ctx): void => {
result = ctx.text.toLowerCase();
result = ctx.getText().toLowerCase();
};
visitTerminal() {}
visitErrorNode() {}
enterEveryRule() {}
exitEveryRule() {}
}
const listenTableName = new MyListener();

View File

@ -1,6 +1,6 @@
import SparkSQL from 'src/parser/spark';
import { SparkSqlParserVisitor } from 'src/lib/spark/SparkSqlParserVisitor';
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
import { AbstractParseTreeVisitor } from 'antlr4ng';
describe('Spark SQL Visitor Tests', () => {
const expectTableName = 'user1';
@ -8,7 +8,7 @@ describe('Spark SQL Visitor Tests', () => {
const parser = new SparkSQL();
const parseTree = parser.parse(sql, (error) => {
console.log('Parse error:', error);
console.error('Parse error:', error);
});
test('Visitor visitRelationPrimary', () => {
@ -21,7 +21,7 @@ describe('Spark SQL Visitor Tests', () => {
return this.result;
}
visitRelationPrimary = (ctx): void => {
this.result = ctx.text.toLowerCase();
this.result = ctx.getText().toLowerCase();
};
}
const visitor = new MyVisitor();