-
-
Save RomanHargrave/4f2b4b80f39f9828ec5d1d0a470ecbfc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env raku | |
grammar ProguardMap { | |
token name { <[a..zA..Z_]> <[a..zA..Z_0..9]>* } | |
token full-name { <.name>+ % '.' } | |
token array { '[]' } | |
token type { <name=full-name> <array>? } | |
token space { <[\ \t]> } | |
token lb { <[\c[LF] \r \r\c[LF]]> } | |
token nl { [ <.space>* <.lb> ]+ } | |
token eol { <.nl> | $ } | |
rule meth { | |
<ret=type> <name> '(' ~ ')' <params=type>+ % ',' | |
} | |
rule field { | |
<type> <name> | |
} | |
rule class-mapping { | |
<from=full-name> '->' <to=full-name> | |
} | |
rule member-mapping { | |
[ <meth> | <field> ] '->' <name> | |
} | |
token block { | |
<class-mapping> ':' <.nl> # class mapping will always be followed by at least one member | |
[ <.space>+ <member-mapping> ]+ %% <.eol> | |
} | |
rule TOP { | |
[ <block> ]+ | |
} | |
} | |
sub MAIN(Str $f where *.IO.f) { | |
with ProguardMap.subparse('a.b.c -> d.e.f', :rule<class-mapping>) { | |
say .hash; | |
dd $_; | |
} | |
with ProguardMap.subparse('a.b c -> d', :rule<member-mapping>) { | |
say .hash; | |
dd $_; | |
} | |
with ProguardMap.subparse('a.b[] c -> d', :rule<member-mapping>) { | |
say .hash; | |
dd $_; | |
} | |
with ProguardMap.subparse('void a(b,c[]) -> d', :rule<member-mapping>) { | |
say .hash; | |
dd $_; | |
} | |
my $block = ProguardMap.subparse(q:to/BLOCK/, :token<block>); | |
left -> right: | |
a.b c -> d | |
x.y z -> a | |
a b(c,d) -> e | |
BLOCK | |
dd $block; | |
say $block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment