main       = { SOI ~ model ~ EOI }
model      = { inputs? ~ tensor* }
inputs     = { "in" ~ "=" ~ "[" ~ name? ~ (DELIM ~ name)* ~ DELIM? ~ "]" }
tensor     = { name_ij ~ "{" ~ tensor_elmt? ~ (DELIM ~ tensor_elmt)* ~ DELIM? ~ "}" }
indices   = { "(" ~ indice ~ ("," ~ indice)* ~ ")" ~ ":" }
indice      = { integer ~ ( range_sep ~ integer )? }
tensor_elmt = { indices? ~ (assignment | expression) }
assignment = { name ~ "=" ~ expression }
expression = { term ~ (term_op ~ term)* }
term       = { factor ~ (factor_op ~ factor)* }
factor     = { sign? ~ ( call | real | integer | name_ij_index | name_ij | "(" ~ expression ~ ")" ) }
call       = { name ~ "(" ~ call_arg ~ ("," ~ call_arg )* ~ ")" }
call_arg   = { expression }
name_ij    = ${ name ~ ("_" ~ name)? }
name_ij_index = ${ name_ij ~ "[" ~ indice ~ "]" }
range_sep  = @{ ".." | ":" }
sign       = @{ ("-"|"+") }
term_op    = @{ "-"|"+" }
factor_op  = @{ "*"|"/" }
name       = @{ ( 'a'..'z' | 'A'..'Z' ) ~ ('a'..'z' | 'A'..'Z' | '0'..'9' )* }
integer    = @{ ('0'..'9')+ }
real       = @{ ('0'..'9')+ ~ ( "." ~ ('0'..'9')* )? ~ ( "e" ~ sign? ~ integer )? }
DELIM      = _{ "," }
WHITESPACE = _{ " " | NEWLINE | "\t" }
COMMENT    = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }


