parseColumnName parses a column name in DDL context, accepting reserved keywords like KEY, TABLE, INDEX as column names when context is unambiguous. In SQLite and other dialects, many reserved words may appear as column names.
()
| 30 | // like KEY, TABLE, INDEX as column names when context is unambiguous. |
| 31 | // In SQLite and other dialects, many reserved words may appear as column names. |
| 32 | func (p *Parser) parseColumnName() *ast.Identifier { |
| 33 | val := p.currentToken.Token.Value |
| 34 | if val == "" { |
| 35 | return nil |
| 36 | } |
| 37 | // Accept identifiers, double-quoted identifiers, and any keyword token |
| 38 | // that could be used as a column name (e.g. KEY, TABLE, INDEX, etc.) |
| 39 | switch p.currentToken.Token.Type { |
| 40 | case models.TokenTypeEOF, models.TokenTypeComma, models.TokenTypeLParen, |
| 41 | models.TokenTypeRParen, models.TokenTypeSemicolon, models.TokenTypePeriod, |
| 42 | models.TokenTypeUnknown: |
| 43 | return nil |
| 44 | } |
| 45 | pos := p.currentLocation() |
| 46 | ident := &ast.Identifier{Name: val, Pos: pos} |
| 47 | p.advance() |
| 48 | return ident |
| 49 | } |
| 50 | |
| 51 | // parseColumnDef parses a column definition including column constraints |
| 52 | func (p *Parser) parseColumnDef() (*ast.ColumnDef, error) { |
no test coverage detected