Comments (7)
If empty inputs were to be handled by the "normal" parser and propagate the error up, what would you expect escaped
to do with a content that is all escaped values (e.g. (\t\t\t
)? In that example, there are 4 empty strings which would be an error.
From an implementation perspective, its as-if you were running with opt(normal)
, making it so any error gets discarded.
However, that wouldn't preclude a escaped1
from existing like there is take_till
and take_til1
, etc if the maintainer was up for it. Personally, I am curious what the use case is. Most of the time I see escaped characters, they are put in delimiters (""
) and 0 or more allowed.
from nom.
I don't follow. escaped
handles \t\t\t
just fine.
main parser gets \t\t\t
as input, hits \
, rejects it, escaped
consumes \
, runs second parser, which consumes t
. Rinse and repeat. The while loop in escaped
terminates when there's no input left.
The issue is about how escaped
does not work with the multi
combinators because it returns Ok
for an empty input string, which is both unexpected and arguably incorrect with how basically the entire library is designed (almost all parsers refuse empty inputs unless they have a 0
variant.)
There's also other issues with escaped
, making implementing e.g. quoted strings difficult. Even nom's own example on escaped string literals doesn't use escaped
. But that's not relevant to this specific issue. Playground link
from nom.
The issue is about how escaped does not work with the multi combinators because it returns Ok for an empty input string, which is both unexpected and arguably incorrect with how basically the entire library is designed (almost all parsers refuse empty inputs unless they have a 0 variant.)
That was in response specifically to:
Ok when given an empty input without even attempting to run the inner parser, which otherwise would correctly return an error,
arguably incorrect with how basically the entire library is designed (almost all parsers refuse empty inputs unless they have a 0 variant.)
This doesn't match my experience with nom
bytes
doesn't use the0
suffix (which includesescaped
): https://docs.rs/nom/latest/nom/bytes/complete/index.htmlcharacter
mostly uses0
suffix exceptnot_line_ending
: https://docs.rs/nom/latest/nom/character/complete/index.htmlmulti
mostly uses0
suffix exceptmany_till
: https://docs.rs/nom/latest/nom/multi/index.html
from nom.
- Parsers with neither a 0 or 1 variant basically never accept empty inputs (
tag
,char
, etc.) - Parsers with only a 1 variant accept empty inputs (
take_*
, seems like nothing else in nom has this) - Parsers with both variants are obvious and behave accordingly.
many_till
seems to be special by virtue of how it works, which is "run f until g succeeds", and looking at the docs f
has to succeed at least once.
Being in the bytes
module, escaped
should behave like the other bytes
parsers, i.e. fail on empty inputs unless a 1 variant exists. I'm sorry but I don't see your argument.
from nom.
many_till seems to be special by virtue of how it works, which is "run f until g succeeds", and looking at the docs f has to succeed at least once.
I'm not seeing what in the docs is leading to that. However, when I look at the code, g
is tried first and immediately returns if it succeeds, independent of f
.
Being in the bytes module, escaped should behave like the other bytes parsers, i.e. fail on empty inputs unless a 1 variant exists. I'm sorry but I don't see your argument.
I had misunderstood and thought you were keying off of whether a 0
variant exists. Instead, you are reading into the API that if a 1
variant exists, then the non-1
variant is implicitly 0
and if there isn't a 1
variant, then its implicitly a 1
variant.
not_line_ending
breaks this "rule". Without there being something documented (which I've not seen), I think this is trying to make rules where there are none.
from nom.
not_line_ending
has neither a 0 or 1 variant and errors on empty inputs. That's perfectly consistent with all the other ones.
from nom.
This discussion is getting pretty tiresome, it has nothing to do with my actual issue (which is, at best a one line documentation change, and at worst a legitimate bug)
The consistency doesn't actually matter. It's merely a supporting argument for why this edge case should be addressed.
from nom.
Related Issues (20)
- Nom's error is referencing data owned by the calling function
- Any other approach to handle left recursion
- How to parse until a range of tags HOT 3
- Mention difference between is_not and take_until in their respective docs.
- I was going to complain about an issue in the function take_while_m_n, but [update : and I will do] ...
- Add u48 number parser HOT 1
- I want to implement `separated_tuple` for 8.0 HOT 7
- `tag_no_case` panicks while matching certain unicode capitalized characters.
- Ergonomics of `alt()` taking tuple versus slice HOT 3
- A new release for 8.0?
- FromStr-esque parsing trait HOT 1
- Float parsing with trailing `e` broken
- A fix has to be implemented by those dependencies HOT 7
- FlatMap does not properly implement Parser HOT 2
- Feature Request: Add branching parser combinator for `exclude()` and `depend()` HOT 1
- Stack overflow before parsing HOT 1
- fold's param init func should be FnOnce instead of FnMut HOT 3
- Profile-Guided Optimization (PGO) benchmark results
- Fn / FnMut HOT 7
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 nom.