Code Monkey home page Code Monkey logo

Comments (3)

alanz avatar alanz commented on September 23, 2024

The model is used because the AST elements follow a definite structure, and must be able to nest, indent, etc.

The comments can appear anywhere, and simply take up what would otherwise be whitespace.

There is a substantial amount of complexity/subtlety to get the thing to actually work, so I am not confident that the requested change can be done easily.

I would welcome a PR to do it, so long as all the tests still pass with it.

from ghc-exactprint.

lspitzner avatar lspitzner commented on September 23, 2024

I don't see how my encoding would not be able to nest, indent, etc. But you certainly have a better picture of the many special cases around this stuff.

But regardless, does the current model not break for refactoring operation such as, lets say, "transform a:[b,c] into [a,b,c]"? Because the DP of the comma between b and c would become unusable? It seems to me that the current design runs into problems sooner or later not only for re-formatting but also refactoring uses.

But I can completely understand that redesigning this would be an enormous amount of work. So I'd like to ask a different question: Would you be opposed to adding redundant information to the exactprint/annotation API, where this additional data is not used for exactprinting but available for downstreams like brittany? The "DP relative to the last non-whitespace character" would be such data that would enable brittany to support retaining empty lines inside literals (tuples, lists, etc.)

Of course that usecase is not terribly important, but I have encountered situations where such feature would be nice-to-have. Either way, thanks for considering.

from ghc-exactprint.

rwe avatar rwe commented on September 23, 2024

I wrestled with this today too. All I wanted was to get apply-refact to actually delete unused language pragmas instead of leaving blank lines…but the annotation offsets are inscrutable and unpredictable. For example, given this:

{-# LANGUAGE Foo #-}

{-# LANGUAGE Bar #}

The DP of both of those is (0, 0), for some reason. But if you add an identifier:

{-# LANGUAGE Foo #-}

{-# LANGUAGE Bar #}
foo = 12

Then suddenly the DP of the second pragma has (2, 0). I can't tell if this is a bug in ghc-exactprint, or if it just has surprising semantics. But in either case, I'm not sure how use it to actually transform documents.

from ghc-exactprint.

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.