Comments (3)
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.
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.
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)
- Trigger clippy: empty doc comment HOT 3
- perf regression in 2.7.9 HOT 6
- Whitespace ignored between rules HOT 1
- What does `outer` and `inner` do?
- Pairs has peek() but does not implement Peekable and has a different interface
- hebrew not working properly HOT 1
- Expected operator, found EOI HOT 3
- Predicate failure doesn't cause expression failure HOT 5
- Feature request: Option to use tags to improve error messages
- WHITESPACE and COMMENT require $ to be compound HOT 4
- Async Pest HOT 2
- Very unhelpful error messages for unmapped prefix operators in pratt parsers
- Tags on rules that can yield more than one pair
- Wrong tag associated with expression?
- Bug when matching brackets
- `Pairs` can be made with mismatched input `str` and `Vec<QueueableToken>` using `pest::state` HOT 1
- docs(book): documentation is missing for `ASCII` HOT 2
- Using `pest_derive` without `std` under a workspace fails in Windows. HOT 5
- Document panics
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 pest.