Skip to content

Instantly share code, notes, and snippets.

@charlieroberts
Last active September 24, 2017 18:37
Show Gist options
  • Save charlieroberts/67fa98fedce1fc6372b8bf6b7d9775c3 to your computer and use it in GitHub Desktop.
Save charlieroberts/67fa98fedce1fc6372b8bf6b7d9775c3 to your computer and use it in GitHub Desktop.
Start of a PEG for Tidal
/*
working towards a gibber-tidal integration, a la:
https://gist.github.com/charlieroberts/445f2fb1ce3555f04cffc334c2be0b42
test here: https://pegjs.org/online
for more info on pegs and music languages:
https://worldmaking.github.io/workshop_nime_2017/editor.html
currently turns [ 3/4 2(5,8) [0 1 2 3*2] ]
to:
[
{
"type": "binop",
"left": "3",
"op": "/",
"right": "4"
},
{
"type": "euclid",
"pulses": 5,
"slots": 8
},
[
"0",
"1",
"2",
{
"type": "binop",
"left": "3",
"op": "*",
"right": "2"
}
]
]
*/
term "term" = body:( binop / euclid / list / word ) _ {
return body
}
list "list" = ( "[" / "{" ) _
body:term* _ ( "]" / "}" ) { return body }
binop = left:word op:op right:word {
return { type:'binop', left, op, right }
}
word "word" = $[^ \[\] \{\} \t\n\r '*' '/' '+' '-']+
op = '*' / '/' / '+' / '-'
euclid = value:number '(' _ pulses:number ',' _ slots:number ')' {
return { type:'euclid', pulses, slots }
}
char = number / [a-zA-Z]
number = "-"? (([0-9]+ "." [0-9]*) / ("."? [0-9]+)) { return +text(); }
_ "whitespace" = [ \t\n\r ]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment