Skip to content

Commit

Permalink
fix: support oracle string
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Jun 17, 2024
1 parent 367c746 commit 9165c2e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"scripts": {
"preinstall": "npx only-allow pnpm",
"build": "pnpm --filter './packages/**' build"
"build": "pnpm --filter './packages/**' build",
"publish": "pnpm --filter './packages/**' publish"
}
}
2 changes: 1 addition & 1 deletion packages/monaco-plugin-ob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanbase-odc/monaco-plugin-ob",
"version": "1.2.3",
"version": "1.2.4",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ob-parser-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanbase-odc/ob-parser-js",
"version": "3.0.3",
"version": "3.0.4",
"description": "OB 前端解析工具库",
"main": "./lib/index.js",
"module": "./esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/ob-parser-js/src/formatter/core/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class Tokenizer {
"\"\"": "((\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*(\"|$))+)",
"''": "(('[^'\\\\]*(?:\\\\.[^'\\\\]*)*('|$))+)",
"N''": "((N'[^N'\\\\]*(?:\\\\.[^N'\\\\]*)*('|$))+)",
"'\\'": "(('[^''']*(?:[^''']*)*('|$))+)",
};

return stringTypes.map(t => patterns[t]).join("|");
Expand Down
3 changes: 2 additions & 1 deletion packages/ob-parser-js/src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default {
return new N1qlFormatter(cfg).format(query);
case "pl/sql":
return new PlSqlFormatter(cfg).format(query);
case "ob":
case "ob-mysql":
case 'ob-oracle':
return new OBFormatter(cfg).format(query);
case "sql":
case undefined:
Expand Down
50 changes: 37 additions & 13 deletions packages/ob-parser-js/src/formatter/languages/OBFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,44 @@ export default class OBFormatter {
* @return {String} formatted string
*/
format(query) {
const language = this.cfg.language;
let params;
switch (language) {
case 'ob-mysql': {
params = {
reservedWords,
reservedToplevelWords,
reservedNewlineWords,
relineFunctionPrefix,
stringTypes: [`""`, "''", "``", "[]"],
openParens: ["("],
closeParens: [")"],
indexedPlaceholderTypes: ["?"],
namedPlaceholderTypes: [":"],
lineCommentTypes: ["--"],
specialWordChars: ["$", "#", "@", "\\u4e00-\\u9fff"]
};
break;
}
case 'ob-oracle': {
params = {
reservedWords,
reservedToplevelWords,
reservedNewlineWords,
relineFunctionPrefix,
stringTypes: [`""`, "'\\'"],
openParens: ["("],
closeParens: [")"],
indexedPlaceholderTypes: ["?"],
namedPlaceholderTypes: [":"],
lineCommentTypes: ["--"],
specialWordChars: ["$", "#", "@", "\\u4e00-\\u9fff"]
};
break;
}
}
if (!tokenizer) {
tokenizer = new Tokenizer({
reservedWords,
reservedToplevelWords,
reservedNewlineWords,
relineFunctionPrefix,
stringTypes: [`""`, "''", "``", "[]"],
openParens: ["("],
closeParens: [")"],
indexedPlaceholderTypes: ["?"],
namedPlaceholderTypes: [":"],
lineCommentTypes: ["--"],
specialWordChars: ["$", "#", "@", "\\u4e00-\\u9fff"]
});
tokenizer = new Tokenizer(params);
}
return new Formatter(this.cfg, tokenizer).format(query);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ob-parser-js/src/parser/format/simpleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ const reservedNewlineWords = [
];

export default function (input: string, isMySQL: boolean = false) {
return Formatter.format(input, { language: 'ob' })
return Formatter.format(input, { language: isMySQL ? 'ob-mysql' : 'ob-oracle' })
}

0 comments on commit 9165c2e

Please sign in to comment.