Skip to content
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

Created lexer module #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
antlr-4.7.2-complete.jar
*.jar
MySQLParser.interp
MySQLParser.py
MySQLParserListener.py
MySQLLexer.interp
MySQLLexer.py
grammar/__pycache__
grammar/__pycache__
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Setting up antlr:

```
wget http://www.antlr.org/download/antlr-4.7.2-complete.jar > bin
export CLASSPATH=${PWD}"/antlr-4.7.2-complete.jar:$CLASSPATH"
alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
wget http://www.antlr.org/download/antlr-4.8-complete.jar -O bin/antlr-4.8-complete.jar
export CLASSPATH=${PWD}"/bin/antlr-4.8-complete.jar"
alias antlr4='java -Xmx500M -cp ${PWD}"/bin/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
alias grun='java org.antlr.v4.gui.TestRig'
```

Expand All @@ -14,3 +14,9 @@ Generating the parser:
cd grammar
antlr4 -Dlanguage=Python3 MySQLLexer.g4 MySQLParser.g4
```

## TODO

1. Create all methods in MySQLBaseLexer:
* getText
*
Empty file added bin/README.md
Empty file.
64 changes: 64 additions & 0 deletions grammar/MySQLBaseLexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from antlr4 import Lexer


class MySQLBaseLexer(Lexer):
def __init__(self, server_version, *a, **kw):
self.server_version = server_version
super().__init__(*a, **kw)
self.pending_tokens = []

def determineNumericType(self, s: str):
pass
# LENGTH_LONG = 10
# LENGTH_LONGLONG = 19
# LENGTH_SIGNED_LONGLONG = 19
# LENGTH_UNSIGNED_LONGLONG = 20
#
# value = int(s)
# s_normalized = str(value) if value >= 0 else str(value)[1:]
#
# length = len(s_normalized)
# if length < LENGTH_LONG:
# return self.INT_NUMBER
#
# if value < 0


def setType(self, *a, **kw):
pass

def getText(self, *a, **kw):
print('getText')
pass

def emitDot(self, *a, **kw):
t = self._factory.create(self._tokenFactorySourcePair, self.DOT_SYMBOL, self._text, self._channel,
self._tokenStartCharIndex,
self._tokenStartCharIndex, self._tokenStartLine, self._tokenStartColumn)
self.pending_tokens.append(t)
self._tokenStartCharIndex += 1

def isSqlModeActive(self, *a, **kw):
pass

def nextToken(self):
if self.pending_tokens:
return self.pending_tokens.pop()

next_token = super().nextToken()
if self.pending_tokens:
pending_token = self.pending_tokens.pop()
self.pending_tokens.append(next_token)
return pending_token

return next_token

def checkVersion(self, s: str):
pass

def determineFunction(self, token: int):
return

NoBackslashEscapes = True
inVersionComment = True
PipesAsConcat = True
394 changes: 195 additions & 199 deletions grammar/MySQLLexer.g4

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions grammar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .MySQLLexer import MySQLLexer
# from .MySQLParser import MySQLParser
3 changes: 0 additions & 3 deletions test.py

This file was deleted.