xsawyerx / guacamole

Guacamole is a parser toolkit for Standard Perl. It provides fully static BNF-based parsing capability to a reasonable subset of Perl.
https://metacpan.org/pod/Guacamole
20 stars 8 forks source link

Initial support for postderef #40

Closed xsawyerx closed 4 years ago

xsawyerx commented 4 years ago

A few problems:

A bug:

# bug
$foo->@ [ 0, 1, ]

Unfortunately, we see this as legitimate.

xsawyerx commented 4 years ago

There might be simpler solution: https://metacpan.org/pod/Marpa::R2::Scanless::DSL#priority

If I understand the doc correctly, it tells Marpa to use only one lexeme even if multiple match. So we coul do something like this:

Quote ~ 'q' | 'qq' | 'qw'
Phase ~ 'BEGIN' | 'END'
Identifer ~ [A-Za-z_]+
:lexeme ~ Phase priority => 1
:lexeme ~ Quote priority => 1

And have Marpa always parse BEGIN as Phase.

This is excellent. I'm wondering whether this breaks our goal of only having unambiguous grammar. Priority is not a concept in BNF. If it does break it, can we accept it?

The dance I do with the QLike operators for q*, m, s, tr, y, and all the phases is... pretty wild and I would be happy to remove it.

Maybe we should create a separate ticket for this.

vickenty commented 4 years ago

Using priority is not breaking the goal of unambiguous grammar. On the contrary, it allows us to unambiguously define lexems with otherwise ambiguous regular expressions. It can be done with regexes alone (as you did here), but is rather cumbersome (especially considering that we need to throw all named keywords there too).

As an aside, priority here is not part of the grammar either, it is part of the lexer. Marpa just combines two traditional text analysis stages in one tool and specification. For another example, flex has implicit priority defined by order in which they are given in the source file.

gonzus commented 4 years ago

Also, yacc-like systems allow defining syntax priorities with all the left / right / nonassoc qualifiers, as well as the order in which you list your rules. So, indeed, this is a well known and correct way of handling ambiguity that is still inside the context of a "pure parser".

On Tue, May 19, 2020 at 12:02 PM Vickenty Fesunov notifications@github.com wrote:

Using priority is not breaking the goal of unambiguous grammar. On the contrary, it allows us to unambiguously define lexems with otherwise ambiguous regular expressions. It can be done with regexes alone (as you did here), but is rather cumbersome (especially considering that we need to throw all named keywords there too).

As an aside, priority here is not part of the grammar either, it is part of the lexer. Marpa just combines two traditional text analysis stages in one tool and specification. For another example, flex has implicit priority defined by order in which they are given in the source file.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/xsawyerx/reimagined-guacamole/pull/40*issuecomment-630719992__;Iw!!FzMMvhmfRQ!533NIgIJ6IXTXEMWG99Vhsuy_SQ18cAG8u0iewvLseGuUnvaOj7BMtTlH1_ytB23AIk6pzo$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AABS5IT4DV62UOM7D6P5Z6TRSJKLTANCNFSM4NECMO7Q__;!!FzMMvhmfRQ!533NIgIJ6IXTXEMWG99Vhsuy_SQ18cAG8u0iewvLseGuUnvaOj7BMtTlH1_ytB23C_axXJs$ .

-- Gonzalo Diethelm Principal Developer

Booking.com BV Rembrandtplein 29-45 Amsterdam 1017 HG Netherlands Direct +31207035469 [image: Booking.com] https://www.booking.com/ Making it easier for everyone to experience the world since 1996 43 languages, 214+ offices worldwide, 141,000+ global destinations, 29 million reported listings Subsidiary of Booking Holdings Inc. (NASDAQ: BKNG)

xsawyerx commented 4 years ago

Also, yacc-like systems allow defining syntax priorities with all the left / right / nonassoc qualifiers, as well as the order in which you list your rules. So, indeed, this is a well known and correct way of handling ambiguity that is still inside the context of a "pure parser". On Tue, May 19, 2020 at 12:02 PM Vickenty Fesunov @.***> wrote: Using priority is not breaking the goal of unambiguous grammar. On the contrary, it allows us to unambiguously define lexems with otherwise ambiguous regular expressions. It can be done with regexes alone (as you did here), but is rather cumbersome (especially considering that we need to throw all named keywords there too). As an aside, priority here is not part of the grammar either, it is part of the lexer. Marpa just combines two traditional text analysis stages in one tool and specification. For another example, flex has implicit priority defined by order in which they are given in the source file.

Thanks guys.

I'll add the priority rules. Will definitely make this easier. :)

xsawyerx commented 4 years ago

The fixes for q-like values were done in a previous PR.

I also fixed $foo->$ [...] to fail, as well as $foo->$ *.