Skip to content

Commit 2f06e6d

Browse files
committed
fixed tokenizer for placeholder
1 parent 9329094 commit 2f06e6d

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sqlparser-devexpress",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"main": "src/index.js",
55
"type": "module",
66
"scripts": {

src/core/tokenizer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tokenPatterns = {
66
function: "\\b(ISNULL)\\b", // Matches function names like ISNULL (case-insensitive)
77
null: "\\bNULL\\b|\\(\\s*NULL\\s*\\)", // Matches NULL as a keyword
88
number: "\\(\\d+\\)|\\d+", // Matches numbers while stripping unnecessary parentheses
9-
placeholder: "'?\\{[^}]+\\}'?", // Matches placeholders like {variable} or '{variable}'
9+
placeholder: "\\('?\\{[^}]+\\}'?\\)|'?\\{[^}]+\\}'?", // Matches placeholders like {variable} or '{variable}' or ({variable}) or ('{variable}')
1010
string: "\\('\\w+\\'\\)|'(?:''|[^'])*'", // Matches strings, allowing for escaped single quotes ('')
1111
operator: "=>|<=|!=|>=|=|<>|>|<|\\bAND\\b|\\bOR\\b|\\bBETWEEN\\b|\\bIN\\b|\\bNOT IN\\b|\\bLIKE\\b|\\bIS NOT\\b|\\bNOT LIKE\\b|\\bIS\\b", // Matches SQL operators and logical keywords
1212
identifier: "[\\w.]+|\"[^\"]+\"|\\[[^\\]]+\\]", // Matches regular identifiers, quoted identifiers ("identifier"), and bracketed identifiers [identifier]
@@ -47,7 +47,7 @@ class Tokenizer {
4747
let value = match.groups[type];
4848

4949
// Remove surrounding single quotes from placeholders
50-
if (type === "placeholder") value = value.replace(/^['"]|['"]$/g, "").replace(" ", "");
50+
if (type === "placeholder") value = value.replace(/^[\s'"\(\)]+|[\s'"\(\)]+|[\s]+/g, "");
5151

5252
if (type === "operator") {
5353
const lowerValue = value.toLowerCase();
@@ -59,15 +59,15 @@ class Tokenizer {
5959
}
6060
}
6161

62-
if (LITERALS.includes(type)){
62+
if (LITERALS.includes(type)) {
6363
value = value.replace(/^[(]|[)]$/g, "");
6464
}
6565

6666
if (type === "identifier") {
6767
value = value.replace(/^["\[]|["\]]$/g, "");
6868
}
69-
70-
69+
70+
7171
return { type, value };
7272
}
7373

src/debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// const astTree = parsedResult.ast;
2626
// console.log("AST Tree:", JSON.stringify(astTree, null, 2), "\n");
2727

28-
// return convertToDevExpressFormat({ ast: astTree, variables: extractedVariables, resultObject: sampleData });
28+
// return convertToDevExpressFormat({ ast: astTree, resultObject: sampleData });
2929
// }
3030

3131
// const devexpress = parseFilterString("OrderID = {CustomerOrders.OrderID} AND Status IN (1, 3)", sampleData);

tests/parser.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ describe("Parser SQL to dx Filter Builder", () => {
185185
]
186186
},
187187
{
188-
input: "AddressType IN ('2', ('4'))",
188+
input: "AddressType IN ('2', ('4')) OR AddressType =({ServiceOrderDocument .SourceID})",
189189
expected: [
190190
["AddressType", "=", '2'],
191191
"or",
192-
["AddressType", "=", '4']
192+
["AddressType", "=", '4'],
193+
"or",
194+
["AddressType", "=", 2]
193195
]
194196
}
195197
];
@@ -217,7 +219,7 @@ describe("Parser SQL to dx Filter Builder", () => {
217219
const variables = astwithVariables.variables;
218220
const ast = astwithVariables.ast;
219221

220-
const result = convertAstToDevextreme(ast, variables, sampleData);
222+
const result = convertAstToDevextreme(ast, sampleData);
221223

222224
if (result == null || result == true || result == false) {
223225
expect([]).toEqual(expected);

0 commit comments

Comments
 (0)