Closed amiika closed 2 years ago
Tried out treetop for parsing the syntax, looks promising:
Treetop.load_from_string("
grammar Ziffers
rule line
(repeat / s / bar / chord / group / parens / control)*
{
def value
elements.collect {|v|
v.value }
end
}
end
rule chord
s [0-9]+ s
{
def value
text_value
end
}
end
rule group
[\-a-z0-9]+
{
def value
text_value
end
}
end
rule parens
'(' line ')'
{
def value
line.elements.collect { |v|
v.value
}
end
}
end
rule control
[A-Z] [0-9\.0-9]*
{
def value
text_value
end
}
end
rule repeat
'|:' line ':' num '|'
{
def value
text_value
end
}
end
rule num
[0-9]? {
def value
text_value
end }
end
rule s
[\s]
{
def value
''
end
}
end
rule bar
'|' {
def value
'|'
end
}
end
end
")
Done in Ziffers 2
Current string parsing function zparse is an accumulated piece of steaming spaghetti and meatballs. Refactor parsing function to produce plain parsed hash array and create separate functions for sliding, chord parsing etc etc.
Plain hash arrays (without parsed notes and chords) would work better with loops as they could be resolved on the fly.