Skip to content

Commit 8d364eb

Browse files
committed
lex unicode escape squences like \u407f to increase compatibility to OpenOffice
1 parent 0a8813e commit 8d364eb

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/client/compiler/lexer/Lexer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,22 @@ export class Lexer {
413413
if (char == "\\") {
414414
let escapeChar = EscapeSequenceList[this.nextChar];
415415
if (escapeChar == null) {
416-
this.pushError('Die Escape-Sequenz \\' + this.nextChar + ' gibt es nicht.', 2);
416+
if(this.nextChar == 'u'){ // Unicode escape sequences (for OpenOffice)
417+
let hex: string = "";
418+
this.next(); // skip \
419+
this.next(); // skip u
420+
while ("abcdef0123456789".indexOf(this.currentChar) >= 0 && hex.length < 4) {
421+
hex += this.currentChar;
422+
if(hex.length < 4) this.next();
423+
}
424+
if (hex.length < 4) {
425+
this.pushError('Unbekanntes Unicode-Zeichen: u' + hex, 1 + hex.length);
426+
} else {
427+
char = String.fromCodePoint(parseInt(hex, 16));
428+
}
429+
} else {
430+
this.pushError('Die Escape-Sequenz \\' + this.nextChar + ' gibt es nicht.', 2);
431+
}
417432
} else {
418433
char = escapeChar;
419434
this.next();

src/client/compiler/lexer/Token.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum TokenType {
2929
keywordPrimary,
3030
keywordForeign,
3131
keywordTable,
32+
keywordSchema,
3233
keywordTables,
3334
keywordColumn,
3435
keywordDrop,
@@ -202,6 +203,7 @@ export var TokenTypeReadable: {[tt: number]: string} = {
202203
[TokenType.keywordPrimary]: "primary",
203204
[TokenType.keywordForeign]: "foreign",
204205
[TokenType.keywordTable]: "table",
206+
[TokenType.keywordSchema]: "schema",
205207
[TokenType.keywordTables]: "tables",
206208
[TokenType.keywordColumn]: "column",
207209
[TokenType.keywordDrop]: "drop",

src/client/compiler/parser/Parser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,13 @@ export class Parser {
500500
}
501501

502502
this.nextToken(); // skip 'set'
503+
504+
// SET DATABASE Collation "German" ( -> OpenOffice)
505+
if(this.comesToken(TokenType.keywordDatabase)){
506+
this.nextToken();
507+
}
503508
this.expect(TokenType.identifier, true);
504-
this.expect(TokenType.equal, true);
509+
this.comesToken(TokenType.equal, true); // skip = if present
505510
this.expect([TokenType.identifier, TokenType.stringConstant, TokenType.integerConstant, TokenType.charConstant, TokenType.booleanConstant, TokenType.floatingPointConstant], true);
506511

507512
node.endPosition = this.getCurrentPosition();
@@ -1025,6 +1030,7 @@ export class Parser {
10251030
return this.parseCreateTable();
10261031
case TokenType.keywordView:
10271032
return this.parseCreateView();
1033+
case TokenType.keywordSchema:
10281034
default:
10291035
this.nextToken();
10301036
this.pushError("Nach 'create' wird 'table' erwartet.");

src/client/tools/DatabaseTools.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class DatabaseTool {
249249
let values = result[0]?.values;
250250
let types: ("table"|"view")[] = values?.map(value => value[2]);
251251

252-
values?.forEach(value => sql1 += `PRAGMA table_info(${value[0]});\nPRAGMA foreign_key_list(${value[0]});\nselect count(*) from ${value[0]};\n\n`)
252+
values?.forEach(value => sql1 += `PRAGMA table_info("${value[0]}");\nPRAGMA foreign_key_list("${value[0]}");\nselect count(*) from "${value[0]}";\n\n`)
253253

254254
if (sql1 != "") {
255255
this.executeQuery(sql1, (result1) => {
@@ -260,7 +260,11 @@ export class DatabaseTool {
260260

261261
callback(that.databaseStructure);
262262

263-
}, (error) => { console.log(error)});
263+
}, (error) => {
264+
console.log(error);
265+
that.databaseStructure = { tables: [] };
266+
callback(that.databaseStructure);
267+
});
264268
} else {
265269
that.databaseStructure = { tables: [] };
266270
callback(that.databaseStructure);

0 commit comments

Comments
 (0)