Browse Source

Replaced temporary variable names with correct ones

pull/79/head
Louis 9 years ago
parent
commit
87532f784e
  1. 2
      patacrep/songs/__init__.py
  2. 34
      patacrep/songs/chordpro/ast.py
  3. 18
      patacrep/songs/chordpro/data/latex/content_chord.tex
  4. 20
      patacrep/songs/chordpro/lexer.py
  5. 26
      patacrep/songs/chordpro/syntax.py

2
patacrep/songs/__init__.py

@ -81,7 +81,7 @@ class Song(Content):
# Version format of cached song. Increment this number if we update
# information stored in cache.
CACHE_VERSION = 1
CACHE_VERSION = 2
# List of attributes to cache
cached_attributes = [

34
patacrep/songs/chordpro/ast.py

@ -122,27 +122,27 @@ class Chord(LineElement):
_template = "chord"
def __init__(self, todo_note, todo_diesebemol, todo_mdimmajsus, todo_chiffre, todo_chordbis):
def __init__(self, key, alteration, modifier, add_note, bass):
super().__init__()
self.todo_note = todo_note
self.todo_diesebemol = todo_diesebemol
self.todo_mdimmajsus = todo_mdimmajsus
self.todo_chiffre = todo_chiffre
self.todo_chordbis = todo_chordbis
self.key = key
self.alteration = alteration
self.modifier = modifier
self.add_note = add_note
self.bass = bass
def __str__(self):
text = ""
text += self.todo_note
if self.todo_diesebemol is not None:
text += self.todo_diesebemol
if self.todo_mdimmajsus is not None:
text += self.todo_mdimmajsus
if self.todo_chiffre is not None:
text += str(self.todo_chiffre)
if self.todo_chordbis is not None:
text += "/" + self.todo_chordbis[0]
if self.todo_chordbis[1] is not None:
text += self.todo_chordbis[1]
text += self.key
if self.alteration is not None:
text += self.alteration
if self.modifier is not None:
text += self.modifier
if self.add_note is not None:
text += str(self.add_note)
if self.bass is not None:
text += "/" + self.bass[0]
if self.bass[1] is not None:
text += self.bass[1]
return "[{}]".format(text)
class Verse(AST):

18
patacrep/songs/chordpro/data/latex/content_chord.tex

@ -1,13 +1,13 @@
\[
((- content.todo_note -))
(* if content.todo_diesebemol == '#' *)#(* endif -*)
(* if content.todo_diesebemol == 'b' *)&(* endif -*)
(* if content.todo_mdimmajsus *)((content.todo_mdimmajsus))(* endif -*)
(* if content.todo_chiffre *)((content.todo_chiffre))(* endif -*)
(* if content.todo_chordbis -*)
((- content.key -))
(* if content.alteration == '#' *)#(* endif -*)
(* if content.alteration == 'b' *)&(* endif -*)
(* if content.modifier *)((content.modifier))(* endif -*)
(* if content.add_note *)((content.add_note))(* endif -*)
(* if content.bass -*)
/
((- content.todo_chordbis[0] -))
(* if content.todo_chordbis[1] == '#' *)#(* endif -*)
(* if content.todo_chordbis[1] == 'b' *)&(* endif -*)
((- content.bass[0] -))
(* if content.bass[1] == '#' *)#(* endif -*)
(* if content.bass[1] == 'b' *)&(* endif -*)
(* endif -*)
]

20
patacrep/songs/chordpro/lexer.py

@ -9,11 +9,11 @@ LOGGER = logging.getLogger()
tokens = (
'LBRACE',
'RBRACE',
'TODONOTE',
'TODODIESEBEMOL',
'TODOMDIMMAJSUS',
'TODOCHIFFRE',
'TODOSLASH',
'KEY',
'ALTERATION',
'MODIFIER',
'ADDNOTE',
'SLASH',
'NEWLINE',
'COLON',
'WORD',
@ -43,11 +43,11 @@ class ChordProLexer:
t_SPACE = r'[ \t]+'
t_chord_TODONOTE = r'[A-G]'
t_chord_TODODIESEBEMOL = r'[#b]'
t_chord_TODOMDIMMAJSUS = r'(maj|dim|m|sus)'
t_chord_TODOCHIFFRE = r'[2-9]'
t_chord_TODOSLASH = r'/'
t_chord_KEY = r'[A-G]'
t_chord_ALTERATION = r'[#b]'
t_chord_MODIFIER = r'(maj|dim|m|sus)'
t_chord_ADDNOTE = r'[2-9]'
t_chord_SLASH = r'/'
t_directive_SPACE = r'[ \t]+'
t_directive_KEYWORD = r'[a-zA-Z_]+'

26
patacrep/songs/chordpro/syntax.py

@ -108,7 +108,7 @@ class ChordproParser(Parser):
@staticmethod
def p_chord(symbols):
"""chord : TODONOTE chordtododiesebemol chordtodomdimmajsus chordtodochiffre chordtodoautre"""
"""chord : KEY chordalteration chordmodifier chordaddnote chordbass"""
symbols[0] = ast.Chord(
symbols[1],
symbols[2],
@ -118,23 +118,23 @@ class ChordproParser(Parser):
)
@staticmethod
def p_chordtododiesebemol(symbols):
"""chordtododiesebemol : TODODIESEBEMOL
| empty
def p_chordalteration(symbols):
"""chordalteration : ALTERATION
| empty
"""
symbols[0] = symbols[1]
@staticmethod
def p_chordtodomdimmajsus(symbols):
"""chordtodomdimmajsus : TODOMDIMMAJSUS
| empty
def p_chordmodifier(symbols):
"""chordmodifier : MODIFIER
| empty
"""
symbols[0] = symbols[1]
@staticmethod
def p_chordtodochiffre(symbols):
"""chordtodochiffre : TODOCHIFFRE
| empty
def p_chordaddnote(symbols):
"""chordaddnote : ADDNOTE
| empty
"""
if symbols[1] is None:
symbols[0] = symbols[1]
@ -142,9 +142,9 @@ class ChordproParser(Parser):
symbols[0] = int(symbols[1])
@staticmethod
def p_chordtodoautre(symbols):
"""chordtodoautre : TODOSLASH TODONOTE chordtododiesebemol
| empty
def p_chordbass(symbols):
"""chordbass : SLASH KEY chordalteration
| empty
"""
if len(symbols) == 2:
symbols[0] = None

Loading…
Cancel
Save