Created
January 7, 2017 00:29
-
-
Save anonymous/710b65b90fbc8244d39cb6086d151fdc 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; | |
use Grammar::Tracer; | |
grammar NVL { | |
rule TOP { [<main>]* <textfin> } | |
rule main { <text> <nvl> } | |
regex text {:s .+? } | |
rule nvl {:i 'nvl' '(' <expr1> ',' <expr2> ')'} | |
regex expr1 { .+? } | |
regex expr2 { .+? } | |
regex textfin { .+ } | |
} | |
class Nvl { | |
method TOP ($/) { my $result ~= make $_.made for $<main>; | |
make $result ~= $<textfin>; } | |
method main ($/) { make $<text> ~ $<nvl>.made ; } | |
method nvl ($/) { make "coalesce("~$<expr1>~','~$<expr2> ~ ")" ;} | |
} | |
grammar TEST { | |
rule TOP { <sql> } | |
rule sql { \s* <sqlstart> <sqltext> <sqlend> \s* } | |
token sqlstart {'EXEC SQL'} | |
token sqlend {'END-EXEC'} | |
regex sqltext { .+? <before 'END-EXEC'> } | |
} | |
class Test { | |
method TOP ($/) { my $sql=$<sql><sqltext>.made; | |
my $act = Nvl.new; | |
my $result= NVL.parse($sql, :act).made ; | |
} | |
method sql ($/) { $/.make: (~$/) } | |
method sqltext ($/) { $/.make: (~$/) } | |
} | |
my $cbl = "EXEC SQL select nvl(toto,titi) from dual END-EXEC"; | |
say TEST.parse($cbl, actions => Test).made; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment