Git Product home page Git Product logo

Comments (6)

rgrove avatar rgrove commented on July 24, 2024 1

Hey Titus!

Adding whole-string offset info to nodes would probably be pretty easy since the offset is already available during parsing, but line and column positions are currently only calculated when an error occurs (and not very efficiently).

There are currently several places where the parser consumes newlines, so keeping track of the line and column efficiently would probably take some refactoring. I'm open to this in theory, but I'm concerned about the potential performance impact given that many users aren't likely to need this functionality. I haven't looked into it deeply though, so I'm mostly working from memory.

from parse-xml.

wooorm avatar wooorm commented on July 24, 2024 1

Byte offsets into the source document is good enough for me!

from parse-xml.

wooorm avatar wooorm commented on July 24, 2024

https://github.com/vfile/vfile-location can do the transform! Should be more efficient that the current algorithm for errors, as it does most of the work once upfront, but it would likely still be faster to track everything directly when parsing

from parse-xml.

wooorm avatar wooorm commented on July 24, 2024

If you’re worried about performance (which makes sense), this could be put behind an option.
When that option is turned on, vfile-location is used at the start to generate the index, and then later for each start/end of a node you can do if (options.position) location.toPosition(byteOffset) or so?
I think that for me the perf “bottle neck” is fine

from parse-xml.

rgrove avatar rgrove commented on July 24, 2024

True. Unfortunately, integrating vfile-location into parse-xml would mean adding several runtime dependencies. Having zero runtime dependencies is one of parse-xml's differentiating features, and I'd prefer to preserve that.

One alternative might be to add events or callback hooks that would give vfile-location (or anything else) an opportunity to annotate nodes during parsing. Then this optional behavior could be part of a higher level package without requiring parse-xml itself to add any dependencies.

Or, if parse-xml were to annotate each node with its string offset, maybe another option would be for a higher level package to traverse the node tree after parsing and use vfile-location at that point?

from parse-xml.

rgrove avatar rgrove commented on July 24, 2024

@wooorm How does this look? #25

from parse-xml.

Related Issues (18)

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.