Differences From Artifact [09e3498be39b61fc]:
- Executable file
parse.py
- 2010-11-16 08:37:56 - part of checkin [c2f128e728] on branch ply - Added default accidental value of None to Notes (user: spiffytech@gmail.com) [annotate]
To Artifact [911b321ada6f1434]:
- Executable file
parse.py
- 2010-11-16 15:57:26 - part of checkin [32e6229eaa] on branch ply - Now parses roman numerals I-VII instead of notes (user: spiffytech@gmail.com) [annotate]
8 "BASENOTE", 8 "BASENOTE",
9 "ACCIDENTAL", 9 "ACCIDENTAL",
10 "REST", 10 "REST",
11 "OCTAVE", 11 "OCTAVE",
12 "CHORD_TYPE", 12 "CHORD_TYPE",
13 ) 13 )
14 14
> 15 t_ignore = " |"
> 16
15 t_BASENOTE = r"[A-Ga-g]" | 17 #t_BASENOTE = r"[A-Ga-g]"
> 18 t_BASENOTE = r"I?V?I*[^ ]"
16 t_ACCIDENTAL = r"\^{1,2}|_{1,2}|=" 19 t_ACCIDENTAL = r"\^{1,2}|_{1,2}|="
17 t_REST = r"z" 20 t_REST = r"z"
18 t_OCTAVE = r"'+|,+" 21 t_OCTAVE = r"'+|,+"
19 t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7b5|6 22 t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7b5|6
20 23
21 def t_NOTE_LENGTH(t): 24 def t_NOTE_LENGTH(t):
22 r"/?\d+" 25 r"/?\d+"
................................................................................................................................................................................
25 multiplier = 1/multiplier 28 multiplier = 1/multiplier
26 t.value = multiplier 29 t.value = multiplier
27 return t 30 return t
28 31
29 def t_error(t): 32 def t_error(t):
30 raise TypeError("Unknown text '%s'" % (t.value,)) 33 raise TypeError("Unknown text '%s'" % (t.value,))
31 34
32 t_ignore = " |" <
33 <
34 lex.lex() 35 lex.lex()
35 36
36 #lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 37 #lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD")
37 s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD" | 38 #s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD"
> 39 s = "I IV V VI I"
38 #s = "GF_G,/2" 40 #s = "GF_G,/2"
39 lex.input(s) 41 lex.input(s)
40 for tok in iter(lex.token, None): 42 for tok in iter(lex.token, None):
41 print repr(tok.type), repr(tok.value) 43 print repr(tok.type), repr(tok.value)
42 44
43 45
44 # Parse (yacc) 46 # Parse (yacc)
................................................................................................................................................................................
48 self.value = value 50 self.value = value
49 self.duration = duration 51 self.duration = duration
50 self.octave = octave 52 self.octave = octave
51 self.accidental = None 53 self.accidental = None
52 def __repr__(self): 54 def __repr__(self):
53 return "Note %s %s %s" % (self.value, self.duration, self.octave) 55 return "Note %s %s %s" % (self.value, self.duration, self.octave)
54 56
55 #def p_element(p): <
56 # "element : note_element" <
57 # p[0] = p[1] <
58 # <
59 #def p_note_element(p): <
60 # '''note_element : note_element note_stem <
61 # | note_stem <
62 # ''' <
63 # p[0] = p[1] <
64 # <
65 #def p_note_stem(p): <
66 # '''note_stem : note''' <
67 # p[0] = p[1] <
68 # <
69 #def p_note(p): <
70 # '''note : note_or_rest <
71 # | note_or_rest NOTE_LENGTH <
72 # ''' <
73 # p[0] = p[1] <
74 # <
75 #def p_note_or_rest(p): <
76 # '''note_or_rest : pitch <
77 # | REST <
78 # ''' <
79 # p[0] = p[1] <
80 # <
81 #def p_pitch(p): <
82 <
83 def p_pitch_list(p): 57 def p_pitch_list(p):
84 '''score : score note 58 '''score : score note
85 ''' 59 '''
86 p[0] = p[1] + [p[2]] 60 p[0] = p[1] + [p[2]]
87 61
88 def p_score(p): 62 def p_score(p):
89 '''score : note 63 '''score : note