lava-oushudb-dt-sql-parser/build/antlr4.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-08-28 13:29:47 +08:00
const path = require('path');
const exec = require('child_process').exec;
2023-05-04 10:13:05 +08:00
const argv = require('yargs-parser')(process.argv.slice(2))
2020-08-28 13:29:47 +08:00
2023-05-04 10:13:05 +08:00
const antlr4 = path.resolve(__dirname, './antlr-4.12.0-complete.jar');
2020-08-28 13:29:47 +08:00
const grammars = path.resolve(__dirname, '../src/grammar');
const output = path.resolve(__dirname, '../src/lib');
2020-08-28 13:29:47 +08:00
2020-09-09 14:11:04 +08:00
const entry = [
2020-12-14 11:09:57 +08:00
'generic',
'hive',
2022-12-15 18:19:46 +08:00
'pgsql',
2020-12-14 11:09:57 +08:00
'plsql',
'spark',
2020-10-22 19:57:13 +08:00
'flinksql',
feat: support trino(presto) sql language (#105) * feat(trino): intergrate prestoGrammar to dt-sql-parser * feat(trino): add trinoSQl test framework * feat(trino): intergrate test files for trinoSQL * test(trino): support alterStatement test * test(trino): support alter table set authorization statement * feat(trino): complete trinosql alter unit tests * test(trino): complete dropStatement unit cases for trinosql * test(trino): complete create statement unit cases for trinoSQL * test(trino): complete insertStatement unit cases for trinoSQl * test(trino): dropStatement test files changed to short line split * test(trino): complete selectStatement unit cases and grammar check * test(trino): complete commentStatement unit case for trinoSQL * test(trino): complete analyze commit and call clause unit case * test(trino): complete delete deny and describe statement unit case * test(trino): complete explain execute and grant statement unit case * feat(trino): improve GRANT Role grammar * test(trino): complete show statement unit case * test(trino): complete truncateTable startTransaction update and values statement unit case * test(trino): improve update statement test cases * test(trino): complete revoke revoke roles and rollback statement unit case * test(trino): add set statement test case * feat: generator new trino parser and lexer file * feat(trino): improve alter statement grammar * test(trino): complete alter statement unit cases * feat(trino): support case-insensitive lexers * fix(trino): rm unless gen files * test(trino): complete merge and reset session statement unit cases * test(trino): complete merge anduse statement unit cases * test(trino): complete prepare and refresh materialized view statement unit cases * test(trino): improve statement unit cases * test(trino): complete match recognize statement unit cases * test(trino): complete window with row pattern recognition statement unit cases
2023-05-24 15:07:02 +08:00
'trinosql',
2020-08-28 13:29:47 +08:00
];
2023-05-04 10:13:05 +08:00
function compile(language) {
2020-09-09 14:11:04 +08:00
const cmd = `
antlr4ts
2020-09-09 14:11:04 +08:00
-visitor
-listener
-Xexact-output-dir -o ${output}/${language}
2020-09-09 14:11:04 +08:00
${grammars}/${language}/*.g4
`.replace(/\n/g, '');
2023-05-04 10:13:05 +08:00
console.info('Executing:', cmd);
2020-09-09 14:11:04 +08:00
exec(cmd, (err) => {
if (err) {
console.error('Antlr4 build error: ' + language, err);
} else {
console.log(`Build ${language} success.`);
}
});
2023-05-04 10:13:05 +08:00
}
if (argv.all) { // build all: yarn antlr4 --all
entry.forEach((language) => {
compile(language);
});
} else if (argv.lang) {// build single: yarn antlr4 --lang=generic
const supportedLanguage = entry.find((language) => language === argv.lang);
if (supportedLanguage) {
compile(argv.lang);
} else {
console.error('Invalid language: ' + argv.lang + ', supported languages:\n' + entry.join(', '));
2023-05-04 10:13:05 +08:00
}
} else {
console.error('Please to specify the language, just like: yarn antlr4 --lang flinksql');
}
2020-08-28 13:29:47 +08:00