Skip to content

Commit

Permalink
[WIP] format with semicolon and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Dec 29, 2023
1 parent 1df0a2a commit 9b09ae0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ func (t *SQLToken) NoQuateString() string {
case *token.SQLWord:
return v.NoQuateString()
case string:
if t.Kind == token.Comment {
return "--" + v + "\n"
}
return v
default:
return " "
Expand All @@ -539,6 +542,9 @@ func (t *SQLToken) Render(opts *RenderOptions) string {
case *token.SQLWord:
return renderSQLWord(v, opts)
case string:
if t.Kind == token.Comment {
return "--" + v + "\n"
}
return v
default:
return " "
Expand Down
9 changes: 9 additions & 0 deletions internal/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ func formatItem(node ast.Node, env *formatEnvironment) ast.Node {
results = append(results, linebreakNode)
results = append(results, env.genIndent()...)
}
breakStatementAfterMatcher := astutil.NodeMatcher{
ExpectTokens: []token.Kind{
token.Semicolon,
},
}
if breakStatementAfterMatcher.IsMatch(node) {
results = append(results, linebreakNode)
env.indentLevelDown()
}

return &ast.ItemWith{Toks: results}
}
Expand Down
3 changes: 0 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ func NewParser(src io.Reader, d dialect.Dialect) (*Parser, error) {

parsed := []ast.Node{}
for _, tok := range tokens {
if tok.Kind == token.Comment {
continue
}
parsed = append(parsed, ast.NewItem(tok))
}

Expand Down

0 comments on commit 9b09ae0

Please sign in to comment.