Skip to content

Semantic actions #399

Open
Open

Description

@fan-tom

Currently we need to write separate code to convert pest parsed representation to our own AST representation, as shown in JSON example. The drawback of that approach is that you have to keep that conversion in sync with grammar, as they are in different places. Bison have semantic actions and peg crate also supports them (see a:e1 b:e2 c:e3 { rust }). It allows to get you own AST type right after parsing and you can change AST construction steps right when you change your grammar, no need to separate conversion step, you can even avoid creating intermidiate parser-related values (Pair) and just immidiately produce user defined types while parsing

Activity

  1. CAD97 commented on Jun 30, 2019

    @CAD97
    Contributor

    The vision for pest3 is much closer to this. So far we've seen value in not embedding actions into the grammar itself; this means that the grammar is an actual formal definition of the grammar you're parsing (as opposed to, say, ANTLR, where you can arbitrarily add conditions/effects to the grammar).

    Pest3 intends to bring a system where instead of creating the pair-based tree, we create a "Listener"-like interface that you implement that determines what is used to "reduce" a tree from the "actions" the parser parses.

  2. Nadrieril commented on Sep 18, 2019

    @Nadrieril
    Contributor

    I have written a crate that provides something like that with the current version of pest: https://docs.rs/pest_consume. I've been using it in a large parser and it works very smoothly. Check out the csv example if you're curious.
    @fan-tom you might be interested if you don't want to wait for pest3
    @CAD97 I'd be interested to discuss how that would fit with pest3 and how the listener approach would work in practice

  3. Sayan751 commented on Aug 19, 2020

    @Sayan751

    @CAD97 Is the work for pest3 is progress? Excited about this feature. I have recently went through the boo. Loved the simplicity of pest :)

  4. CAD97 commented on Aug 21, 2020

    @CAD97
    Contributor

    Unfortunately, @dragostis hasn't been able to work on pest recently, and basically everything pest3 related is blocked on him. I can merge fixes and dependency updates to this repository, but I can't actually publish, so the project is basically on hiatus while @dragostis is busy.

  5. mainrs commented on Aug 24, 2020

    @mainrs

    Might be a good idea to share publishing rights as this just holds development back ;)

  6. added this to the v3.0 milestone on Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions