Code Monkey home page Code Monkey logo

Comments (3)

igordejanovic avatar igordejanovic commented on June 19, 2024

You've hit an interesting case of nested empty parses. See unit test in the commit. There was a subtle bug triggered if nothing is matched in nested parses consisting of OrderedChoice and ZeroOrMore.

The authority rule if completely optional (indirectly), meaning that it will match empty strings. I'm not sure is this what you really want, or what RFC suggest?

Get the current master version. It parses now but you will get empty parse tree for illegal inputs. That is not what you want I guess. It is usually a good idea to terminate your grammar root rule with EOF match. That means that you must be at the end of your input when done parsing. If that is not the case than your have superfluous characters in the input and NoMatch should be raised.

def authority():
    return Optional(userinfo, '@'), host, Optional(':', port), EOF

from arpeggio.

ixemad avatar ixemad commented on June 19, 2024

I want to implement the full grammar of several RFCs so it's not possible to append EOF to authority. I also wondered how authority [1], host [2] and reg-name [3] are defined. Anyway, glad to see it's solved in the current master.

Kind regards!

[1] https://tools.ietf.org/html/rfc3986#section-3.2
[2] https://tools.ietf.org/html/rfc3986#section-3.2.2
[3] https://tools.ietf.org/html/rfc3986#page-21

from arpeggio.

igordejanovic avatar igordejanovic commented on June 19, 2024

Ah, right. authority is not your grammar root rule. Anyway, when you finish your grammar your top level rule should be something like:

def grammar(): return URI, EOF
def URI(): return ....

Now, your real RFC grammar starts from URI but your root rule used in ParserPython will include EOF at the end to signify that you are interested in parsing the whole input always. This will prevent successful parses for URIs that have superfluous characters at the end.

from arpeggio.

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.