Overview
Comment: | Now parses note duration |
---|---|
Timelines: | family | ancestors | descendants | both | ply |
Files: | files | file ages | folders |
SHA1: |
dc8bbfb68e7312a4ea7b9fefad92db90 |
User & Date: | spiffytech@gmail.com on 2010-11-16 08:36:44 |
Other Links: | branch diff | manifest | tags |
Context
2010-11-16
| ||
08:37 | Added default accidental value of None to Notes check-in: c2f128e728 user: spiffytech@gmail.com tags: ply | |
08:36 | Now parses note duration check-in: dc8bbfb68e user: spiffytech@gmail.com tags: ply | |
08:29 | Now parses notes, accidentals, and octaves check-in: bd456efa03 user: spiffytech@gmail.com tags: ply | |
Changes
Modified parse.py from [b5bfbaf68d] to [ba81961e5a].
︙ | ︙ | |||
31 32 33 34 35 36 37 | 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" | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 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 = "GF_G,/2" lex.input(s) for tok in iter(lex.token, None): print repr(tok.type), repr(tok.value) # Parse (yacc) |
︙ | ︙ | |||
76 77 78 79 80 81 82 | # | REST # ''' # p[0] = p[1] # #def p_pitch(p): def p_pitch_list(p): | | | | | | > | > > > > < < < < < > > > > > | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | # | REST # ''' # p[0] = p[1] # #def p_pitch(p): def p_pitch_list(p): '''score : score note ''' p[0] = p[1] + [p[2]] def p_score(p): '''score : note ''' p[0] = [p[1]] def p_note(p): '''note : pitch ''' p[0] = p[1] def p_note_length(p): ''' note : note NOTE_LENGTH ''' new_note = p[1] new_note.duration = p[2] p[0] = new_note def p_accidental(p): '''pitch : ACCIDENTAL pitch ''' p[2].accidental = p[1] p[0] = p[2] def p_octave(p): '''pitch : pitch OCTAVE ''' count = len(p[2]) increment_or_decrement = 1 if p[2][0] == "," else -1 octave = 8 + (count * increment_or_decrement) p[1].octave = octave p[0] = p[1] def p_pitch(p): '''pitch : BASENOTE ''' p[0] = Note(p[1]) def p_error(p): print "Syntax error at '%s' of element type %s" % (p.value, p.type) yacc.yacc() #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") print yacc.parse(s) |