parrotcode: Untitled | |
Contents | Language Implementations | ChitChat |
grammar ChitChat::Grammar is PCT::Grammar;
token TOP { <ws> [ | <exprs> | <methods> | '!' ]+ <ws> [ $ || <panic: 'Syntax error'> ] {*} }
token whitespace { \h | \v | <comment> }
token ws { <whitespace>* }
token comment { '"' <-["]>* '"' }
rule methods { '!' <id> 'class'? 'methodsFor:' <string> '!' [<method> '!']? '!' }
rule method { <message> <pragma>? <temps>? <exprs> }
token message { <id> | <binsel> <.ws> <id> | [<keysel> <.ws> <id>]+ }
token pragma { '<' <keymsg> '>' }
rule temps { '|' [<id> ]* '|' }
token unit { | <id> {*} #= id | <literal> {*} #= literal | <block> {*} #= block | <arrayconstructor> {*} #= arrayconstructor | '(' <expr> ')' {*} #= expr }
rule unaryexpr { <unit> [<!keysel><id> ]+ {*} }
token primary { <!unaryexpr> <unit> {*} | <unaryexpr> {*} }
rule exprs { [ | <expr> [ '.' <expr>]* ['.' '^' <expr>]? '.'? | '^' <expr> '.'? ] {*} }
rule expr { [<id> [':='|'_']]* <expr2> {*} }
rule expr2 {[ <msgexpr> [ ';' <cascade> ]* | <primary> ] {*} }
token msgexpr { | <keyexpr> {*} #= keyexpr | <binexpr> {*} #= binexpr | <unaryexpr> {*} #= unaryexpr }
token cascade { <id> | <binmsg> | <keymsg> }
rule binexpr { <primary> <binmsg> [<binmsg> ]* {*} }
rule binmsg { <binsel> <primary> }
token binsel { <binchar>**{1..2} }
rule keyexpr { <keyexpr2> <keymsg> {*} }
token keyexpr2 { <!binexpr> <primary> {*} | <binexpr> {*} }
rule keymsg { [<keysel> <keyexpr2> ]+ {*} }
token keysel { <id> ':' }
rule block { '[' [[':' <id>]* '|']? <temps>? <exprs> ']' }
token arrayconstructor { '{' <exprs> '}' }
token literal { | <number> {*} #= number | <string> {*} #= string | <charconst> {*} #= charconst | <symconst> {*} #= symconst | <arrayconst> {*} #= arrayconst | <binding> {*} #= binding | <eval> {*} #= eval }
token arrayconst { '#' <array> | '#' <bytearray> }
token bytearray { '[' <number>* ']' }
rule array { '(' [ <literal> | <array> | <bytearray> | <arraysym> ]* ')' }
token number { [<.digit>+ 'r']? '-'? <.alnum>+ ['.' <.alnum>+]? [<exp> '-'? <dig>+]? }
token string { \' $<text>:=<-[']>* \' {*} }
token charconst { '$' . }
token symconst { '#'<symbol> | '#'<string> }
token arraysym { [<id> | ':']* }
token exp { <[deqs]> }
token binding { '#{' [<id> '.']* <id> '}' }
token symbol { <id> | <binsel> | <keysel>**{1..2} }
rule eval { '##(' <temps>? <exprs> ')' }
token id { <.alpha> [ <.alpha> | <.digit> ]* }
token binchar { <[+\-*/~,<>=&´?\\%]> }
|