=pod Perl 6's grammar written as a Perl 6 regexs. A prerequisite for self hosting. =cut use v6-alpha; grammar Perl6::Grammar-0.0.1; # Top level structures token code { <-[{}]>* } # a section of code #regex block { \{ \} } # a block of code # pugs parsing problem? - 2005 Jul 31 token block { <[{]> <[}]> } # a block of code # subs and sub-like structures rule lexicalsub { # from A06 ? ? ? * } rule lexicalsub { # from A06 ? ? ? * } rule packagesub { # from A06 ? * } rule anonsub { ? * } # Pointy subs rule pointysub { # from A06 -\> } # Variables # From A06 regex sigil { <[$@%&]> <[*.?^]>? } # "What is that, swearing?" regex variable { [ \( \) ]? } # Bare subs # from A06 #rule baresub { # { .find_placeholders() } #} # Identifiers regex name_sec { <-[0..9:.]> <-[:]>* }; regex nameZZ { | [\:\: ]+ | [\:\: ]+}; ## What is the difference between an ident, a name and a subname ## A06 doesn't tell me even though it uses them. These are guesses ## until we are enlightened. regex subname { \*? }; regex identZZ { }; # Numbers # base 10 regex natural { [_* _*]* }; regex Int {[\+|\-]? }; regex decimal { [\. ? ]? | [\+|\-]? \. }; regex Rat { [ [e|E] ]? }; # base N regex binary { 0b <[01]>+ }; regex hex { 0x <[0..9a..fA..F]>+}; regex oct { 0o <[0..7]>+}; # any perl style number regex Num { Int | Rat | binary | hex | oct }; # these are defined in A06 # Siglets rule siglet { [ [<[,:]> ]* ]? } #rule paramlet { # [ ? ? * # require type # | ? * # or zone # | * # or varlet # | \[ \] # treat single array as an arg list # ] #} # comments appear to be poisonous - 2005 Jul 31 rule paramlet { [ ? ? * | ? * | * | \[ \] ] } rule varlet { [ \( \) ]? } # Defaults rule defval { \= } # Placeholders regex placeholder { \^ } # Formal parameter syntax #rule parameter { # [ ? ? * ? # | \[ \] # treat single array as an arg list # ] #} # comments appear to be poisonous - 2005 Jul 31 rule parameter { [ ? ? * ? | \[ \] ] } regex type { yada type } regex zone { yada zone } rule signature { [ [<[,:]> ]* ]? } # The sub form regex subintro { sub | method | submethod | regex | macro } regex lexscope { my | our } regex submodifer { multi } rule psignature { \( \) } rule psiglet { \( \) } rule scopedsubvar { ? & ? * } rule unscopedsubvar { & ? * } rule trait { is [\( \)]? | will | of | returns } regex traitparam { yada traitparam } regex closure { yada closure }