Hi Yary, I'd certainly welcome a simpler answer than what I posted--for both 1). incremental search and 2). returning positional values.
Below are some links to Regular Expressions in Python and in R. Regular Expressions in Perl 6 should aim to be as good if not better: Python: https://developers.google.com/edu/python/regular-expressions https://stackoverflow.com/questions/250271/python-regex-how-to-get-positions-and-values-of-matches R: https://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html https://stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html On Mon, Aug 19, 2019 at 5:51 PM yary <not....@gmail.com> wrote: > > If you do make this a grammar, I think there's more than one way to > have " {@a.push($/.pos)}/" fire after every match, and not repeat that > code snippit on each rule... keep that in mind as a goal... > > -y > > On Tue, Aug 20, 2019 at 7:13 AM William Michels via perl6-users > <perl6-users@perl.org> wrote: > > > > Thanks to Brad Gilbert's code contribution in this thread, I re-wrote > > a small snippet of his code (code that incrementally checks a series > > of regex matches), to have it return the last position of each match. > > Testing with three 'matches' and one 'willnotmatch' returns three > > positional values, as expected: > > > > use v6 > > my $test = " foo bar"; > > > > sub foo($x) { > > state @a = 0; > > $x ~~ m /^\s+ {@a.push($/.pos)}/; > > $x ~~ m :pos(@a[*-1]) /foo\s+ {@a.push($/.pos)}/; > > $x ~~ m :pos(@a[*-1]) /willnotmatch {@a.push($/.pos)}/; > > $x ~~ m :pos(@a[*-1]) /bar {@a.push($/.pos)}/; > > return @a[1 .. *]; > > } > > > > #say foo($test); # returns (6 10 13) > > put foo($test); # returns 6 10 13 > > > > > > I'm actually pleasantly surprised that I can add a dozen or so > > 'willnotmatch' lines, and it doesn't screw up the result. The next > > step might be to 1). pull the individual regexes out into an object > > (as suggested in the SO post below) to simplify each smartmatch line, > > and/or 2). store the results in a hash (instead of an array), for > > later substring extraction. But at this point it seems I'm getting > > into 'Grammar' territory, so that might be the better approach. > > > > HTH, Bill. > > > > https://stackoverflow.com/questions/50829126/perl6-interpolate-array-in-match-for-and-or-not-functions/50838441#50838441 > > > > > > > > > > > > > > > > > > On Mon, Aug 19, 2019 at 1:08 AM Patrick Spek via perl6-users > > <perl6-users@perl.org> wrote: > > > > > > On Sun, 18 Aug 2019 13:45:27 -0300 > > > Aureliano Guedes <guedes.aureli...@gmail.com> wrote: > > > > > > > Even being another language, Perl6 should be inheriting Perl5's > > > > regexes or even improving it not making it uglier and harder. > > > > > > > > Or I'm seeing how to use it in an easy way. Also, dunno if there is > > > > some GOOD documentation to Perl6 regexes. > > > > > > Beauty is in the eye of the beholder. While I'm much more proficient > > > with PCRE than P6CRE, I do find the Perl 6 variants to be much cleaner > > > and easier to understand when reading regexes of others. > > > > > > If you find that there's a lack of documentation explaining things > > > clearly to you, that'd be an issue to solve in the documentation. This > > > takes a lot of effort, and if you would be so kind as to improve it > > > where you think it's needed, it would be a great help to everyone (we > > > can't really see how or where you're looking for what, after all). > > > > > > -- > > > With kind regards, > > > > > > Patrick Spek > > > > > > > > > www: https://www.tyil.nl/ > > > mail: p.s...@tyil.nl > > > pgp: 1660 F6A2 DFA7 5347 322A 4DC0 7A6A C285 E2D9 8827 > > > > > > social: https://soc.fglt.nl/tyil > > > git: https://gitlab.com/tyil/