Differences From Artifact [e9eede661e4e6d3a]:
- Executable file
parse.py
- 2011-09-13 20:08:17 - part of checkin [029fd48614] on branch feature/abc - Added a name parameter to the Tree class that will prove helpful in generating the score (user: brian) [annotate]
To Artifact [8755d61a44de1205]:
- Executable file
parse.py
- 2011-09-15 15:28:03 - part of checkin [33ddc6fee4] on branch feature/abc - Got the program to run through again. Now without the roman numerals (user: brian) [annotate]
40 "CHORD_TYPE", 40 "CHORD_TYPE",
41 "QUOTE", 41 "QUOTE",
42 "NODE", 42 "NODE",
43 ) 43 )
44 44
45 t_ignore = " |" 45 t_ignore = " |"
46 46
47 #t_BASENOTE = r"[A-Ga-g]" | 47 t_BASENOTE = r"[A-Ga-g]"
48 # t_BASENOTE = r"I+V?|VI*|i+v?|vi*" 48 # t_BASENOTE = r"I+V?|VI*|i+v?|vi*"
49 t_BASENOTE = r"[A-Ga-g]" <
50 t_ACCIDENTAL = r"\^{1,2}|_{1,2}|=" 49 t_ACCIDENTAL = r"\^{1,2}|_{1,2}|="
51 t_REST = r"z" 50 t_REST = r"z"
52 t_OCTAVE = r"'+|,+" 51 t_OCTAVE = r"'+|,+"
53 t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7 52 t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7
54 t_QUOTE = '"' 53 t_QUOTE = '"'
55 t_NODE = r"([a-zA-Z0-9_-]+)" | 54 t_NODE = r"\([a-zA-Z0-9_-]+\)"
56 55
57 def t_NOTE_LENGTH(t): 56 def t_NOTE_LENGTH(t):
58 r"/?\d+" 57 r"/?\d+"
59 multiplier = float(t.value.strip("/")) 58 multiplier = float(t.value.strip("/"))
60 if t.value.startswith("/"): 59 if t.value.startswith("/"):
61 multiplier = 1/multiplier 60 multiplier = 1/multiplier
62 t.value = multiplier 61 t.value = multiplier
................................................................................................................................................................................
151 ''' rest : REST 150 ''' rest : REST
152 | REST NOTE_LENGTH 151 | REST NOTE_LENGTH
153 ''' 152 '''
154 p[0] = Rest() 153 p[0] = Rest()
155 if len(p) > 2: 154 if len(p) > 2:
156 p[0].duration = p[2] 155 p[0].duration = p[2]
157 156
158 def node(p): | 157 def p_node(p):
159 '''node: NODE | 158 '''node : NODE
160 ''' 159 '''
161 p[0] = tree.Tree(node.strip("(").strip(")")) | 160 p[0] = tree.Tree(p[1].strip("(").strip(")"))
162 161
163 162
164 def p_error(p): 163 def p_error(p):
> 164 print p
165 raise Exception("Syntax error at '%s' of element type %s" % (p.value, p. 165 raise Exception("Syntax error at '%s' of element type %s" % (p.value, p.
166 166
167 yacc.yacc() 167 yacc.yacc()
168 168
169 #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 169 #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD")
170 return yacc.parse(score) 170 return yacc.parse(score)