Skip to content

Commit

Permalink
Update existing ports of Oracle MySQL to set defaults in constructors…
Browse files Browse the repository at this point in the history
…, so Test.* can be generated/removed. Add Dart port.
  • Loading branch information
kaby76 committed Nov 29, 2024
1 parent 97bd288 commit 00a96c9
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 980 deletions.
98 changes: 52 additions & 46 deletions sql/mysql/Oracle/Antlr4ng/MySQLLexerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable no-underscore-dangle */
/* cspell: ignore antlr, longlong, ULONGLONG, MAXDB */

import { Lexer, Token } from "antlr4ng";
import { CharStream, Lexer, Token } from "antlr4ng";
import { MySQLLexer } from "./MySQLLexer.js";

/** SQL modes that control parsing behavior. */
Expand Down Expand Up @@ -41,6 +41,12 @@ export abstract class MySQLLexerBase extends Lexer {
static #unsignedLongLongString = "18446744073709551615";
static #unsignedLongLongLength = 20;

constructor(input: CharStream) {
super(input);
this.serverVersion = 80200;
this.sqlModeFromString("ANSI_QUOTES");
}

/**
* Determines if the given SQL mode is currently active in the lexer.
*
Expand Down Expand Up @@ -313,226 +319,226 @@ export abstract class MySQLLexerBase extends Lexer {

public doLogicalOr(): void
{
this.type = this.isSqlModeActive(SqlMode.PipesAsConcat) ? MySQLLexer.CONCAT_PIPES_SYMBOL : MySQLLexer.LOGICAL_OR_OPERATOR;
this.type = this.isSqlModeActive(SqlMode.PipesAsConcat) ? MySQLLexer.CONCAT_PIPES_SYMBOL : MySQLLexer.LOGICAL_OR_OPERATOR;
}

public doIntNumber(): void
{
this.type = this.determineNumericType(this.text);
this.type = this.determineNumericType(this.text);
}

public doAdddate(): void
{
this.type = this.determineFunction(MySQLLexer.ADDDATE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.ADDDATE_SYMBOL);
}

public doBitAnd(): void
{
this.type = this.determineFunction(MySQLLexer.BIT_AND_SYMBOL);
this.type = this.determineFunction(MySQLLexer.BIT_AND_SYMBOL);
}

public doBitOr(): void
{
this.type = this.determineFunction(MySQLLexer.BIT_OR_SYMBOL);
this.type = this.determineFunction(MySQLLexer.BIT_OR_SYMBOL);
}

public doBitXor(): void
{
this.type = this.determineFunction(MySQLLexer.BIT_XOR_SYMBOL);
this.type = this.determineFunction(MySQLLexer.BIT_XOR_SYMBOL);
}

public doCast(): void
{
this.type = this.determineFunction(MySQLLexer.CAST_SYMBOL);
this.type = this.determineFunction(MySQLLexer.CAST_SYMBOL);
}

public doCount(): void
{
this.type = this.determineFunction(MySQLLexer.COUNT_SYMBOL);
this.type = this.determineFunction(MySQLLexer.COUNT_SYMBOL);
}

public doCurdate(): void
{
this.type = this.determineFunction(MySQLLexer.CURDATE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.CURDATE_SYMBOL);
}

public doCurrentDate(): void
{
this.type = this.determineFunction(MySQLLexer.CURDATE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.CURDATE_SYMBOL);
}

public doCurrentTime(): void
{
this.type = this.determineFunction(MySQLLexer.CURTIME_SYMBOL);
this.type = this.determineFunction(MySQLLexer.CURTIME_SYMBOL);
}

public doCurtime(): void
{
this.type = this.determineFunction(MySQLLexer.CURTIME_SYMBOL);
this.type = this.determineFunction(MySQLLexer.CURTIME_SYMBOL);
}

public doDateAdd(): void
{
this.type = this.determineFunction(MySQLLexer.DATE_ADD_SYMBOL);
this.type = this.determineFunction(MySQLLexer.DATE_ADD_SYMBOL);
}

public doDateSub(): void
{
this.type = this.determineFunction(MySQLLexer.DATE_SUB_SYMBOL);
this.type = this.determineFunction(MySQLLexer.DATE_SUB_SYMBOL);
}

public doExtract(): void
{
this.type = this.determineFunction(MySQLLexer.EXTRACT_SYMBOL);
this.type = this.determineFunction(MySQLLexer.EXTRACT_SYMBOL);
}

public doGroupConcat(): void
{
this.type = this.determineFunction(MySQLLexer.GROUP_CONCAT_SYMBOL);
this.type = this.determineFunction(MySQLLexer.GROUP_CONCAT_SYMBOL);
}

public doMax(): void
{
this.type = this.determineFunction(MySQLLexer.MAX_SYMBOL);
this.type = this.determineFunction(MySQLLexer.MAX_SYMBOL);
}

public doMid(): void
{
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
}

public doMin(): void
{
this.type = this.determineFunction(MySQLLexer.MIN_SYMBOL);
this.type = this.determineFunction(MySQLLexer.MIN_SYMBOL);
}

public doNot(): void
{
this.type = this.isSqlModeActive(SqlMode.HighNotPrecedence) ? MySQLLexer.NOT2_SYMBOL: MySQLLexer.NOT_SYMBOL;
this.type = this.isSqlModeActive(SqlMode.HighNotPrecedence) ? MySQLLexer.NOT2_SYMBOL: MySQLLexer.NOT_SYMBOL;
}

public doNow(): void
{
this.type = this.determineFunction(MySQLLexer.NOW_SYMBOL);
this.type = this.determineFunction(MySQLLexer.NOW_SYMBOL);
}

public doPosition(): void
{
this.type = this.determineFunction(MySQLLexer.POSITION_SYMBOL);
this.type = this.determineFunction(MySQLLexer.POSITION_SYMBOL);
}

public doSessionUser(): void
{
this.type = this.determineFunction(MySQLLexer.USER_SYMBOL);
this.type = this.determineFunction(MySQLLexer.USER_SYMBOL);
}

public doStddevSamp(): void
{
this.type = this.determineFunction(MySQLLexer.STDDEV_SAMP_SYMBOL);
this.type = this.determineFunction(MySQLLexer.STDDEV_SAMP_SYMBOL);
}

public doStddev(): void
{
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
}

public doStddevPop(): void
{
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
}

public doStd(): void
{
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
this.type = this.determineFunction(MySQLLexer.STD_SYMBOL);
}

public doSubdate(): void
{
this.type = this.determineFunction(MySQLLexer.SUBDATE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SUBDATE_SYMBOL);
}

public doSubstr(): void
{
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
}

public doSubstring(): void
{
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SUBSTRING_SYMBOL);
}

public doSum(): void
{
this.type = this.determineFunction(MySQLLexer.SUM_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SUM_SYMBOL);
}

public doSysdate(): void
{
this.type = this.determineFunction(MySQLLexer.SYSDATE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.SYSDATE_SYMBOL);
}

public doSystemUser(): void
{
this.type = this.determineFunction(MySQLLexer.USER_SYMBOL);
this.type = this.determineFunction(MySQLLexer.USER_SYMBOL);
}

public doTrim(): void
{
this.type = this.determineFunction(MySQLLexer.TRIM_SYMBOL);
this.type = this.determineFunction(MySQLLexer.TRIM_SYMBOL);
}

public doVariance(): void
{
this.type = this.determineFunction(MySQLLexer.VARIANCE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.VARIANCE_SYMBOL);
}

public doVarPop(): void
{
this.type = this.determineFunction(MySQLLexer.VARIANCE_SYMBOL);
this.type = this.determineFunction(MySQLLexer.VARIANCE_SYMBOL);
}

public doVarSamp(): void
{
this.type = this.determineFunction(MySQLLexer.VAR_SAMP_SYMBOL);
this.type = this.determineFunction(MySQLLexer.VAR_SAMP_SYMBOL);
}

public doUnderscoreCharset(): void
{
this.type = this.checkCharset(this.text);
this.type = this.checkCharset(this.text);
}

public isVersionComment(): boolean
{
return this.checkMySQLVersion(this.text);
return this.checkMySQLVersion(this.text);
}

public isBackTickQuotedId(): boolean
{
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
}

public isDoubleQuotedText(): boolean
{
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
}

public isSingleQuotedText(): boolean
{
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
return !this.isSqlModeActive(SqlMode.NoBackslashEscapes);
}

public startInVersionComment(): void
{
this.inVersionComment = true;
this.inVersionComment = true;
}

public endInVersionComment(): void
{
this.inVersionComment = false;
this.inVersionComment = false;
}

public isInVersionComment(): boolean
{
return this.inVersionComment;
return this.inVersionComment;
}
}
44 changes: 38 additions & 6 deletions sql/mysql/Oracle/Antlr4ng/MySQLParserBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Copyright © 2024, Oracle and/or its affiliates
*/

import { Parser } from "antlr4ng";

import { Parser, TokenStream } from "antlr4ng";
import { SqlMode } from "./MySQLLexerBase.js";

export abstract class MySQLParserBase extends Parser {
Expand All @@ -15,6 +14,12 @@ export abstract class MySQLParserBase extends Parser {
/** Enable Multi Language Extension support. */
public supportMle = true;

constructor(input: TokenStream) {
super(input);
this.serverVersion = 80200;
this.sqlModeFromString("ANSI_QUOTES");
}

/**
* Determines if the given SQL mode is currently active in the lexer.
*
Expand All @@ -28,21 +33,48 @@ export abstract class MySQLParserBase extends Parser {

public isPureIdentifier(): boolean
{
return this.isSqlModeActive(SqlMode.AnsiQuotes);
return this.isSqlModeActive(SqlMode.AnsiQuotes);
}

public isTextStringLiteral(): boolean
{
return !this.isSqlModeActive(SqlMode.AnsiQuotes);
return !this.isSqlModeActive(SqlMode.AnsiQuotes);
}

public isStoredRoutineBody(): boolean
{
return this.serverVersion >= 80032 && this.supportMle;
return this.serverVersion >= 80032 && this.supportMle;
}

public isSelectStatementWithInto(): boolean
{
return this.serverVersion >= 80024 && this.serverVersion < 80031;
return this.serverVersion >= 80024 && this.serverVersion < 80031;
}

/**
* Converts a mode string into individual mode flags.
*
* @param modes The input string to parse.
*/
public sqlModeFromString(modes: string): void {
this.sqlModes = new Set<SqlMode>();

const parts = modes.toUpperCase().split(",");
parts.forEach((mode: string) => {
if (mode === "ANSI" || mode === "DB2" || mode === "MAXDB" || mode === "MSSQL" || mode === "ORACLE" ||
mode === "POSTGRESQL") {
this.sqlModes.add(SqlMode.AnsiQuotes).add(SqlMode.PipesAsConcat).add(SqlMode.IgnoreSpace);
} else if (mode === "ANSI_QUOTES") {
this.sqlModes.add(SqlMode.AnsiQuotes);
} else if (mode === "PIPES_AS_CONCAT") {
this.sqlModes.add(SqlMode.PipesAsConcat);
} else if (mode === "NO_BACKSLASH_ESCAPES") {
this.sqlModes.add(SqlMode.NoBackslashEscapes);
} else if (mode === "IGNORE_SPACE") {
this.sqlModes.add(SqlMode.IgnoreSpace);
} else if (mode === "HIGH_NOT_PRECEDENCE" || mode === "MYSQL323" || mode === "MYSQL40") {
this.sqlModes.add(SqlMode.HighNotPrecedence);
}
});
}
}
Loading

0 comments on commit 00a96c9

Please sign in to comment.