Coder Social home page Coder Social logo

Back-references and AST Nodes about pegase HOT 2 CLOSED

strblr avatar strblr commented on August 25, 2024
Back-references and AST Nodes

from pegase.

Comments (2)

joshuabowers avatar joshuabowers commented on August 25, 2024 1

Fair and understandable. I've developed an alternative approach for the use case abstracted above via a visitor, so the need for Nodes in back-references isn't necessary. Thanks for the sanity check.

from pegase.

strblr avatar strblr commented on August 25, 2024

That's an interesting situation. The thing is that once the left hand side of + is parsed, the only context you have of it is a Node, which can be arbitrarily defined with fields unrelated to your captures, or even unrelated to the parsing for that matter. So there is no way Pegase can tell automatically from which sub-matches the Node was built from, therefor it can't enforce anything for the right hand side of +.

Theoretically it might be possible to extend back references to nodes, but the nodes would lose a lot of flexibility as Pegase would need more predictability about the fields. That's not what abstract syntax trees are for. The abstraction must be user-defined.

Your case can however simply be solved by capturing the two operand's ASTs (or reading $children) and comparing them as you see fit in a semantic action.

Does that answer the question?

PS: By the way, that increases my sentiment that nodes and ASTs shouldn't be part of the core Pegase library, but rather distributed as an addon package with plugin and helper functions, for example in @pegase/node. By being entangled with the core package, it gives off the vibe that there is something more to nodes than just custom objects emitted like any other value. In fact it's nothing more. Pegase is not able to derive any deeper context from them.

from pegase.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.