refactor: 移除antlr4减小包体积&ai助手优化

This commit is contained in:
meilin.huang
2026-05-08 20:45:13 +08:00
parent 3768cef62d
commit f23b243fc5
154 changed files with 13054 additions and 396804 deletions

View File

@@ -1,11 +1,5 @@
package base
import (
"fmt"
"github.com/antlr4-go/antlr/v4"
)
// SingleSQL is a separate SQL split from multi-SQL.
type SingleSQL struct {
Text string
@@ -49,51 +43,6 @@ func (e *SyntaxError) Error() string {
return e.Message
}
// ParseErrorListener is a custom error listener for PLSQL parser.
type ParseErrorListener struct {
BaseLine int
Err *SyntaxError
}
// SyntaxError returns the errors.
func (l *ParseErrorListener) SyntaxError(_ antlr.Recognizer, token any, line, column int, msg string, _ antlr.RecognitionException) {
if l.Err == nil {
errMessage := ""
if token, ok := token.(*antlr.CommonToken); ok {
stream := token.GetInputStream()
start := token.GetStart() - 40
if start < 0 {
start = 0
}
stop := token.GetStop()
if stop >= stream.Size() {
stop = stream.Size() - 1
}
errMessage = fmt.Sprintf("related text: %s", stream.GetTextFromInterval(antlr.NewInterval(start, stop)))
}
l.Err = &SyntaxError{
Line: line + l.BaseLine,
Column: column,
Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", line+l.BaseLine, column, errMessage),
}
}
}
// ReportAmbiguity reports an ambiguity.
func (*ParseErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
}
// ReportAttemptingFullContext reports an attempting full context.
func (*ParseErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)
}
// ReportContextSensitivity reports a context sensitivity.
func (*ParseErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs *antlr.ATNConfigSet) {
antlr.ConsoleErrorListenerINSTANCE.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)
}
func FilterEmptySQL(list []SingleSQL) []SingleSQL {
var result []SingleSQL
for _, sql := range list {