diff --git a/src/chordpro/base.py b/src/chordpro/base.py index f925f33..96ffc6f 100644 --- a/src/chordpro/base.py +++ b/src/chordpro/base.py @@ -30,18 +30,13 @@ class Directive(object): return None for known_directive in KNOWN_DIRECTIVES: if match.group(1) in known_directive: - self.directive = match.group(1) + self.directive = known_directive[0] self.info = match.group(2) @staticmethod def is_directive(line): """Check if a line in a file contains a directive""" - match = DIRECTIVE.match(line) - if match: - for known_directive in KNOWN_DIRECTIVES: - if match.group(1) in known_directive: - return True - return False + return DIRECTIVE.match(line) is not None class Syllable(object): diff --git a/src/chordpro/constants.py b/src/chordpro/constants.py index 633a649..3916a4f 100644 --- a/src/chordpro/constants.py +++ b/src/chordpro/constants.py @@ -15,7 +15,8 @@ KNOWN_DIRECTIVES = [ ('tempo',), ('duration',), ('capo',), - ('meta',) + ('meta',), + ('comment', 'c') ] KNOWN_VERSE_TYPES = [ 'verse', @@ -29,9 +30,10 @@ GERMAN_NOTES = '[CDEFGAH]' NEOLATIN_NOTES = '(Do|Re|Mi|Fa|Sol|La|Si)' CHORD_SUFFIXES = '(b|bb)?(#)?(m|maj7|maj|min7|min|sus)?(1|2|3|4|5|6|7|8|9)?' SLIM_CHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\' -DIRECTIVE = re.compile(r'\{(.*?): *(.*?)\}') +DIRECTIVE = re.compile(r'\{(' + '|'.join([d for t in KNOWN_DIRECTIVES for d in t]) + r'): *(.*?)\}') START_OF = re.compile(r'\{start_of_(' + '|'.join(KNOWN_VERSE_TYPES) + r')(: *(.*?))?\}') END_OF = re.compile(r'\{end_of_(' + '|'.join(KNOWN_VERSE_TYPES) + r')\}') CHORUS_MARKER = re.compile(r'\{chorus(: *(.*?))?\}') +VERSE_MARKER = re.compile(r'\{verse: *(.*?)\}') CHORD_WORD = re.compile(r'(.*?)\[(.*?)\]') CHORD = re.compile(r'\[(.*?)\]')