tests/auto/qml/ecmascripttests/test262/tools/lint/lib/frontmatter.py
raw| 1 | import re |
| 2 | import yaml |
| 3 | |
| 4 | def parse(src): |
| 5 | '''Parse the YAML-formatted metadata found in a given string of source |
| 6 | code. Tolerate missing or invalid metadata; those conditions are handled by |
| 7 | a dedicated "Check" instance.''' |
| 8 | |
| 9 | match = re.search(r'/\*---(.*)---\*/', src, re.DOTALL) |
| 10 | if not match: |
| 11 | return None |
| 12 | |
| 13 | try: |
| 14 | return yaml.load(match.group(1)) |
| 15 | except (yaml.scanner.ScannerError, yaml.parser.ParserError): |
| 16 | return None |