Created
January 31, 2017 23:01
-
-
Save anonymous/27c7c108022c58e7bb6bef1c491a5064 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
#!/opt/rakudo-star-2016.10/bin/perl6 | |
use v6; | |
############################################################################################# | |
# The result of this perl6 program depends on the usage of "use Grammar::Tracer;" instruction. | |
# | |
# If "use Grammar::Tracer;" is active the program display : | |
# | |
#「;DECODE(CODUO,'C',UFO_IDE,'')」 | |
# main => 「;DECODE(CODUO,'C',UFO_IDE,'')」 | |
# text => 「;」 | |
# decode => 「DECODE(CODUO,'C',UFO_IDE,'')」 | |
# decodeinstr => 「DECODE」 | |
# paraIn => 「(」 | |
# val => 「CODUO」 | |
# expr => 「CODUO」 | |
# mot1 => 「CODUO」 | |
# whenthen => 「,'C',UFO_IDE」 | |
# comma => 「,」 | |
# when => 「'C'」 | |
# expr => 「'C'」 | |
# mot1 => 「'」 | |
# mot1 => 「C」 | |
# mot1 => 「'」 | |
# comma => 「,」 | |
# then => 「UFO_IDE」 | |
# expr => 「UFO_IDE」 | |
# mot1 => 「UFO_IDE」 | |
# comma => 「,」 | |
# else => 「''」 | |
# expr => 「''」 | |
# mot1 => 「'」 | |
# mot1 => 「'」 | |
# paraOut => 「)」 | |
# | |
# If "use Grammar::Tracer;" is not active the program display | |
# | |
#「;DECODE(CODUO,'C',UFO_IDE,'')」 | |
# textfin => 「;DECODE(CODUO,'C',UFO_IDE,'')」 | |
# | |
# I'm not sure to well understand why and not sure it's a "normal" behaviour ... | |
############################################################################################# | |
use Grammar::Tracer; | |
grammar DECODE { | |
rule TOPDECODE { [<main>]* [<textfin>]? } | |
rule main { <text> <decode> } | |
rule decode {:i <decodeinstr> <paraIn> <val> <whenthen>+ [<comma> <else>]? <paraOut> } | |
regex decodeinstr {:i 'decode'\s* } | |
regex val {:s <decode> | |
|<expr> } | |
regex whenthen {:i <comma> <when> <comma> <then> } | |
regex when {:s <decode> | |
| <expr> } | |
regex then {:s <decode> | |
|<expr> } | |
regex else {:s <decode> | |
|<expr> } | |
regex text {:s .+? } | |
regex textfin {:s .+ } | |
regex comma {\s*','\s* } | |
regex paraIn {\s*'('\s*} | |
regex paraOut {\s*')'\s*} | |
token ws { <!ww> } | |
regex expr {:s {}<mot1>* | |
#regex expr {:s <mot1>* | |
| [<mot1><paraIn><mot>*<paraOut>]* | |
| [<paraIn><mot>*<paraOut>]* | |
} | |
rule mot { <-[()]>+? } | |
rule mot1 { <-[(),]>+? } | |
} | |
my $cbl = "\;DECODE(CODUO,'C',UFO_IDE,'')" ; | |
say DECODE.parse($cbl, rule => 'TOPDECODE'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment