lava-oushudb-dt-sql-parser/scripts/antlr4.js
霜序 e203f1a48a
feat: support impala (#184)
* feat(impala): add impala sqlLexer

* feat(impala): add impala grammar

* feat(impala): add alter table sql

* feat(impala): update alter table sql

* feat(impala): add alter db sql

* feat(impala): add alter view sql

* feat(impala): add compute stats/comment statement and update partition_desc for alter table

* feat(impala): add drop statement sql

* feat(impala): add revoke and grant sql

* feat(impala): add create db/function/role/view sql

* feat(impala): add describe/explain/invalidata_metadata/load_data sql

* feat(impala): add refresh/set/shutdown sql

* feat(impala): add truncate_table/use/values sql

* fix(impala): update shutdown and invaliddate_metadata

* feat(impala): add show/update/upsert sql

* feat(impala): add create/insert sql

* feat(impala): add select and delete sql

* feat(impala): add impala tokens and fix todo

* feat(impala): update impalaparser and some test unit

* feat(impala): add syntax suggestion

* feat(impala): add syntax suggestion

* feat(impala): update test unit

* feat(impala): remove reference

* fix(impala): add statement for sqlname and collect tableName

* fix(impala): fix syntax suggestion unit test

* fix(impala): update syntax suggestion and collect column

* feat(impala): add collect column create
2023-11-28 21:11:07 +08:00

84 lines
2.5 KiB
JavaScript

const path = require('path');
const exec = require('child_process').exec;
const fs = require('fs');
const argv = require('yargs-parser')(process.argv.slice(2));
const inquirer = require('inquirer');
const chalk = require('chalk');
const grammarsPath = path.resolve(__dirname, '../src/grammar');
const outputPath = path.resolve(__dirname, '../src/lib');
const languageEntries = fs.readdirSync(grammarsPath);
const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';
function compile(language) {
const cmd = `${baseCmd} ${outputPath}/${language} ${grammarsPath}/${language}/*.g4`;
if (fs.existsSync(`${outputPath}/${language}`)) {
console.info(chalk.green(`\nRemoving:`, chalk.gray(`${outputPath}/${language}/*`)));
fs.rmSync(`${outputPath}/${language}`, { recursive: true });
}
console.info(chalk.green('Executing:'), chalk.gray(cmd));
exec(cmd, (err) => {
if (err) {
console.error(
chalk.redBright(`\n[Antlr4 compile error]:`),
chalk.cyan(language),
chalk.gray(err)
);
} else {
console.log(chalk.greenBright(`\nCompile ${language} succeeded!`));
}
});
}
function prompt() {
inquirer
.prompt([
{
type: 'list',
name: 'language',
message: 'Which language you want compile (or all languages)',
choices: ['All Languages', ...languageEntries],
loop: true,
},
])
.then((result) => {
const language = result.language;
if (language === 'All Languages') {
languageEntries.forEach((language) => {
compile(language);
});
} else {
compile(result.language);
}
});
}
function main() {
if (argv.all) {
// compile all: yarn antlr4 --all
languageEntries.forEach((language) => {
compile(language);
});
} else if (argv.lang) {
// compile single: yarn antlr4 --lang=mysql
const supportedLanguage = languageEntries.some((language) => language === argv.lang);
if (supportedLanguage) {
compile(argv.lang);
} else {
console.error(
chalk.bold.red('\n[Invalid language]:'),
chalk.white.underline(`${argv.lang}\n`)
);
prompt();
}
} else {
prompt();
}
}
main();