Code Monkey home page Code Monkey logo

Comments (5)

maddyblue avatar maddyblue commented on August 26, 2024 1

I would love to support comments instead of remove them. They are hard because our parser always removes them. But I think we have a few workarounds.

For your use case, which is comments in between statements, we can maybe do something to support those using the lexer to look for comments on either side of a SQL semicolon token and print them somehow. I feel like this is doable because I think it can be done without changing the current lexer or parser (or maybe a simple change to the lexer to have it emit comments? Unsure).

The more difficult version is to support comments in the middle of a statement. This would require teaching AST nodes about comments or else some shadow data structure that could attach comments to any node in the AST somehow, which would have to be consulted during pretty printing. I think this feature would be much harder, because I'm unsure how to do it.

Thoughts @knz?

from sqlfmt.

knz avatar knz commented on August 26, 2024

Going the cockroachdb lexer route is going to be hard and inelegant.

Mainly because the lexer code is complex, and adding special code on a lexer that is otherwise optimized for speed in the production case, just for satisfying the needs of sqlfmt, feels like the wrong choice.

I think the only sane choice to achieve this is to pre-process using a separate tool / lexer.

from sqlfmt.

knz avatar knz commented on August 26, 2024

For example I would simply split the input at newlines, detect lines containing only comments (top level), and then feed the lines in-between comments separately to sqlfmt.

from sqlfmt.

maddyblue avatar maddyblue commented on August 26, 2024

I don't think that works for queries like

select '
-- 1
2';

from sqlfmt.

knz avatar knz commented on August 26, 2024

that is not a query that interests rich. I do not care about this type of things. I would be relatively opposed to making the crdb scanner more complex just so that sqlfmt has correct behavior in those odd cases.

If that is important to you I fear the only reasonable option is to fork the scanner into the sqlfmt tool (and ensure it doesn't get linked with the crdb binary so we don't have code duplication).

from sqlfmt.

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.