GithubHelp home page GithubHelp logo

Comments (2)

jcoglan avatar jcoglan commented on August 21, 2024

I think this shares some of the problems of #7 in that parsing expressions do not have names. A grammar binds rule names to parsing expressions, which are arbitrarily nested, like expressions in a programming language. The %action syntax is bound to these nested expressions, not to rule names. So parsing expressions and their results are really anonymous, there isn't a "type" that we could track and pass through to these functions.

It is possible in theory for us to assign a "type" to nodes based on the rule where they are initially created, where their parsing expression is. However I think this would end up being more confusing, because referencing conceptually "moves" nodes between rules. Some rules generate one of many different types via a choice like a / b / c -- should the nodes this expression returns retain their original type, or the type of the referencing rule? How should this affect optional nodes, or repeitions?

It would also make grammars harder to refactor; grammar rules are effectively function definitions, and imagine a programming language where every value had the name of the function that generated it attached to it. If you refactored by moving code between functions, or splitting functions into smaller units, you'd need to change how all their values are handled. So adding this "type" information strongly couples the grammar to the program that consumes it, in a way that I believe would cause more hassle than its worth.

In cases like yours, there will usually by logic somewhere that cases about the "type" you've assigned to each ParseNode and cause different behaviour. I think that logic should live in the parser by causing different types of object to be created, and the different behaviours should be attached to those objects -- the parser is the place you make these decisions.

from canopy.

jcoglan avatar jcoglan commented on August 21, 2024

As mentioned in #7 (comment) I've added a limited form of rule name capture in order to improve error messages. I am still not sold on adding rule names to parse tree nodes, for the reasons mentioned there and on this thread. I will keep it under review for future releases, however.

from canopy.

Related Issues (20)

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.