mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
80 lines
1.3 KiB
Go
80 lines
1.3 KiB
Go
package sqlstmt
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/antlr4-go/antlr/v4"
|
|
)
|
|
|
|
type INode interface {
|
|
GetText() string
|
|
|
|
// GetStartIndex() int
|
|
// GetStopIndex() int
|
|
}
|
|
|
|
type Node struct {
|
|
// startIndex int
|
|
// stopIndex int
|
|
|
|
parser antlr.Parser
|
|
ruleContext antlr.RuleContext
|
|
}
|
|
|
|
func (n *Node) GetText() string {
|
|
if n == nil || n.ruleContext == nil || n.parser == nil {
|
|
return ""
|
|
}
|
|
return n.parser.GetTokenStream().GetTextFromRuleContext(n.ruleContext)
|
|
}
|
|
|
|
// func (n *Node) GetStartIndex() int {
|
|
// return n.startIndex
|
|
// }
|
|
|
|
// func (n *Node) GetStopIndex() int {
|
|
// return n.stopIndex
|
|
// }
|
|
|
|
func NewNode(parser antlr.Parser, ruleContext antlr.RuleContext) *Node {
|
|
return &Node{
|
|
parser: parser,
|
|
ruleContext: ruleContext,
|
|
}
|
|
}
|
|
|
|
// func NewNode(startIndex, stopIndex int) *Node {
|
|
// return &Node{
|
|
// startIndex: startIndex,
|
|
// stopIndex: stopIndex,
|
|
// }
|
|
// }
|
|
|
|
// func GetText(sqlstmts string, node INode) string {
|
|
// return sqlstmts[node.GetStartIndex() : node.GetStopIndex()+1]
|
|
// }
|
|
|
|
type Stmt interface {
|
|
INode
|
|
}
|
|
|
|
type SqlStmt struct {
|
|
*Node
|
|
}
|
|
|
|
type DmlStmt struct {
|
|
SqlStmt
|
|
}
|
|
|
|
type OtherReadStmt struct {
|
|
*Node
|
|
}
|
|
|
|
type WithStmt struct {
|
|
*Node
|
|
}
|
|
|
|
func IsSelectStmt(stmt Stmt) bool {
|
|
return reflect.TypeOf(stmt).AssignableTo(reflect.TypeOf(&SelectStmt{}))
|
|
}
|