Skip to content

Instantly share code, notes, and snippets.

@chriskiefer
Created February 5, 2020 16:49
Show Gist options
  • Save chriskiefer/edfa6ba1cbce2529b6dd9c559bac897f to your computer and use it in GitHub Desktop.
Save chriskiefer/edfa6ba1cbce2529b6dd9c559bac897f to your computer and use it in GitHub Desktop.
@{%
const lexer = moo.compile({
click: /click/,
convol1: /convol1/,
heart: /heart/,
separator: />/,
number: /-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\b/,
ws: {match: /\s+/, lineBreaks: true},
});
%}
# Pass your lexer object using the @lexer option
@lexer lexer
main -> _ Statement _ {% d => ({ "@lang" : d[1] }) %}
Statement ->
SampleName %separator %number
{% d => [{"@sigOut": { "@spawn": sema.synth('loop',[sema.num(d[2].value),sema.str(d[0])]) }}] %}
SampleName -> (%click | %convol1 | %heart) {% d => d[0][0].value %}
# Whitespace
_ -> wschar:* {% function(d) {return null;} %}
__ -> wschar:+ {% function(d) {return null;} %}
wschar -> %ws {% id %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment