Adding def parser shell
Note that there is a name conflict in the modules for tokens, are they defined as some sort of global????
Solution for now is to split them into separate files. Why would this be the case for varaibles defined in a class??
from ply import lex
-from pathlib import Path
-
-#Documentation for ply
+#################################################################
+# DEF Parser
+#################################################################
+#The DEF parser uses the awesome lec tokenizer PLYL
#https://ply.readthedocs.io/en/latest/ply.html#the-tokens-list
-data = Path('/home/aolofsson/work/openroad/OpenDB/src/def/TEST/complete.5.8.def').read_text()
-
-########################
-# LEX Lexer
-########################
-
+class Def:
-#LEF Keywords
keywords = ["VERSION",
"BUSBITCHARS",
"DIVIDERCHAR",
@@ -47,6 +42,7 @@ keywords = ["VERSION",
#Tokens (nested keywords and delimeters)
tokens = keywords.copy()
+
tokens.extend(["SEMICOLON",
"PIPE",
"DIVIDER",
@@ -64,7 +60,6 @@ tokens.extend(["SEMICOLON",
"STRING",
"FLOAT"])
-
# Ignore white space and comments
t_ignore_COMMENT = r'\#.*'
t_ignore = ' \t'
@@ -95,29 +90,32 @@ t_QUOTE = r'\"'
t_STRING = r'\w+'
t_FLOAT = r'[\d\.\-]+'
+
+ #Create lexer once
+ def __init__ (self):
+ self.lexer = lex.lex(module=self)
+
# Keep track of newlines
-def t_newline(t):
+ def t_newline(self,t):
r'\n+'
t.lexer.lineno += len(t.value)
-def t_error(t):
+ def t_error(self,t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
-# Build the lexer
-lexer = lex.lex()
-lexer.input(data)
-
-########################
-# DEF Parser
-########################
+ def parse(self,data):
string = False
lef = {}
values = []
keyword = None
-routing_layer = 1
+
+ #Insert data to lexer
+ self.lexer.input(data)
+
+ #Parse each token
while True:
- tok = lexer.token()
+ tok = self.lexer.token()
if not tok:
break
if(tok.value == "\""):
@@ -128,3 +126,15 @@ while True:
else:
values.append(tok.value)
+
+####################################################
+#FOOFOO TESTING
+####################################################
+from pathlib import Path
+
+defdata = Path('test/complete.5.8.def').read_text()
+mydef = Def()
+mydef.parse(defdata)
+
+
+
