aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2011-06-19 22:57:44 +0200
committerSebastian Parborg <darkdefende@gmail.com>2011-06-19 22:57:44 +0200
commitf9f5bbdefef05e8877d0d53cc34d38576c174794 (patch)
tree1aa728569e53de27df6e3f8b74928b4d20f3ab8b
parentMade command interp handle mixed strings and vars (diff)
downloadebuildgen-f9f5bbdefef05e8877d0d53cc34d38576c174794.tar.gz
ebuildgen-f9f5bbdefef05e8877d0d53cc34d38576c174794.tar.bz2
ebuildgen-f9f5bbdefef05e8877d0d53cc34d38576c174794.zip
Parsing of variables seems to work now.
-rw-r--r--filetypes/makefilecom.py2
-rw-r--r--filetypes/makefiles.py73
2 files changed, 49 insertions, 26 deletions
diff --git a/filetypes/makefilecom.py b/filetypes/makefilecom.py
index 71adab9..21b2c3b 100644
--- a/filetypes/makefilecom.py
+++ b/filetypes/makefilecom.py
@@ -211,7 +211,7 @@ def com_interp(string,variables):
"""
func : BEGINCOM textstr SPACE funcinput
"""
- result = "This calls a function"
+ result = ["This calls a function"]
#result = funcexe(p[2],p[4])
p[0] = result
diff --git a/filetypes/makefiles.py b/filetypes/makefiles.py
index 09719cf..41cb584 100644
--- a/filetypes/makefiles.py
+++ b/filetypes/makefiles.py
@@ -58,7 +58,11 @@ def scanmakefile(makefile):
t.lexer.push_state("com")
def t_com_other(t):
- r"[^(\n|\\)]+"
+ r"[^\\\n]+"
+ pass
+
+ def t_com_lit(t):
+ r"\\."
pass
def t_com_newline(t):
@@ -85,23 +89,23 @@ def scanmakefile(makefile):
return t
def t_EQ(t):
- r"=[ \t]*"
- t.lexer.begin('var')
+ r"[ \t]*=[ \t]*"
+ t.lexer.begin("var")
return t
def t_PEQ(t):
- r"\+=[ \t]*"
- t.lexer.begin('var')
+ r"[ \t]*\+=[ \t]*"
+ t.lexer.begin("var")
return t
def t_CEQ(t):
- r":=[ \t]*"
- t.lexer.begin('var')
+ r"[ \t]*:=[ \t]*"
+ t.lexer.begin("var")
return t
def t_QEQ(t):
- r"\?=[ \t]*"
- t.lexer.begin('var')
+ r"[ \t]*\?=[ \t]*"
+ t.lexer.begin("var")
return t
def t_contline(t):
@@ -131,8 +135,12 @@ def scanmakefile(makefile):
t.lexer.lineno += 1
return t
+ def t_var_TEXT(t):
+ r"[^ \n\t,\$\\]+"
+ return t
+
def t_TEXT(t):
- r"[^ \n\t:\?\+=\\,]+"
+ r"[^ \n\t:\?\+=\\,\$]+"
return t
def t_END(t):
@@ -158,12 +166,19 @@ def scanmakefile(makefile):
ivars = [] #keep track of the immediate variables
targets = [] #buildtargets, [[target,deps,options],[target2,....
+ def p_testvar(p):
+ """
+ compvar : compvar var
+ | compvar end
+ | var
+ """
+
def p_peq(p): #immediate if peq was defined as immediate before else deferred
"""
- end : end textstr PEQ textlst end
- | end textstr PEQ end
+ var : end textstr PEQ textlst
+ | end textstr PEQ
"""
- if len(p) == 6:
+ if len(p) == 5:
if not p[2] in variables:
variables[p[2]] = p[4]
elif not p[2] in ivars:
@@ -174,11 +189,10 @@ def scanmakefile(makefile):
def p_ceq(p): #immediate
"""
- end : end textstr CEQ textlst end
- | end textstr CEQ end
+ var : end textstr CEQ textlst
+ | end textstr CEQ
"""
- if len(p) == 6:
- print(p[4])
+ if len(p) == 5:
textvalue = expand(p[4],variables) #expand any variables
variables[p[2]] = textvalue
ivars.append(p[2])
@@ -188,20 +202,20 @@ def scanmakefile(makefile):
def p_qeq(p): #deferred
"""
- end : end textstr QEQ textlst end
- | end textstr QEQ end
+ var : end textstr QEQ textlst
+ | end textstr QEQ
"""
- if not p[2] in variables and len(p) == 6:
+ if not p[2] in variables and len(p) == 5:
variables[p[2]] = p[4]
else:
variables[p[2]] = []
def p_var(p): #deferred
"""
- end : end textstr EQ textlst end
- | end textstr EQ end
+ var : end textstr EQ textlst
+ | end textstr EQ
"""
- if len(p) == 6:
+ if len(p) == 5:
variables[p[2]] = p[4]
else:
variables[p[2]] = []
@@ -218,6 +232,16 @@ def scanmakefile(makefile):
else:
p[0] = [p[1]]
+ def p_com_and_str(p):
+ """
+ command : command textstr
+ | textstr command
+ """
+ if isinstance(p[1],list):
+ p[0] = [p[1][0] + p[2]]
+ else:
+ p[0] = [p[1] + p[2][0]]
+
def p_textstr(p):
"""
textstr : textstr LIT
@@ -235,7 +259,7 @@ def scanmakefile(makefile):
| COMMAND
"""
if len(p) == 2:
- p[0] = [p[1]] #commands are lists within the testlst
+ p[0] = [p[1]] #commands are lists within the textlst
else:
p[0] = [p[1][0] + p[2]]
@@ -243,7 +267,6 @@ def scanmakefile(makefile):
"""
end : end END
| end spacestr END
- | end spacestr
| END
"""