MCPcopy
hub / github.com/sqlc-dev/sqlc / convertLiteral

Method convertLiteral

internal/engine/sqlite/convert.go:734–774  ·  view source on GitHub ↗
(n *parser.Expr_literalContext)

Source from the content-addressed store, hash-verified

732}
733
734func (c *cc) convertLiteral(n *parser.Expr_literalContext) ast.Node {
735 if literal, ok := n.Literal_value().(*parser.Literal_valueContext); ok {
736
737 if literal.NUMERIC_LITERAL() != nil {
738 i, _ := strconv.ParseInt(literal.GetText(), 10, 64)
739 return &ast.A_Const{
740 Val: &ast.Integer{Ival: i},
741 Location: n.GetStart().GetStart(),
742 }
743 }
744
745 if literal.STRING_LITERAL() != nil {
746 // remove surrounding single quote
747 text := literal.GetText()
748 return &ast.A_Const{
749 Val: &ast.String{Str: text[1 : len(text)-1]},
750 Location: n.GetStart().GetStart(),
751 }
752 }
753
754 if literal.TRUE_() != nil || literal.FALSE_() != nil {
755 var i int64
756 if literal.TRUE_() != nil {
757 i = 1
758 }
759
760 return &ast.A_Const{
761 Val: &ast.Integer{Ival: i},
762 Location: n.GetStart().GetStart(),
763 }
764 }
765
766 if literal.NULL_() != nil {
767 return &ast.A_Const{
768 Val: &ast.Null{},
769 Location: n.GetStart().GetStart(),
770 }
771 }
772 }
773 return todo("convertLiteral", n)
774}
775
776func (c *cc) convertBinaryNode(n *parser.Expr_binaryContext) ast.Node {
777 return &ast.A_Expr{

Callers 1

convertMethod · 0.95

Calls 9

GetTextMethod · 0.80
GetStartMethod · 0.80
todoFunction · 0.70
Literal_valueMethod · 0.65
NUMERIC_LITERALMethod · 0.65
STRING_LITERALMethod · 0.65
TRUE_Method · 0.65
FALSE_Method · 0.65
NULL_Method · 0.65

Tested by

no test coverage detected