Skip to content

update antlr4 parser for pg #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
493 changes: 128 additions & 365 deletions backend/preprocessor/antlr_parser/pg_parser/PostgreSQLLexer.interp

Large diffs are not rendered by default.

6,996 changes: 3,279 additions & 3,717 deletions backend/preprocessor/antlr_parser/pg_parser/PostgreSQLLexer.py

Large diffs are not rendered by default.

2,354 changes: 1,096 additions & 1,258 deletions backend/preprocessor/antlr_parser/pg_parser/PostgreSQLLexer.tokens

Large diffs are not rendered by default.

106 changes: 76 additions & 30 deletions backend/preprocessor/antlr_parser/pg_parser/PostgreSQLLexerBase.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,95 @@
from antlr4 import *
# PostgreSQL grammar.
# The MIT License (MIT).
# Copyright (c) 2021-2023, Oleksii Kovalov (Oleksii.Kovalov@outlook.com).
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from typing import TextIO
from antlr4 import *
from antlr4.Token import CommonToken
import sys
from typing import TextIO

class PostgreSQLLexerBase(Lexer):

def __init__(self, input, output):
def IsColumnZero(self):
return self.column == 0

def VerifyNotOperator():
c1 = this.InputStream.LA(1);
if (c1 == 'a'):
c2 = this.InputStream.LA(2);
if (c2 == 'n'):
c3 = this.InputStream.LA(3);
if (c3 == 'd'):
c4 = this.InputStream.LA(4);
if (c4 == '.'):
return false;
elif (c1 == 'o'):
c2 = this.InputStream.LA(2);
if (c2 == 'r'):
c3 = this.InputStream.LA(3);
if (c3 == '.'):
return false;
return true;


class PostgreSQLLexerBase(Lexer):
def __init__(self, input: InputStream, output: TextIO = sys.stdout):
super().__init__(input, output)
self.tags = []

def pushTag(self):
self.tags.append(super().text)
def PushTag(self):
self.tags.append(self.text)

def isTag(self):
return super().text == self.tags[-1] if self.tags else False
def IsTag(self):
return self.text == self.tags[-1] if self.tags else False

def popTag(self):
def PopTag(self):
if self.tags:
self.tags.pop()

def checkLA(self, c):
return super().inputStream.LA(1) != c
def UnterminatedBlockCommentDebugAssert(self):
assert self._input.LA(1) == -1 # EOF

def CheckLaMinus(self):
return self._input.LA(1) != ord('-')

def CheckLaStar(self):
return self._input.LA(1) != ord('*')

def charIsLetter(self):
return super().inputStream.LA(-1).isalpha()
def CharIsLetter(self):
return chr(self._input.LA(-1)).isalpha()

def HandleNumericFail(self):
super().inputStream.seek(super().inputStream.index() - 2)
super().type(658)
self._input.seek(self._input.index - 2)
self.type = PostgreSQLLexer.INTEGRAL

def HandleLessLessGreaterGreater(self):
text = super().text
if text == "<<":
super().type(18)
elif text == ">>":
super().type(19)

def UnterminatedBlockCommentDebugAssert(self):
# Debug.Assert(InputStream.LA(1) == -1 /*EOF*/)
pass
if self.text == "<<":
self.type = PostgreSQLLexer.LESS_LESS
elif self.text == ">>":
self.type = PostgreSQLLexer.GREATER_GREATER

def CheckIfUtf32Letter(self):
code_point = super().inputStream.LA(-2) << 8 + super().inputStream.LA(-1)
if code_point < 0x10000:
c = [chr(code_point)]
else:
code_point -= 0x10000
c = [chr(code_point // 0x400 + 0xd800),
chr(code_point % 0x400 + 0xdc00)]
return c[0].isalpha()
try:
char = chr(int.from_bytes((chr(self._input.LA(-2)) + chr(self._input.LA(-1))).encode("utf-32"), 'little'))
return char.isalpha()
except ValueError:
return False

def IsSemiColon(self):
return chr(self._input.LA(1)) == ';'
Loading