Skip to content

Commit 847fd6c

Browse files
committed
Take only comment inside CREATE query
1 parent ec94235 commit 847fd6c

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

internal/engine/sqlite/convert.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c *cc) convertCreate_table_stmtContext(n *parser.Create_table_stmtContext)
112112
stmt := &ast.CreateTableStmt{
113113
Name: parseTableName(n),
114114
IfNotExists: n.EXISTS_() != nil,
115-
Comment: comment(tokenStream, n, false),
115+
Comment: comment(tokenStream, n.OPEN_PAR().GetSymbol()),
116116
}
117117

118118
for _, idef := range n.AllColumn_def() {
@@ -126,27 +126,22 @@ func (c *cc) convertCreate_table_stmtContext(n *parser.Create_table_stmtContext)
126126
Colname: identifier(def.Column_name().GetText()),
127127
IsNotNull: hasNotNullConstraint(def.AllColumn_constraint()),
128128
TypeName: &ast.TypeName{Name: typeName},
129-
Comment: comment(tokenStream, def, true),
129+
Comment: comment(tokenStream, def.GetStop()),
130130
})
131131

132132
}
133133
}
134134
return stmt
135135
}
136136

137-
// comment returns the comment associated with the given context. The parameter right indicates whether the comment is
138-
// to the right or to the left of the context.
139-
func comment(tokenStream *antlr.CommonTokenStream, ctx antlr.ParserRuleContext, right bool) string {
137+
// comment returns the comment associated with the given context.
138+
func comment(tokenStream *antlr.CommonTokenStream, from antlr.Token) string {
140139
var (
141140
hiddenTokens []antlr.Token
142141
comment string
143142
)
144143

145-
if right {
146-
hiddenTokens = tokenStream.GetHiddenTokensToRight(ctx.GetStop().GetTokenIndex()+1, antlr.TokenHiddenChannel)
147-
} else {
148-
hiddenTokens = tokenStream.GetHiddenTokensToLeft(ctx.GetStart().GetTokenIndex(), antlr.TokenHiddenChannel)
149-
}
144+
hiddenTokens = tokenStream.GetHiddenTokensToRight(from.GetTokenIndex()+1, antlr.TokenHiddenChannel)
150145

151146
for _, token := range hiddenTokens {
152147
// Filter for single-line comments

internal/engine/sqlite/parse.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
5050
pp.AddErrorListener(el)
5151
// pp.BuildParseTrees = true
5252
tree := pp.Parse()
53-
5453
if el.err != "" {
5554
return nil, errors.New(el.err)
5655
}
@@ -84,7 +83,6 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
8483
loc = stmt.GetStop().GetStop() + 2
8584
}
8685
}
87-
8886
return stmts, nil
8987
}
9088

0 commit comments

Comments
 (0)