/parseproblem.p6 Secret
Created
May 10, 2019 12:26
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Grammar::Tracer; | |
| my $testprog = q:to/CONFPROG/; | |
| version = 1 | |
| entry profiler_static: | |
| profile |= sf.name eq "florble"; | |
| profile |= sf.name eq "blorb"; | |
| custom_var = (sf.name eq "blurb") and (frame.caller.name eq "blop") | |
| profile |= custom_var | |
| CONFPROG | |
| die "only support version 1" unless $testprog.lines.head ~~ m/^version \s+ "=" \s+ 1 \s* ";"? $/; | |
| grammar ConfProg { | |
| regex TOP { | |
| "version" \s* "=" \s* "1" \n | |
| <statement>+ %% <.eol> | |
| } | |
| regex eol { \s* ';' \n* | \s* \n+ | \s* \n* $$ } | |
| proto regex statement { * } | |
| regex statement:<var_update> { | |
| <variable> \s+ <update_op> \s+ <expression> | |
| } | |
| regex statement:<entrypoint> { | |
| 'entry' \s+ $<entrypoint>=[ | |
| | 'profiler_static' | |
| | 'profiler_dynamic' | |
| | 'spesh' | |
| | 'jit' | |
| ] \s* | |
| ":" | |
| } | |
| regex statement:<label> { | |
| <ident> \s* ':' | |
| } | |
| proto regex variable { * } | |
| regex variable:<custom> { | |
| '$' <.ident> | |
| } | |
| regex variable:<builtin> { | |
| <.ident> | |
| } | |
| proto regex update_op { * } | |
| regex update_op:<logical> { | |
| '|=' | '&=' | |
| } | |
| regex update_op:<assignment> { | |
| '=' | |
| } | |
| proto regex expression { * } | |
| proto regex one_expression { * } | |
| regex one_expression:<literal_number> { | |
| <[1..9]> '_'? <[0..9]>* % '_'? | |
| } | |
| regex one_expression:<literal_number_base16> { | |
| "0x" <[1..9a..fA..F]> '_'? <[0..9a..fA..F]>* % '_'? | |
| } | |
| regex one_expression:<literal_string> { | |
| | '"' [ <-["]> | \\ \" ]+ '"' | |
| | "'" [ <-[']> | \\ \' ]+ "'" | |
| } | |
| regex one_expression:<drilldown> { | |
| <variable> <postfixish>+ | |
| } | |
| regex one_expression:<variable> { | |
| <variable> | |
| } | |
| regex expression:<one> { | |
| <!before '('> <one_expression> | |
| } | |
| regex expression:<comparison> { | |
| <one_expression> \s* <compop> \s* <one_expression> | |
| } | |
| regex one_expression:<parenthesized> { | |
| '(' \s* <expression> \s* ')' | |
| } | |
| regex one_expression:<prefixed> { | |
| <prefixop> '(' \s* <expression> \s* ')' | |
| } | |
| proto regex postfixish { * } | |
| regex postfixish:<attribute> { | |
| '.' <.ident> | |
| } | |
| regex postfixish:<positional> { | |
| '.' "[" <.one_expression> "]" | |
| } | |
| regex compop { | |
| [ | |
| | "eq" | |
| | "ne" | |
| | '&&' | |
| | '||' | |
| | "and" | |
| | "or" | |
| ] | |
| } | |
| regex prefixop { | |
| [ | |
| | '!' | |
| ] | |
| } | |
| } | |
| ConfProg.parse($testprog).say; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://tio.run/##jVbdb9owEH/nr7hZtOZDS8tLpfFVTZW6t7Wa9gYMJY0BT8FO7dDByvqvs4sTEptAaR5K7nz3u7vf3bmJmYpudrvlBuoJ00ms5BwG8NxN5NXdw/f7xx8P3656NcDnhSnNpcDTjpGZSNQG0GHGI6amOvET/tQ1R7kStgPQM0/4SwbsGcgskiqIGOm9ZxSkRrnJ00oncjl98RVGbbhWK7Rqgi9CaMwUqr0nP8I8HKCYNA9DlZDmZF9jrRZyBkSKaAN6FcdSJUXBHQIrETGtS4q8iAumvQXzQ3h7g@XVr73xWLeBDIj57eDfFpAeuYU6klibY55LrOVOitljSvSryUGxOVvDz4fHXE4fkuORDGKQ/2IqY1EY9VPO2RIbMWzDxQX0PSajoTn@V7OgUQuvBoD2KAK0YGuksWgXby2o1/deWGEic98iBCK0XNjiqNtHOqerOER5aBWRqrmPHR8aOvqZxVTGuczWsUJascx90kfBzaDFkmOZFjg1amqQ6rbNYFTYpM8W6MGM0pPn4Qan54iBjpleVLS/eVLqJimPZfu6pNoGq6TID1jkUMXDtI1Zk7rUdra7sSe02oz9SbefTbhDVZ3ibGQRKkSXjsGKRwkXTlquVyWfoqPVhIojrFbOOW6nk9J2QFMOLwe0SpTl6uN4zIUZcdt7cJKhcqbslGwLKdj0uNWxc8yeJ0z50VSslgFTDjujjud9mQyBTuktStdGasGFUVSYfh94GviadW5sfHK9JnkQ3/NmXz3v3g1Wag@CfiCqThQXczsctoNQGEH/84hgHLwZxjAmMGmnesuKUJJZ0cKKplaoPx8@VDyKQvlHnLgo@rHUyYyvuV4M2@fhSsdjaEeuQssXsWw36H8K2EwqBrRBMRE31BmsJ7mMMaqWbl0HGGa9jW12B7Y@EOWwYgyD27Bgmv9lobMUDZpBHgakTXp2FvENSXcBc2Wa6gewK3tWNjLfsTJ6eYQbnuAgBiv3Pwf13rmxbG985wlmc3C7oDsZ4e54hw0gkyMzmjXE8h/Z086eiS0KZov08tJeDbrdOpuCnyeOs1SlOKkmsif8RCr0E614o//@c8LD0dCsUXykND3tb3q13e4/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment