Index: parse.py ================================================================== --- parse.py +++ parse.py @@ -10,11 +10,14 @@ "REST", "OCTAVE", "CHORD_TYPE", ) -t_BASENOTE = r"[A-Ga-g]" +t_ignore = " |" + +#t_BASENOTE = r"[A-Ga-g]" +t_BASENOTE = r"I?V?I*[^ ]" t_ACCIDENTAL = r"\^{1,2}|_{1,2}|=" t_REST = r"z" t_OCTAVE = r"'+|,+" t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7b5|6|b6|m6|mb6|46|maj9|9|add9|7b9|m9" @@ -27,16 +30,15 @@ return t def t_error(t): raise TypeError("Unknown text '%s'" % (t.value,)) -t_ignore = " |" - lex.lex() #lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") -s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD" +#s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD" +s = "I IV V VI I" #s = "GF_G,/2" lex.input(s) for tok in iter(lex.token, None): print repr(tok.type), repr(tok.value) @@ -50,38 +52,10 @@ self.octave = octave self.accidental = None def __repr__(self): return "Note %s %s %s" % (self.value, self.duration, self.octave) -#def p_element(p): -# "element : note_element" -# p[0] = p[1] -# -#def p_note_element(p): -# '''note_element : note_element note_stem -# | note_stem -# ''' -# p[0] = p[1] -# -#def p_note_stem(p): -# '''note_stem : note''' -# p[0] = p[1] -# -#def p_note(p): -# '''note : note_or_rest -# | note_or_rest NOTE_LENGTH -# ''' -# p[0] = p[1] -# -#def p_note_or_rest(p): -# '''note_or_rest : pitch -# | REST -# ''' -# p[0] = p[1] -# -#def p_pitch(p): - def p_pitch_list(p): '''score : score note ''' p[0] = p[1] + [p[2]]