Comments (5)
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.
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.
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.
I don't think that works for queries like
select '
-- 1
2';
from sqlfmt.
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)
- try to reduce binary size
- CREATE FUNCTION not implemented
- share links should override auto-paste
- switch to post
- row is removed
- current_timestamp -> current_timestamp() breaking postgres HOT 2
- Any plan to split out the formatting part out to a module? HOT 4
- Extensions HOT 2
- Purpose: SQL or CockroachDB-flavored SQL? HOT 1
- Support for gopherjs
- Broken interval for Postgres HOT 2
- Additional double quotation marks added to the T-SQL statement HOT 1
- New release? HOT 2
- SQL format failed
- module declares its path as: github.com/HdrHistogram/hdrhistogram-go but was required as: github.com/codahale/hdrhistogram HOT 2
- [Feature request] Publish on homebrew
- could I use it in my go code with import the packge
- NPM package / vscode support?
- Why mix the style of functions and phrases? HOT 1
- support placeholder HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlfmt.