Comments (4)
Thanks for taking a look.
It would be fine if Source
wasn't intended for use as an input type.
Having percolated on it over night, I would change the flow of my code to: Parse on a str
, convert str
to Source
and place in Cache, Print diagnostics from the Cache.
This may already be what you intended it just wasn't the first thing that came to my mind because I was looking at the ariadne::Cache
which directly returns Source
objects.
I ended up writing my own cache so I didn't have to load the files from the filesystem at both parsing and diagnostics.
from ariadne.
Hi, thanks for opening this issue. I definitely agree that this should be documented better and I'll be adding this to my TODO list (including moving to byte offsets instead of character positions) for my planned refactor of the library.
From my end, I wonder whether it would be better for me to keep Source
's internal view of things as an implementation detail: it's set up to make it as easy as possible for Ariadne's diagnostic generator to work with and isn't really intended as a way for library users to directly interact with a file's contents.
from ariadne.
I ran into the same issue just now. I do agree that it doesn't have to be Source
s job to act as input to a parser but given the state of documentation it's not unreasonable to try to use it that way.
For me, my main motivation to use Source
as input to Chumsky was that it looked like the safest bet to avoid getting bitten by changes to the newline handling, ie.:
len: line.chars().count() + 1, // TODO: Don't assume all newlines are a single character!
Now, if you can promise not to work on this TODO until switching to byte offsets (at which point this is probably moot, anyway), I'd just switch to iterate the source string directly, filtering out any '\r'
characters.
from ariadne.
This is handled slightly better in master
, fwiw. I've not had time to sit down and do the rework of the crate I've been meaning to in order to properly address this though.
from ariadne.
Related Issues (20)
- Remove "filesystem" category from `Cargo.toml` HOT 1
- error[E0284]: type annotation needed HOT 1
- Upgrade to `yansi 1.0` HOT 1
- Version 0.4.1 is a breaking change HOT 4
- Config::default().with_color(false) not disable colors for `with_message`
- Feature Request: Getters of private fields
- Remove README include from normal build
- Dotted lines in left margins disappeared in version `0.2.0` HOT 1
- Allow annotation with different styles HOT 3
- Support `Caused by` HOT 3
- Recommended approach to handling colors HOT 2
- Potential deprecation of `concolor` HOT 4
- Potential deprecation of `concolor` HOT 1
- Assistance? HOT 2
- Problem specifying filename HOT 8
- Ariadne crashes when input is empty HOT 4
- convert `ariadne::Report` to `String` HOT 2
- convert `ariadne::Report` to `String` HOT 3
- Empty Labels / A way to color characters
- Tracking: The Big Refactor 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 ariadne.