Browse Source

Code simplification

pull/112/head
Louis 9 years ago
parent
commit
124e11b20c
  1. 19
      patacrep/songs/chordpro/ast.py
  2. 2
      patacrep/songs/chordpro/syntax.py

19
patacrep/songs/chordpro/ast.py

@ -286,7 +286,6 @@ class EndOfLine(AST):
class Directive(AST): class Directive(AST):
"""A directive""" """A directive"""
inline = False
def __init__(self, keyword, argument=None): def __init__(self, keyword, argument=None):
super().__init__() super().__init__()
@ -304,20 +303,10 @@ class Directive(AST):
def __str__(self): def __str__(self):
return self.argument return self.argument
@classmethod @property
def create(cls, keyword, argument=None): def inline(self):
"""Create a :class:`Directive` or :class:`InlineDirective`. """Return `True` iff `self` is an inline directive."""
return self.keyword in INLINE_DIRECTIVES
Depending on the keyword.
"""
if keyword in INLINE_DIRECTIVES:
return InlineDirective(keyword, argument)
else:
return cls(keyword, argument)
class InlineDirective(Directive):
"""Directive displayed in the flow of the song"""
inline = True
class Define(Directive): class Define(Directive):
"""A chord definition. """A chord definition.

2
patacrep/songs/chordpro/syntax.py

@ -144,7 +144,7 @@ class ChordproParser(Parser):
self.song.add(define) self.song.add(define)
else: else:
directive = ast.Directive.create(keyword, argument) directive = ast.Directive(keyword, argument)
if directive.inline: if directive.inline:
symbols[0] = directive symbols[0] = directive
else: else:

Loading…
Cancel
Save