Giter Site home page Giter Site logo

Comments (3)

tomtau avatar tomtau commented on July 17, 2024

LineIndex is internal only, I think (it was done differently before, so it's just an implementation detail)... maybe just returning the offsets &[usize] from that accessor function would be better? Or are you specifically interested in LineIndex for the line_col helper function?

from pest.

BoolPurist avatar BoolPurist commented on July 17, 2024

I prefere the latter one, "line_col" function from LineIndex https://github.com/pest-parser/pest/blob/master/pest/src/iterators/line_index.rs#L36 .

Just getting the offsets &[usize] would be appreaciated though.
However then I need the columns numbers too. I still would have to implement the logic for getting the column number . This library already solves this problem too, Why not provide to user too ?

I know there is a way to access the line and column number on a returned token. However that requires one to keep every pair struct around for getting the line and column number from a byte.

I think it would be nice to get a struct which would provide this function "line_col ". This pub struct could be a different one than the LineIndex to hide this detail. Since the LineIndex is already in a Rc, It would not be hard to provide this new pub struct with this inner hidden detail.

Here draft of an API, I would find useful on this pub struct.

pub fn line_col(&self, input: &str, pos: usize) -> (usize, usize) {
   ...
}

pub fn line(&self, input: &str, pos: usize) -> usize {
  ...
}

from pest.

tomtau avatar tomtau commented on July 17, 2024

I recall @huacnlee was using this line/col information before, so may have an opinion or suggestion for this.
In principle, it should be ok as long as the API's returned types wouldn't limit changes in the internal implementation.

from pest.

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.