Comments (7)
Closing this as stale since we haven't looped back to it in a while, but hope all's going well!
from superpower.
Hi!
The problem looks to be that at the end of the input, Cell
will still match via the LiteralCellContent.Many()
rule, and RecordTerminator
will also match, because of the Parse.Return("").AtEnd()
rule, meaning there would be an essentially infinite procession of empty records at the end of the input.
A quick fix (not sure about error message quality implications?) might be to remove the terminator
part from Record
, and make the final rule:
public static readonly TextParser<IEnumerable<IEnumerable<string>>> Csv =
Record.ManyDelimitedBy(NewLine).AtEnd().Select(x => x.AsEnumerable());
from superpower.
I figured the Parse.Return("").AtEnd()
rule could potentially be hurting me.
Believe it or not, in my experimenting with this conversion, I have attempted what you suggested and it still fails with the same exception.
I am going to keep working on this today, any other suggestions appreciated.
from superpower.
Looks like it was the NewLine field/prop was causing my problem, even in my simpler non-quoted Csv parser.
I changed this line
static readonly TextParser<string> NewLine = Parse.Return(Environment.NewLine);
to
static readonly TextParser<TextSpan> NewLine = Span.EqualTo(Environment.NewLine);
It now works as intended and I am going to clean it up.
@nblumhardt Any chance you want a test or sample PR submitted?
from superpower.
Aha, great! I missed that one :-)
It'd be awesome if you can post the example somewhere we can link, but I don't think we should currently add more text-parser examples to this repo, since the general not-migrating-from-Sprache usage should probably be via TokenParser
.
from superpower.
It'd be awesome if you can post the example somewhere we can link, but I don't think we should currently add more text-parser examples to this repo
No problem and makes sense. I will respond to this issue when I have a sample Gist created using TextParser
method/style.
since the general not-migrating-from-Sprache usage should probably be via
TokenParser
.
Curious, are you saying the proper way to use Superpower is to preferably utilize the TokenParser
instead of the built in TextParser
's? Is that because Token parsers have better error messaging and reporting? Or?
I am going to keep practicing with this library and also make a simple TokenParser
to handle CSV/TSV files. Perhaps when I feel comfortable with it you could review it one day? I know you're busy and I will never ask for immediate review. Just a big fan of your work, style, design and architecture.
from superpower.
Thanks! :D
I might have overstated the suggestion to start with token parsers; for simple things that stay simple, text parsers are probably just as good from the perspective of this library. Token parsers are able to make use of more features of Superpower, though, including the nicer error reporting and the easy handling of whitespace and comments. Not a big difference, but probably enough that I'd try starting with a token parser in most cases.
Keen to hear how you go, making the API as usable/approachable as Sprache's is an ongoing project :-) Cheers!
from superpower.
Related Issues (20)
- Zero allocation parsing? HOT 1
- Unit Testing? HOT 1
- Is it normal that NaturalUInt32 raise System.OverflowException : Value was either too large or too small for a UInt32 ? HOT 2
- [Request] Need a new introductory blog for v2 (or v3) HOT 1
- Questions: My On Going Questions HOT 4
- Parsing confusion: Zero-width parsers, what rewinds and when, and properly returning a "failed" parse? HOT 4
- [Question] New Release? HOT 1
- Thank you for writing superpower HOT 1
- Better `Message` HOT 5
- Improve error reporting for some failed match scenarios HOT 9
- Using backslash in CStyle QuotedString causes syntax error HOT 1
- `OptionalOrNull()` HOT 2
- Send parser value into another parser HOT 1
- Tokenizer and Parser Assistance HOT 3
- TokenizerBuilder and Mapping CLR Types HOT 2
- Dynamically referencing Parsers via Decorators for TokenizerBuilder HOT 2
- Some way to check the next token HOT 3
- Missing: Cheat sheet for upgrading from Sprache to Superpower HOT 1
- How to handle consecutive delimiters HOT 6
- dotnet 8 upgrade? HOT 5
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 superpower.