aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2011-06-20 21:00:52 +0200
committerSebastian Parborg <darkdefende@gmail.com>2011-06-20 21:00:52 +0200
commit2ede9d421509cebebaac006c138b2460c4edcd45 (patch)
tree00f81a728352086a18bbbdb5acfbd283733e62c0 /filetypes
parentfixed some more variable stuff (diff)
downloadebuildgen-2ede9d421509cebebaac006c138b2460c4edcd45.tar.gz
ebuildgen-2ede9d421509cebebaac006c138b2460c4edcd45.tar.bz2
ebuildgen-2ede9d421509cebebaac006c138b2460c4edcd45.zip
It now parses the doneyet makefile again.
Diffstat (limited to 'filetypes')
-rw-r--r--filetypes/makefilecom.py37
-rw-r--r--filetypes/makefiles.py86
2 files changed, 84 insertions, 39 deletions
diff --git a/filetypes/makefilecom.py b/filetypes/makefilecom.py
index 21b2c3b..d1e9d65 100644
--- a/filetypes/makefilecom.py
+++ b/filetypes/makefilecom.py
@@ -26,14 +26,15 @@ def com_interp(string,variables):
)
states = (
("ccode", "exclusive"), #command code
+ ("eval", "exclusive"), #code to evaluate
)
# Match the first $(. Enter ccode state.
- def t_ccode(t):
+ def t_eval_ccode(t):
r'\$(\{|\()'
t.lexer.code_start = t.lexer.lexpos # Record the starting position
t.lexer.level = 1 # Initial level
- t.lexer.begin('ccode') # Enter 'ccode' state
+ t.lexer.push_state('ccode') # Enter 'ccode' state
# Rules for the ccode state
def t_ccode_newcom(t):
@@ -48,7 +49,7 @@ def com_interp(string,variables):
if t.lexer.level == 0:
t.value = t.lexer.lexdata[t.lexer.code_start-1:t.lexer.lexpos]
t.type = "COMMAND"
- t.lexer.begin('INITIAL')
+ t.lexer.pop_state()
return t
def t_ccode_text(t):
@@ -56,33 +57,39 @@ def com_interp(string,variables):
def t_BEGINCOM(t):
r"(\(|\{)"
+ t.lexer.begin("eval")
return t
- def t_ENDCOM(t):
+ def t_eval_ENDCOM(t):
r"(\)|\})"
+ t.lexer.begin("INITIAL")
return t
- def t_PERCENT(t):
+ def t_eval_PERCENT(t):
r"\%"
return t
- def t_EQ(t):
+ def t_eval_EQ(t):
r"="
- return t
+ return t
- def t_COMMA(t):
+ def t_eval_COMMA(t):
r","
return t
- def t_COL(t):
+ def t_eval_COL(t):
r":"
return t
- def t_TEXT(t):
+ def t_eval_TEXT(t):
r"[^ \n\t:=\)\}\(\}\\\$,]+"
return t
- def t_SPACE(t):
+ def t_TEXT(t):
+ r"[^ \\t$\(\{]"
+ return t
+
+ def t_eval_SPACE(t):
r"[ \t]"
return t
@@ -92,9 +99,9 @@ def com_interp(string,variables):
lexer = lex.lex()
- #lexer.input(string)
- #for tok in lexer:
- # print(tok)
+ lexer.input(string)
+ for tok in lexer:
+ print(tok)
#YACC stuff begins here
@@ -281,4 +288,4 @@ def com_interp(string,variables):
return retlst
-#print(com_interp("(y)y(y)",{"x":["y"], "y":["z"], "z":["u"],"yz":["u","v"]}))
+print(com_interp("(SRC:.c=.o)",{"x":["y"], "y":["z"], "z":["u"],'SRC': [['(wildcard src/*.c)']]}))
diff --git a/filetypes/makefiles.py b/filetypes/makefiles.py
index 9ea8d1a..0323032 100644
--- a/filetypes/makefiles.py
+++ b/filetypes/makefiles.py
@@ -14,10 +14,8 @@ def scanmakefile(makefile):
"QEQ",
"TEXT",
"COMMAND",
- "PERCENT",
"ENDTAB",
"LIT",
- "COMMA",
"SPACE",
)
@@ -76,18 +74,10 @@ def scanmakefile(makefile):
t.lexer.lineno += 1
return t
- def t_SEMICOL(t):
- r";"
- return t
-
def t_bsdexe(t): #Create a cleaner version
r".*\!=.*"
pass
- def t_PERCENT(t):
- r"\%"
- return t
-
def t_EQ(t):
r"[ \t]*=[ \t]*"
t.lexer.begin("var")
@@ -119,19 +109,24 @@ def scanmakefile(makefile):
return t
def t_COL(t):
- r":"
+ r"[ \t]*:[ \t]*"
+ t.lexer.begin("var")
return t
- def t_COMMA(t):
- r","
+ def t_var_ENDTAB(t):
+ r"[ \t]*;[ \t]*"
return t
- def t_SPACE(t):
- r"[ \t]"
+ def t_SEMICOL(t):
+ r";"
+ return t
+
+ def t_COMMA(t):
+ r","
return t
def t_ENDTAB(t):
- r"[ \t]*\n\t"
+ r"[ \t]*\n\t[ \t]*"
t.lexer.lineno += 1
return t
@@ -149,6 +144,15 @@ def scanmakefile(makefile):
t.lexer.begin('INITIAL')
return t
+ def t_SPACE(t):
+ r"[ \t]"
+ return t
+
+ def t_var_special(t):
+ r"\$[^({]"
+ t.type = "TEXT"
+ return t
+
def t_ANY_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
@@ -168,10 +172,36 @@ def scanmakefile(makefile):
def p_testvar(p):
"""
- compvar : compvar var
- | compvar end
- | var
+ comp : comp var
+ | comp rule
+ | comp end
+ | var
+ | rule
+ """
+
+ def p_ruleoption(p):
+ """
+ rule : end textlst COL textlst options
+ | end textlst COL options
"""
+ if len(p) == 6:
+ for target in expand(p[2],variables):
+ targets.append([target,expand(p[4],variables),p[5]])
+ else:
+ for target in expand(p[2],variables):
+ targets.append([target,[],p[4]])
+
+ def p_rule(p):
+ """
+ rule : end textlst COL textlst
+ | end textlst COL
+ """
+ if len(p) == 5:
+ for target in expand(p[2],variables):
+ targets.append([target,expand(p[4],variables),[]])
+ else:
+ for target in expand(p[2],variables):
+ targets.append([target,[],[]])
def p_peq(p): #immediate if peq was defined as immediate before else deferred
"""
@@ -220,6 +250,16 @@ def scanmakefile(makefile):
else:
variables[p[2]] = []
+ def p_options(p):
+ """
+ options : options ENDTAB textlst
+ | ENDTAB textlst
+ """
+ if len(p) == 4:
+ p[0] = p[1] + p[3]
+ else:
+ p[0] = p[2]
+
def p_textlst(p):
"""
textlst : textlst spacestr command
@@ -290,12 +330,10 @@ def scanmakefile(makefile):
yacc.parse(makefile)
+ for target in targets:
+ print(target)
print(variables)
- #for target in targets:
- # print(target)
- #print(variables)
-
#return targets
@@ -303,7 +341,7 @@ def scanmakefile(makefile):
#deferred
-file="Makefile2"
+file="Makefile"
with open(file, encoding="utf-8", errors="replace") as inputfile:
scanmakefile(inputfile.read())