### a set of rules for parsing Captures in perl6 ### ??? is please answer ### XXX is please do ;) # ??? when capturing values that will be interpolated, # is a string the right representation? # ( e.g. $ = "%" ~ "hash" ~ "" ) # ??? any twigils possible in flattened pairs? # ??? any twigils possible in hash-access-for-named-args? # ??? is it possible to pull a key and a value out of a flattened pair # during the parse? if not, just leave $ and $ # blank? # XXX need a generalized subrule # should include different brace semantics # XXX need a generalized subrule # should include qq{*} and friends # XXX general pair handling should be moved to a separate grammar grammar Capture { # stand-in for bracketing constructs # XXX add more or get unicode character classes working token open_group { <[<({[]> } # should be Ps and < token close_group { <[>)}\]]> } # should be Pe and > # perl6 sigils in captures # ??? define context here, or later in the parse? token is_array { $ := <[@]> } token is_scalar { $ := <[$]> } token is_code { $ := <[&]> } token is_hash { $ := <[%]> } token sigil { | | | } token name { [ | _ ]+ [ | \d | _ ]+ } token value { } # the colon appears in a few different positions to indicate named-ness token is_named { <[:]> } # adverbial pair form of named arguments # :$what, :what('when'), :what($when) token adv_name := name; token adv_value := value; token is_negated { <[!]> } token adv_twigil { } token adverbial_pair { [ | ? | $ := [ ? ] ] : { $ := $ } : { $ := $ bar, 'foo' => bar, and 'foo', 'bar' # XXX same problem as bracketing characters: need character # classes and smart open/close behavior token open_quote { <['"]> } token close_quote { <['"]> } token fat_comma { =\> } token pair_constructor { | <[,]> } token pair_value { ',' )> } token bareword_key { } token quoted_key { } token complex_key { } token pair_key { [ | | | ] } # only args with bareword keys are parsed as named # ??? should this be turned into some sort of check on a general # pair match? rule bareword_pair { [ $ := ] [ $ := ] } rule anonymous_pair { [ $ := ] [ $ := ] } # flattened pair form of named arguments # *$pair token is_flattened { <[\[,\]]> } token flattened_pair { ? } # hash-access-for-named-args form of named arguments # %hash: goes to :a(%hash) # ??? what's a nice catchy less-hyphenated name for this construction? # XXX since we're going to match hashes a lot, this should be cleaned up # and factored out into a more general grammar token is_hash { <[%]> } token hashed_pair { : { $ := $ } : { $ := $ ~ $ ~ $ ~ $ ~ $ } } # generalized pairs token pair { [ | | | | ] } # integrating all forms of named arguments into one token token named_arg { | | | : $ := $ : $ := $ } token positional { ',' )> } rule capture { [ | | ]* } }