# Tokenizer
DIGIT = [0-9]
ID = [a-zA-Z_]
CHAR = ... \ '"'
PITCH = 'c' | 'd' | 'e' | 'f' | 'g' | 'a' | 'h'
PITCH_MODIFIER = 'b' | '#'

<integer> ::= '-' DIGIT+ | DIGIT+
<string> ::= '"' CHAR* '"'
<note> ::= '@' PITCH PITCH_MODIFIER? DIGIT? [':' DIGIT+ 'd'?]?
<identifier> ::= ID [ID|DIGIT]*
<bool> ::= 'true' | 'false'
<type> ::= 'integer' | 'string' | 'note' | 'list' | 'map' | 'sound' | 'bool' | 'void'

# Parser
<expr> ::= <integer> <access> | <integer>
<expr> ::= <string> <access> | <string>
<expr> ::= <note> <access> | <note>
<expr> ::= <identifier> <access> | <identifier> '=' <expr> | <functionCall> | <identifier>
<expr> ::= <list> <access> | <list>
<expr> ::= <map> <access> | <map>
<expr> ::= <bool> <access> | <bool>
<expr> ::= <expr> '.' <identifier> | <expr> '.' <functionCall>
<expr> ::= <asteriskExpr> '*' <expr>
<asteriskExpr> ::= <integer> | <string> | <note> | <identifier> | <list> | <map>

<functionCall> ::= <identifier> <arglist>

<list> ::= '[' ']' | '[' <expr> <listTail>
<listTail> ::= <expr> ', ' <listTail> | ']'

<arglist> ::= '(' ')' | '(' <expr> <arglistTail>
<arglistTail> ::= <expr> ', ' <arglistTail> | ')'

<argdeflist> ::= '(' ')' | '(' <typedVariable> <argdeflist>
<argdeflist> ::= <typedVariable> ', ' <argdeflist> | ')'

<argdef> = <type> <typeSpecifier>? <identifier> '...'? | <typeSpecifier> <identifier> '...'?

<typedVariable> ::= <type> <typeSpecifier>? <identifier>

<map> ::= '{' '}' | '{' <mapEntry> <mapTail>
<mapTail> ::= <mapEntry> ', ' <mapTail> | ']'
<mapEntry> ::= <integer> '->' <expr> | <string> '->' <expr> | <note> '->' <expr>

<typeSpecifier> ::= '<' '>' | '<' <typeSpecifierItem> <typeSpecifierTail>
<typeSpecifierTail> ::= <typeSpecifierItem> ', ' <typeSpecifierTail> | '>'
<typeSpecifierItem> ::= <type> <typeSpecifier>*

<block> ::= '{' <stmt>* '}'

<stmt> ::= <block>
<stmt> ::= 'return' <expr>
<stmt> ::= <expr>

<functionDefinition> ::= 'function' <identifier> <list> <block>

<extend> ::= 'extend' <type> 'as' <identifier> '{' <functionDefinition> '}'

<import> ::= 'import' <string> | 'import' <type> 'from' <string> 'as' <identifier>

<programItem> ::= <stmt> | <expr> | <import> | <functionDefinition> | <extend>

<program> ::= <programItem>*

