Parsing with Regexes and Grammars

2018-08-01 Thread Theo van den Heuvel
@Moritz Dear Moritz, I am using your book and have some remarks on it that I hope you find useful. It appears the address you are using here is send-only. The content of the book is good, but there are some problems with the publishing process. E.g. the first couple of pages are missing com

parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Perl6-people, I am looking for some inspiration. I am working with a grammar that I would like to have operate in two different modes. In both modes the rules are identical, but the methods should behave differently. There are probably better ways to do this than I can think of at this p

Re: parsing in different modes

2018-08-01 Thread yary
Have you considered subclassing your grammar? The child inherits the rules from the parent, and an override the changed methods. Or, the parent grammar could be rules-and-common-methods-only, and then have two child grammas for "inside parens" vs "outside parens." Not sure the mechanics of impleme

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Yary, no, i haven't. I need to think about this. I have trouble seeing how this would solve my problem. As I indicated: the grammar itself does not change. It is only the methods that need to change. I don't think I could use the actions method to actually select an Actions class. Thanks,

Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Hi Theo, have you considered using only one grammar but simply calling it with two different actions classes as a parameter depending on the mode you want to use? 2018-08-01 16:41 GMT+02:00 Theo van den Heuvel : > > > Hi Perl6-people, > > I am looking for some inspiration. I am working with a

start up delay?

2018-08-01 Thread ToddAndMargo
Hi All, Is it just me or does Perl 6 take about three times as long to start up as Perl 5? I do have a very fast machine and it takes about seven see for some of my Perl 6 stuff to get past the ruminating phase and start running. Any workaround for this, or is this just growing pains for Perl 6

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Laurent, yes I have, but the mode switching is supposed to happen mid-parsing. I hope to avoid having to interrupt the parse, because picking up after a subparse is going to be hard. I was looking for a way to communicate a change of mode with the action class, but: a) I don't think there i

Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Theo, if you define a dynamic variable (with the * twigil, for example $*mode)) in the section of the code right before calling the parse (or equivalent) method, then your actions class should be able to read it and to modify it when needed. Then, it is a matter of defining your action methods to

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Laurent, dynamic variables were my first attempt (see original post). The problem as I see it, but I may well be mistaken, is that I cannot use the grammar rule to change the variable, e.g, switching it on before and off after handling the item in question, Sum in my example, and use that

Re: parsing in different modes

2018-08-01 Thread Timo Paulssen
Hello Theo, have you considered placing the code for the actions directly inside the grammar's tokens and rules instead? You can just { make 123 } right in the middle and it'll have the same effect as doing that in an action method, but you'll be able to put code after it, too. HTH   - Timo

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Laurent, I will do some experimenting, because I could be wrong about the timing thing. A first experiment seems to work. I will post my solution when I am satisfied that it works. thanks, Theo Theo van den Heuvel schreef op 2018-08-01 21:21: Hi Laurent, dynamic variables were my first

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Laurent, the code below seems to do what I want. Even without a dynamic variable. Maybe I should test more thoroughly. my $nest = 0; grammar Sum { token TOP { ^ $ } rule Sum { + % } rule Expr { | { $nest++ } '[' ~ ']' { $nest-- } } token op { <[-+]> } token num { \d+ } tok

Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Hi Theo, You probably cannot use a grammar rule to change a dynamic variable (unless you include some action code into the rule), I agree, but I think you can use an action method attached to a rule to do it. I have actually done it recently in a real $work grammar that I intend to present at The

Re: parsing in different modes

2018-08-01 Thread Theo van den Heuvel
Hi Laurent, thanks. I particularly like the second idea, Incidentally I used an instantiated action class recently to configure the transformation in another grammar, so I should have thought of that. Great fan of "THink Perl6" by the way. Good luck in Glasgow, Theo Laurent Rosenfeld schree

Re: start up delay?

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Yes, I agree, start-up time is sometimes quite long. But sorry, I do not have a solution. Best, Laurent. 2018-08-01 20:14 GMT+02:00 ToddAndMargo : > Hi All, > > Is it just me or does Perl 6 take about three times as long to > start up as Perl 5? I do have a very fast machine and it takes > abo

Re: start up delay?

2018-08-01 Thread Tom Browder
One thing you can do, depending on your code, is to put most of your code in subroutines, put them in a module, and 'use' it in your main script. The module gets precompiled the first time you execute the program, and the overall program should be faster after the first go. The 'zef' program does

Re: start up delay?

2018-08-01 Thread ToddAndMargo
On Wed, Aug 1, 2018 at 1:14 PM ToddAndMargo wrote: Hi All, Is it just me or does Perl 6 take about three times as long to start up as Perl 5? I do have a very fast machine and it takes about seven see for some of my Perl 6 stuff to get past the ruminating phase and start running. Any workaro

Re: start up delay?

2018-08-01 Thread ToddAndMargo
2018-08-01 20:14 GMT+02:00 ToddAndMargo >: Hi All, Is it just me or does Perl 6 take about three times as long to start up as Perl 5? I do have a very fast machine and it takes about seven see for some of my Perl 6 stuff to get past the ruminat

need regex help

2018-08-01 Thread ToddAndMargo
Hi All, If there are any letter in the string, I want it to fail $ p6 'my $x="9.0v1"; if $x~~/<+alnum>-[]>/ {say "Y";}' ===SORRY!=== Unrecognized regex metacharacter - (must be quoted to match literally) at -e:1 --> my $x="9.0v1"; if $x~~/<+alnum>⏏-[]>/ {say "Y";} Unable to parse regex; co

Re: need regex help

2018-08-01 Thread Brandon Allbery
Set operations have to be inside the <>. You want something like: /<[alnum-alpha]>/. That said, this would be the same as //, I think? Please describe in words what you intended with that regex. (I suspect /<[alpha]>/ is what you really want, based on your earlier statement.) On Thu, Aug 2, 2018

Re: need regex help

2018-08-01 Thread ToddAndMargo
On 08/01/2018 10:00 PM, Brandon Allbery wrote: Set operations have to be inside the <>. You want something like: /<[alnum-alpha]>/. That said, this would be the same as //, I think? Please describe in words what you intended with that regex. (I suspect /<[alpha]>/ is what you really want, bas

Re: need regex help

2018-08-01 Thread Paul Procacci
\d and both match Unicode characters as well. If that's not the intention then it's best to be explicit. die("Horribly") unless "9.b1" ~~ / <[0-9]+> % '.' /; Typing from my phone so unable to test the above*** On Thu, Aug 2, 2018, 12:56 AM ToddAndMargo wrote: > Hi All, > > If there are any l