Enhance the directive detection

This commit is contained in:
Raoul Snyman 2021-07-30 11:31:31 -07:00
parent dc5eedb8f4
commit 61b1cda0f6
2 changed files with 6 additions and 9 deletions

View File

@ -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):

View File

@ -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'\[(.*?)\]')