GithubHelp home page GithubHelp logo

Comments (3)

aslatter avatar aslatter commented on June 19, 2024

Reading your request literally:

Currently the SourcePos data structure is only used for error reporting - it is the responsibility of the running parser to update it in whatever way makes sense for it, and the "API" for doing so is public - adding fields could break parsers built on top of Parsec using a custom token-type.

For example the built-in character parsers, all of them are built on top of Text.Parsec.Char.satisfy, which is a wrapper around Text.Parsec.Prim.tokenPrim - satisfy tells tokenPrim to use the function updatePosChar to update the SourcePos.

Digging a bit deeper:

It looks like you actually want to track the tokens consumed, not necessarily the characters consumed.

This would be different from the reported source position when we're parsing a stream of some other token type which has embedded location information in the token itself - the expectation is that the primitive parsers for the token-type will lift the token source positions into the SourcePos type while it parses (for the Char token-type this lifting is pretty simple).

A token-count would live in a new field in Text.Parsec.Prim.State. You'd need to figure out how to update tokens, token and tokenPrim in Text.Parsec.Prim. I'd also want to know how this affects run-time and memory usage of Parsec-based parsers.

from parsec.

gibiansky avatar gibiansky commented on June 19, 2024

Yes, indeed, your deeper reading is what I was going for – a token count of number of tokens consumed. Perhaps SourcePos is not the right location for that, you are right. I was also unsure of whether this already existed and I had simply missed it.

So, it sounds like there is no fundamental reason this doesn't exist – more like one of lack of need perhaps or lack of effort to do it. Thanks! I do not think that I will be implementing this – as I have not personally needed this and do not think it is a good idea to implement features "just in case someone someday" needs them someday... So you can probably go ahead and close the issue – thanks for the clarification.

from parsec.

aslatter avatar aslatter commented on June 19, 2024

Okay!

I'm not opposed to this sort of thing, but I'll close the issue until someone wants to push for it.

from parsec.

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.