aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2011-06-16 21:09:41 +0200
committerSebastian Parborg <darkdefende@gmail.com>2011-06-16 21:09:41 +0200
commit79af78d4222e0d3d8b7f6ea5916254f98e0908f6 (patch)
tree3104c117d3cfb446a2f38809cc5f37c33a970afa /filetypes/makefilecom.py
parentAdded basic SCM support (diff)
downloadebuildgen-79af78d4222e0d3d8b7f6ea5916254f98e0908f6.tar.gz
ebuildgen-79af78d4222e0d3d8b7f6ea5916254f98e0908f6.tar.bz2
ebuildgen-79af78d4222e0d3d8b7f6ea5916254f98e0908f6.zip
Added branch for the new makefile parser
Diffstat (limited to 'filetypes/makefilecom.py')
-rw-r--r--filetypes/makefilecom.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/filetypes/makefilecom.py b/filetypes/makefilecom.py
new file mode 100644
index 0000000..6bfd29b
--- /dev/null
+++ b/filetypes/makefilecom.py
@@ -0,0 +1,82 @@
+from ply import lex
+from ply import yacc
+
+def com_interp(string):
+ tokens = (
+ "COMMAND",
+ "COMMA",
+ "EQ",
+ "TEXT",
+ "PERCENT",
+ )
+ states = (
+ ("ccode", "exclusive"), #command code
+ )
+
+ # Match the first $(. Enter ccode state.
+ def t_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
+
+ # Rules for the ccode state
+ def t_ccode_newcom(t):
+ r'\$(\{|\()'
+ t.lexer.level +=1
+
+ def t_ccode_endcom(t):
+ r'(\}|\))'
+ t.lexer.level -=1
+
+ # If closing command, return the code fragment
+ if t.lexer.level == 0:
+ t.value = t.lexer.lexdata[t.lexer.code_start:t.lexer.lexpos-1]
+ t.type = "COMMAND"
+ t.lexer.begin('INITIAL')
+ return t
+
+ def t_ccode_text(t):
+ "[^\$\(\{\)\}]"
+
+ def t_PERCENT(t):
+ r"\%"
+ return t
+
+ def t_EQ(t):
+ r"="
+ return t
+
+ def t_COMMA(t):
+ r","
+ return t
+
+ def t_TEXT(t):
+ r"[^ \n\t:=\\,]+"
+ return t
+
+ def t_spacetab(t):
+ r"[ \t]"
+ pass
+
+ def t_ANY_error(t):
+ print("Illegal character '%s'" % t.value[0])
+ t.lexer.skip(1)
+
+ lexer = lex.lex()
+
+ lexer.input(string)
+ #for tok in lexer:
+ # print(tok)
+
+ tokens = 0
+ for tok in lexer:
+ tokens += 1
+ print("gethere")
+
+ print(tokens)
+ if tokens == 1:
+ print("gapp")
+
+
+com_interp("HELOO")