summaryrefslogtreecommitdiffstats
path: root/server/yaml/inline.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/yaml/inline.py')
-rwxr-xr-xserver/yaml/inline.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/server/yaml/inline.py b/server/yaml/inline.py
new file mode 100755
index 0000000..8e647de
--- /dev/null
+++ b/server/yaml/inline.py
@@ -0,0 +1,38 @@
+import re
+import string
+
+class InlineTokenizer:
+ def __init__(self, data):
+ self.data = data
+
+ def punctuation(self):
+ puncts = [ '[', ']', '{', '}' ]
+ for punct in puncts:
+ if self.data[0] == punct:
+ self.data = self.data[1:]
+ return punct
+
+ def up_to_comma(self):
+ match = re.match('(.*?)\s*, (.*)', self.data)
+ if match:
+ self.data = match.groups()[1]
+ return match.groups()[0]
+
+ def up_to_end_brace(self):
+ match = re.match('(.*?)(\s*[\]}].*)', self.data)
+ if match:
+ self.data = match.groups()[1]
+ return match.groups()[0]
+
+ def next(self):
+ self.data = string.strip(self.data)
+ productions = [
+ self.punctuation,
+ self.up_to_comma,
+ self.up_to_end_brace
+ ]
+ for production in productions:
+ token = production()
+ if token:
+ return token
+