Comments (10)
This is definitely something I'm in favour of, especially implementing parser for strings and character literals. Anything that makes the syntax easier to write and understand would be excellent, in my book.
Overloaded operators would be cool, but if it requires a great deal of changes internally, it certainly doesn't have to be a priority. I really like the use of operator overloading in the Scala parser combinators library, but making it work in Rust could be a bit of a struggle.
from combine.
@hawkw I might actually have been a bit to optimistic about allowing strings and character literals as parser. It would work but they would need do be specialized to work on only a single type of input stream (probably &str). It may still be a bit of useful sugar but it does feel like something that would be easy to trip up new users on.
The changes I was thinking of to make operator overloading possible is to introduce a newtype which all parsers return so instead of many(p: P) -> Many<P>
it would be many(p: ParserT<P>) -> ParserT<Many<P>>
. Unfortunately this makes it impossible to pass a parser by &mut reference (many(&mut parser)
) which I find useful quite frequently. It may need some more thought to make it work smoothly.
from combine.
@Marwes: Ah well. I haven't ever had to use pass a &mut
reference to a parser, but if you find that it's important, that should probably remain possible - my particular use case may not be typical. I'm already specializing to &str
because of #21, so I for one would love being able to use literal parsers, but the current syntax should definitely remain available for unspecialized parsers.
from combine.
Passing parsers by &mut is pretty common for combinators since they can't move the parsers they own (see And).
It would be possible to just add a method on ParserT
which converts it like ParserT<P> -> ParserT<&mut P>
but it would also need a method which converts ParserT<P> -> ParserT<&mut Parser>
(trait object) and for Box etc. I have yet to think of a better way though.
from combine.
Tuples as a sequencing parser are implemented in f8c15a2 (0.5.0).
With RangeStreams (#42) I a am a bit more keen on the string literal overloaded as a parser as the &str
Stream feels a bit more important which could warrant the extra sugar for it.
Operators won't happen for 1.0 as it would break everything and require a lot of rewriting.
from combine.
For reference, I like how nom
handles it.
str
and char
literals would be cool too.
from combine.
For reference, I like how nom handles it.
Tuples are the equivalent constructs in combine
. Were you thinking of some extension to that?
str
andchar
literals would be cool too.
Still torn on allowing the use of literals directly as they can only work with a single stream type which may make that those streams seem (&str
and &[u8]
) more important than they should be. At least in the case of &str
one would probably use State<&str>
instead and only use a &str
stream directly if more precise control over the position is required.
from combine.
In nom, you can name the fields you want, while with the tuples you have to use .0
or pattern matching.
from combine.
True. The idea is to use pattern matching to name the fields you want. I suppose it may be clearer in code to put the names as close to the actual parser as possible though (as nom does). It is pretty low priority for me though. I'd be happy to accept a PR for such a macro if you feel inclined to add it.
from combine.
@Yamakaky struct_parser! were added which makes it possible to name the fields of a sequence.
I don't see it as worthwhile making &str
a parser due to Input
being an associated type which would force &str
to only work with a single input type. This could be solved by making Input
a type parameter to the Parser
trait but that comes with problems in type inference instead which would offset any benefit of adding it.
As for overloading operators. This would be an extremely invasive change and in the end all it would give is the ability to write p1 | p2 | p3 ...
. Since this can now be written as choice((p1, p2, p3, ...))
instead of an or
chain I believe the complexity is not worth it for the little syntactic sugar which operators would give. https://docs.rs/combine/3.0.0-alpha.2/combine/fn.choice.html
So as a conclusion I will close this issue
from combine.
Related Issues (20)
- Help with reporting non-parsing errors. HOT 3
- Publishing 4.6.1? HOT 1
- choice! returns an error when one of its parsers would be successful HOT 2
- Throw stream errors HOT 5
- DateTime parser HOT 1
- take_until_bytes() and partial parsing HOT 2
- Is there a way to get `Stream<Token=char>` from `io::Read`? HOT 1
- Tools for debugging recursion problems? HOT 4
- Some issue with error reporting
- Errors include unprintable or awkwardly printed characters. HOT 6
- `expected` error strings always quote what was expected, even if it isn't a literal HOT 3
- How about offset into some data? HOT 3
- Outdated tutorial HOT 1
- Native/abstracted sub-parsers HOT 6
- XML parsing for React.js to Solid.js conversion HOT 4
- Comparison with LALRPOP
- Unbounded mutual recursion in Parser impl HOT 3
- Adivce on reducing code size in WASM target HOT 7
- Docs unclear whether `parser!` should be used on nightly rust HOT 2
- Parse `std::process::Child` stdout
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 combine.