Skip to content

Instantly share code, notes, and snippets.

@fridgei
Last active August 29, 2015 14:00
Show Gist options
  • Save fridgei/1e318a78eb2c1a664ce0 to your computer and use it in GitHub Desktop.
Save fridgei/1e318a78eb2c1a664ce0 to your computer and use it in GitHub Desktop.
\* PEG js grammar for graphite functions *\
start = EXPRS
TARGET = target:[^\(\), ]+ {
return {
'type': 'target',
'data': target.join(''),
'children': null
}
}
FUNCTION = name:FUNCTION_NAME '(' args:EXPRS ')' {
return {
'type': 'function',
'data': name,
'children': args
}
}
EXPRS =
expr:EXPR ',' exprs:EXPRS { return [expr].concat(exprs) } /
expr:EXPR { return expr }
EXPR = func:FUNCTION { return func } / target:TARGET { return target }
FUNCTION_NAME = func_name:[A-Za-z]+
{ return func_name.join('') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment