Skip to content

Instantly share code, notes, and snippets.

Created January 13, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fa686cee87c4b1e5f675275f5d9116a5 to your computer and use it in GitHub Desktop.
Save anonymous/fa686cee87c4b1e5f675275f5d9116a5 to your computer and use it in GitHub Desktop.
use v6;
#use Grammar::Tracer;
# Question is that the parse on the following grammar NVL works fine when parsing expression
# "select nvl(toto,nvl(titi,tata) ) from dual ";
# but it doesn't recognize nvl when parsing this expressioni ( difference is the simplequote) :
# "select nvl(toto,nvl(titi,'tata') ) from dual ";
# I don't understand why simple quote are not part of the regex <expr2txt> defined as {:s .+}
#
# correct result is :
#---
#「select nvl(toto,nvl(titi,'tata') ) from dual 」
# main => 「select nvl(toto,nvl(titi,'tata') 」
# text => 「select」
# nvl => 「nvl(toto,nvl(titi,'tata') 」
# paraIn => 「(」
# expr1 => 「toto,nvl(titi」
# comma => 「,」
# expr2 => 「'tata'」
# expr2txt => 「'tata'」
# paraOut => 「)」
# textfin => 「) from dual 」
#---
#
# but getting
#---
#「select nvl(toto,nvl(titi,'tata') ) from dual 」
# textfin => 「select nvl(toto,nvl(titi,'tata') ) from dual 」
#---
grammar NVL {
rule TOPNVL { [<main>]* <textfin> }
rule main { <text> <nvl> }
regex text {:s .+?}
rule nvl {:i 'nvl' <paraIn> <expr1> <comma> <expr2> <paraOut> }
regex expr1 {:s .+?}
rule expr2 {<nvl>|<expr2txt> }
regex expr2txt {:s .+?}
regex textfin {:s .+ }
regex comma {',' }
regex paraIn {'('}
regex paraOut {')'}
}
### Parsing ok
my $cbl = "select nvl(toto,nvl(titi,tata) ) from dual ";
say "---";
say "Parsing : $cbl ---> OK" ;
say "---";
say NVL.parse($cbl, rule => 'TOPNVL');
say "---";
say "";
### Parsing nook
$cbl = "select nvl(toto,nvl(titi,'tata') ) from dual ";
say "---";
say "Parsing : $cbl ---> NOOK" ;
say "---";
say NVL.parse($cbl, rule => 'TOPNVL');
say "---";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment