@@ -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
0 commit comments