Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor code
  • Loading branch information
akrambek committed Oct 16, 2024
commit a99a47b363dab45be779619f671929537a11082d
2,074 changes: 2,074 additions & 0 deletions incubator/binding-pgsql/gen/PostgreSqlLexer.interp

Large diffs are not rendered by default.

5,245 changes: 5,245 additions & 0 deletions incubator/binding-pgsql/gen/PostgreSqlLexer.java

Large diffs are not rendered by default.

1,314 changes: 1,314 additions & 0 deletions incubator/binding-pgsql/gen/PostgreSqlLexer.tokens

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* specific language governing permissions and limitations under the License.
*/

lexer grammar PostgreSQLLexer;
lexer grammar PostgreSqlLexer;
/* Reference:
* http://www.postgresql.org/docs/9.3/static/sql-syntax-lexical.html
*/

options {
superClass = PostgreSQLLexerBase;
superClass = PostgreSqlLexerBase;
caseInsensitive = true;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ Operator:
)
//TODO somehow rewrite this part without using Actions
{
HandleLessLessGreaterGreater();
handleLessLessGreaterGreater();
}
;
/* This rule handles operators which end with + or -, and sets the token type to Operator. It is comprised of four
Expand Down Expand Up @@ -1408,7 +1408,7 @@ fragment IdentifierStartChar options {
[\u0100-\uD7FF\uE000-\uFFFF] {charIsLetter()}?
| // letters which require multiple UTF-16 code units
[\uD800-\uDBFF] [\uDC00-\uDFFF] {
CheckIfUtf32Letter()
checkIfUtf32Letter()
}?
;

Expand Down Expand Up @@ -1509,7 +1509,7 @@ InvalidUnterminatedHexadecimalStringConstant: 'X' UnterminatedStringConstant;

Integral: Digits;

NumericFail: Digits '..' {HandleNumericFail();};
NumericFail: Digits '..' {handleNumericFail();};

Numeric:
Digits '.' Digits? /*? replaced with + to solve problem with DOT_DOT .. but this surely must be rewriten */ (
Expand Down Expand Up @@ -1557,7 +1557,7 @@ UnterminatedBlockComment:
('/'+ | '*'+ | '/'* UnterminatedBlockComment)?
// Optional assertion to make sure this rule is working as intended
{
UnterminatedBlockCommentDebugAssert();
unterminatedBlockCommentDebugAssert();
}
;
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* specific language governing permissions and limitations under the License.
*/

parser grammar PostgreSQLParser;
parser grammar PostgreSqlParser;

options {
tokenVocab = PostgreSQLLexer;
superClass = PostgreSQLParserBase;
tokenVocab = PostgreSqlLexer;
superClass = PostgreSqlParserBase;
}

@header {
Expand Down Expand Up @@ -2001,7 +2001,7 @@ aggregate_with_argtypes_list

createfunc_opt_list
: createfunc_opt_item+ {
ParseRoutineBody(_localctx);
parseRoutineBody(_localctx);
}
// | createfunc_opt_list createfunc_opt_item
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package io.aklivity.zilla.runtime.binding.pgsql.parser;


import java.util.BitSet;

import org.antlr.v4.runtime.ANTLRErrorListener;
Expand All @@ -28,12 +27,12 @@

public class LexerDispatchingErrorListener implements ANTLRErrorListener
{
@SuppressWarnings("checkstyle:MemberName")
Lexer _parent;
Lexer parent;

public LexerDispatchingErrorListener(Lexer parent)
public LexerDispatchingErrorListener(
Lexer parent)
{
_parent = parent;
this.parent = parent;
}

public void syntaxError(
Expand All @@ -44,41 +43,44 @@ public void syntaxError(
String msg,
RecognitionException e)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
ProxyErrorListener foo = new ProxyErrorListener(parent.getErrorListeners());
foo.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
}

public void reportAmbiguity(Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
BitSet ambigAlts,
ATNConfigSet configs)
public void reportAmbiguity(
Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
BitSet ambigAlts,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
foo.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
ProxyErrorListener proxyError = new ProxyErrorListener(parent.getErrorListeners());
proxyError.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
}

public void reportAttemptingFullContext(Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
BitSet conflictingAlts,
ATNConfigSet configs)
public void reportAttemptingFullContext(
Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
BitSet conflictingAlts,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
foo.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
ProxyErrorListener proxyError = new ProxyErrorListener(parent.getErrorListeners());
proxyError.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
}

public void reportContextSensitivity(Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
int prediction,
ATNConfigSet configs)
public void reportContextSensitivity(
Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
int prediction,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
foo.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
ProxyErrorListener proxyError = new ProxyErrorListener(parent.getErrorListeners());
proxyError.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
public class ParserDispatchingErrorListener implements ANTLRErrorListener
{
@SuppressWarnings("checkstyle:MemberName")
Parser _parent;
Parser parent;

public ParserDispatchingErrorListener(Parser parent)
public ParserDispatchingErrorListener(
Parser parent)
{
_parent = parent;
this.parent = parent;
}

public void syntaxError(
Expand All @@ -42,7 +43,7 @@ public void syntaxError(
String msg,
RecognitionException e)
{
var foo = new ProxyErrorListener(_parent.getErrorListeners());
var foo = new ProxyErrorListener(parent.getErrorListeners());
foo.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
}

Expand All @@ -55,7 +56,7 @@ public void reportAmbiguity(
BitSet ambigAlts,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
ProxyErrorListener foo = new ProxyErrorListener(parent.getErrorListeners());
foo.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
}

Expand All @@ -67,7 +68,7 @@ public void reportAttemptingFullContext(
BitSet conflictingAlts,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
ProxyErrorListener foo = new ProxyErrorListener(parent.getErrorListeners());
foo.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
}

Expand All @@ -79,7 +80,7 @@ public void reportContextSensitivity(
int prediction,
ATNConfigSet configs)
{
ProxyErrorListener foo = new ProxyErrorListener(_parent.getErrorListeners());
ProxyErrorListener foo = new ProxyErrorListener(parent.getErrorListeners());
foo.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import io.aklivity.zilla.runtime.binding.pgsql.parser.listener.SQLTableCommandListener;
import io.aklivity.zilla.runtime.binding.pgsql.parser.listener.SqlTableCommandListener;

public final class PgsqlParser
{
private final ParseTreeWalker walker;
private final BailErrorStrategy errorStrategy;
private final PostgreSQLLexer lexer;
private final PostgreSqlLexer lexer;
private final CommonTokenStream tokens;
private final PostgreSQLParser parser;
private final SQLTableCommandListener tableCommand;
private final PostgreSqlParser parser;
private final SqlTableCommandListener tableCommand;

public PgsqlParser()
{
this.walker = new ParseTreeWalker();
this.errorStrategy = new BailErrorStrategy();
this.lexer = new PostgreSQLLexer(null);
this.parser = new PostgreSQLParser(null);
this.lexer = new PostgreSqlLexer(null);
this.parser = new PostgreSqlParser(null);
this.tokens = new CommonTokenStream(lexer);
this.tableCommand = new SQLTableCommandListener();
this.tableCommand = new SqlTableCommandListener();
parser.setErrorHandler(errorStrategy);
}

public SQLTableCommandListener.TableInfo parseTable(
public SqlTableCommandListener.TableInfo parseTable(
String sql)
{
CharStream input = CharStreams.fromString(sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public abstract class PostgreSQLLexerBase extends Lexer
public abstract class PostgreSqlLexerBase extends Lexer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this generated? If so then we shouldn't need to check it in.
Same for any other generated code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not auto generated the gramma is written around that

https://github.com/antlr/grammars-v4/tree/master/sql/postgresql/Java

{
protected final Deque<String> tags = new ArrayDeque<>();

protected PostgreSQLLexerBase(CharStream input)
protected PostgreSqlLexerBase(CharStream input)
{
super(input);

}

public void pushTag()
Expand Down Expand Up @@ -56,24 +54,30 @@ public boolean charIsLetter()
return Character.isLetter(getInputStream().LA(-1));
}

public void HandleNumericFail()
public void handleNumericFail()
{
getInputStream().seek(getInputStream().index() - 2);
setType(PostgreSQLLexer.Integral);
setType(PostgreSqlLexer.Integral);
}

public void HandleLessLessGreaterGreater()
public void handleLessLessGreaterGreater()
{
if (getText() == "<<") setType(PostgreSQLLexer.LESS_LESS);
if (getText() == ">>") setType(PostgreSQLLexer.GREATER_GREATER);
if ("<<".equals(getText()))
{
setType(PostgreSqlLexer.LESS_LESS);
}
if (">>".equals(getText()))
{
setType(PostgreSqlLexer.GREATER_GREATER);
}
}

public void UnterminatedBlockCommentDebugAssert()
public void unterminatedBlockCommentDebugAssert()
{
//Debug.Assert(InputStream.LA(1) == -1 /*EOF*/);
}

public boolean CheckIfUtf32Letter()
public boolean checkIfUtf32Letter()
{
int codePoint = getInputStream().LA(-2) << 8 + getInputStream().LA(-1);
char[] c;
Expand Down
Loading