test262/tools/lint/lib/frontmatter.py
jugglinmike 74954bfa91 Introduce automated validation for test format (#994)
This script is intended to identify common test file formatting errors
prior to their acceptance into the project. It is designed to support
future extensions for additional validation rules.
2017-05-01 12:04:05 -04:00

17 lines
465 B
Python

import re
import yaml
def parse(src):
'''Parse the YAML-formatted metadata found in a given string of source
code. Tolerate missing or invalid metadata; those conditions are handled by
a dedicated "Check" instance.'''
match = re.search(r'/\*---(.*)---\*/', src, re.DOTALL)
if not match:
return None
try:
return yaml.load(match.group(1))
except (yaml.scanner.ScannerError, yaml.parser.ParserError):
return None