aboutsummaryrefslogtreecommitdiffstats
path: root/wlp.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-01-05 09:03:05 +0100
committerMatěj Cepl <mcepl@cepl.eu>2015-01-05 12:59:40 +0100
commitd17b009ffec3077bf8db6e6902a7456ec90e9c38 (patch)
tree2a5ee305bd8c8a39faf7c2db342d399c689ae432 /wlp.py
parenta9e311030533ac6c175e2289e8928e4aae98b6c3 (diff)
downloadpygn-d17b009ffec3077bf8db6e6902a7456ec90e9c38.tar.gz
First draft of the pure Python parser done, we should be noarch.
Fixes #2
Diffstat (limited to 'wlp.py')
-rw-r--r--wlp.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/wlp.py b/wlp.py
new file mode 100644
index 0000000..64d7361
--- /dev/null
+++ b/wlp.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import wlp_parser
+
+
+__current_file = None
+
+
+def setfilebyname(name):
+ global __current_file
+ __current_file = open(name, 'r')
+
+
+def setfilebyfd(fd):
+ global __current_file
+ __current_file = fd
+
+
+def mkdict():
+ dict = {}
+ if __current_file is None:
+ raise ValueError('current file has not been set.')
+
+ tree = wlp_parser.parser.parse(
+ wlp_parser.lexer.lex(__current_file.read()))
+
+ for subtree in tree:
+ current_key = subtree[0].getstr().strip('<>')
+ if current_key not in dict:
+ dict[current_key] = {}
+
+ for key, value in subtree[1]:
+ key = key.getstr()
+ value = value.getstr().strip("'\"")
+ dict[current_key][key] = value
+
+ return dict