Comments (3)
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.
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.
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)
- Detect and report invalid grammars
- Question to the possible design of the reporting functionality
- 2.0.1: started require deprecated `pytest-runner` HOT 2
- Create .peg/.cleanpeg files from parsers written in python. HOT 1
- Create .peg/clean.peg files from parsers written in python. HOT 1
- Question: Is there a way to convert the graph of Arpeggio nodes into a state machine? HOT 1
- Please read this before asking questions
- Comments in strings / regexps
- Suppressing rules doesn't seem to work
- setup.py fails with UnicodeDecodeError
- ParserPEG with multiple root rules HOT 1
- How to define a recursive rule with Python style? HOT 2
- performance issue when parsing => grammar not good? HOT 7
- Repetitions with separators terminate on empty separator match
- 1.10.2: pytest warnings
- pytest-runner is not required
- Lookahead rules always showed as not matched in debug mode HOT 1
- Lookahead not working in OrderedChoice HOT 5
- Can PEG syntax (cleanpeg) use reduce_tree and memoization? HOT 6
- Unexpected NoMatch when suppressing a StrMatch from the parse tree HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arpeggio.