summaryrefslogtreecommitdiff
path: root/tools/generation/lib/util/parse_yaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/generation/lib/util/parse_yaml.py')
-rw-r--r--tools/generation/lib/util/parse_yaml.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/generation/lib/util/parse_yaml.py b/tools/generation/lib/util/parse_yaml.py
new file mode 100644
index 000000000..3ad356db8
--- /dev/null
+++ b/tools/generation/lib/util/parse_yaml.py
@@ -0,0 +1,17 @@
+# Copyright (C) 2016 the V8 project authors. All rights reserved.
+# This code is governed by the BSD license found in the LICENSE file.
+
+import yaml, re
+
+yamlPattern = re.compile(r'\---\n([\s]*)((?:\s|\S)*)[\n\s*]---',
+ flags=re.DOTALL|re.MULTILINE)
+
+def parse_yaml(string):
+ match = yamlPattern.match(string)
+ if not match:
+ return False
+
+ unindented = re.sub('^' + match.group(1), '',
+ match.group(2), flags=re.MULTILINE)
+
+ return yaml.safe_load(unindented)