Code Monkey home page Code Monkey logo

Comments (4)

robojeb avatar robojeb commented on August 17, 2024 1

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.

zesterer avatar zesterer commented on August 17, 2024

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.

exoticorn avatar exoticorn commented on August 17, 2024

I ran into the same issue just now. I do agree that it doesn't have to be Sources 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.

zesterer avatar zesterer commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.