can someone clarify when white space is significant in rules in Perl 6 grammars? I am learning some by trial and error, but can't seem to find the actual rules in the documentation.
Example 1:
rule number {
<pm> \d '.'? \d*[ <pm> \d* ]?
}
rule pm {
[ '+' || '-' ]?
}
Will match a number 2.68156e+154
, and not care about the spaces that are present in rule number
. However, if I add a space after \d*
, it will fail.
(i.e. <pm> \d '.'? \d* [ <pm> \d* ]?
fails).
Example 2:
If I am trying to find literals in the middle of a word, then spacing around them are important. I.e., in finding the entry Double_t Delta_phi_R_1_9_pTproj_13_dat_cent_fx3001[52] = {
grammar TOP {
^ .*? <word-to-find> .* ?
}
rule word-to-find {
\w*?fx\w*
}
Will find the word. However, if the definition of the rule word-to-find
is changed to :
fx
or \w* fx\w*
or \w*fx \w*
then it won't make a match.
Also, then definition '[52]'
will match, while the definition 'fx[52]'
will not.
Thanks for any insight. A pointer to the proper point in the documentation would help greatly! Thanks,
token
instead ofrule
, and adding<.ws>
manually. – Reproduce