From 124e11b20c74b2a165071c56315ccc585f3b3033 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 12 Oct 2015 17:10:29 +0200 Subject: [PATCH] Code simplification --- patacrep/songs/chordpro/ast.py | 19 ++++--------------- patacrep/songs/chordpro/syntax.py | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 9ee1a137..7b331ecd 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -286,7 +286,6 @@ class EndOfLine(AST): class Directive(AST): """A directive""" - inline = False def __init__(self, keyword, argument=None): super().__init__() @@ -304,20 +303,10 @@ class Directive(AST): def __str__(self): return self.argument - @classmethod - def create(cls, keyword, argument=None): - """Create a :class:`Directive` or :class:`InlineDirective`. - - 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 + @property + def inline(self): + """Return `True` iff `self` is an inline directive.""" + return self.keyword in INLINE_DIRECTIVES class Define(Directive): """A chord definition. diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 8837f501..c86e7ef4 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -144,7 +144,7 @@ class ChordproParser(Parser): self.song.add(define) else: - directive = ast.Directive.create(keyword, argument) + directive = ast.Directive(keyword, argument) if directive.inline: symbols[0] = directive else: