Code Monkey home page Code Monkey logo

Comments (6)

rynoV avatar rynoV commented on June 12, 2024

Same thing happens for class and instance patterns, for example:

instance Class Data where
  f = a

-- | haddock
g = a

class Class where
  f :: Data

-- | haddock
g = a
(class) @class.around
(instance (where)? . _ @class.inside) @class.around

from tree-sitter-haskell.

tek avatar tek commented on June 12, 2024

I'm not sure that it's feasible to implement this, since comments are allowed to break indentation:

f = do
  g

-- foo
  pure 1

so in order to decide whether the comment should terminate the do layout, we'd need to parse the indent of the following line, which would require us to either

  • jump back to after g if indentation decreases to terminate the do node
  • jump back to after foo if indentation stays the same so that the leading spaces of the next line won't be included in the comment (and we need them to determine the indent again for the next node)

and this won't work since we can't store two positions at once ☚ī¸

(in case that is unclear: comments and indent are parsed manually in the C extension)

The only way I can imagine now would be to compromise and use -- | as an indicator, but since that isn't Haskell syntax, but Haddock, it could break valid code. Though it's probably unlikely to occur in an invalid position.

I'll think a bit more about this but I'm fairly pessimistic.

from tree-sitter-haskell.

tek avatar tek commented on June 12, 2024

@414owen do you have an idea maybe?

from tree-sitter-haskell.

414owen avatar 414owen commented on June 12, 2024

I guess I'm unsure why it works without the do block. I would have thought the lexer would only detect the end of f when it sees function g, which would be after the comment.

from tree-sitter-haskell.

tek avatar tek commented on June 12, 2024

indeed, that's curious

from tree-sitter-haskell.

tek avatar tek commented on June 12, 2024

ok so in the case without do the function is entirely contained in the range a = b, so tree-sitter is conservative and uses the smallest tree that works, leaving the comment on its own since there's no reason to associate it with any neighboring node more than the others.

for the do case, the layout end is part of the function rhs, so the comment cannot escape that tree.

from tree-sitter-haskell.

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.