feat: sql解析器替换、工单统一由‘我的流程’发起、流程定义支持自定义条件触发审批、资源隐藏编号、model支持物理删除等

This commit is contained in:
meilin.huang
2024-10-16 17:24:50 +08:00
parent 43edef412c
commit e135e4ce64
170 changed files with 397197 additions and 1251 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
java -jar antlr-4.13.1-complete.jar -Dlanguage=Go -package parser -visitor *.g4

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
/*
PostgreSQL grammar.
The MIT License (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package parser
import (
"unicode"
"github.com/antlr4-go/antlr/v4"
)
type PostgreSQLLexerBase struct {
*antlr.BaseLexer
stack StringStack
}
func (receiver *PostgreSQLLexerBase) pushTag() {
receiver.stack.Push(receiver.GetText())
}
func (receiver *PostgreSQLLexerBase) isTag() bool {
if receiver.stack.IsEmpty() {
return false
}
return receiver.GetText() == receiver.stack.PeekOrEmpty()
}
func (receiver *PostgreSQLLexerBase) popTag() {
_, _ = receiver.stack.Pop()
}
func (receiver *PostgreSQLLexerBase) checkLA(c int) bool {
return receiver.GetInputStream().LA(1) != c
}
func (receiver *PostgreSQLLexerBase) charIsLetter() bool {
c := receiver.GetInputStream().LA(-1)
return unicode.IsLetter(rune(c))
}
func (receiver *PostgreSQLLexerBase) HandleNumericFail() {
index := receiver.GetInputStream().Index() - 2
receiver.GetInputStream().Seek(index)
receiver.SetType(PostgreSQLLexerIntegral)
}
func (receiver *PostgreSQLLexerBase) HandleLessLessGreaterGreater() {
if receiver.GetText() == "<<" {
receiver.SetType(PostgreSQLLexerLESS_LESS)
}
if receiver.GetText() == ">>" {
receiver.SetType(PostgreSQLLexerGREATER_GREATER)
}
}
func (receiver *PostgreSQLLexerBase) UnterminatedBlockCommentDebugAssert() {
//Debug.Assert(InputStream.LA(1) == -1 /*EOF*/);
}
func (receiver *PostgreSQLLexerBase) CheckIfUtf32Letter() bool {
codePoint := receiver.GetInputStream().LA(-2)<<8 + receiver.GetInputStream().LA(-1)
var c []rune
if codePoint < 0x10000 {
c = []rune{rune(codePoint)}
} else {
codePoint -= 0x10000
c = []rune{
(rune)(codePoint/0x400 + 0xd800),
(rune)(codePoint%0x400 + 0xdc00),
}
}
return unicode.IsLetter(c[0])
}

View File

@@ -0,0 +1,29 @@
/*
PostgreSQL grammar.
The MIT License (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package parser
type PostgreSQLParseError struct {
Number int
Offset int
Line int
Column int
Message string
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,214 @@
/*
PostgreSQL grammar.
The MIT License (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package parser
import (
"strings"
"github.com/antlr4-go/antlr/v4"
)
type PostgreSQLParserBase struct {
*antlr.BaseParser
parseErrors []*PostgreSQLParseError
}
func NewPostgreSQLParserBase(input antlr.TokenStream) *PostgreSQLParserBase {
return &PostgreSQLParserBase{
BaseParser: antlr.NewBaseParser(input),
}
}
func (receiver *PostgreSQLParserBase) GetParsedSqlTree(script string, line int) antlr.ParserRuleContext {
parser := getPostgreSQLParser(script)
result := parser.Root()
for _, err := range parser.parseErrors {
receiver.parseErrors = append(receiver.parseErrors, &PostgreSQLParseError{
Number: err.Number,
Offset: err.Offset,
Line: err.Line + line,
Column: err.Column,
Message: err.Message,
})
}
return result
}
func (receiver *PostgreSQLParserBase) ParseRoutineBody(localContextInterface ICreatefunc_opt_listContext) {
localContext, ok := localContextInterface.(*Createfunc_opt_listContext)
if !ok {
return
}
var lang string
for _, coi := range localContext.AllCreatefunc_opt_item() {
createFuncOptItemContext, ok := coi.(*Createfunc_opt_itemContext)
if !ok || createFuncOptItemContext.LANGUAGE() == nil {
continue
}
nonReservedWordOrSConstContextInterface := createFuncOptItemContext.Nonreservedword_or_sconst()
if nonReservedWordOrSConstContextInterface == nil {
continue
}
nonReservedWordOrSConstContext, ok := nonReservedWordOrSConstContextInterface.(*Nonreservedword_or_sconstContext)
if !ok {
continue
}
nonReservedWordContextInterface := nonReservedWordOrSConstContext.Nonreservedword()
if nonReservedWordContextInterface == nil {
continue
}
nonReservedWordContext, ok := nonReservedWordContextInterface.(*NonreservedwordContext)
if !ok {
continue
}
identifierInterface := nonReservedWordContext.Identifier()
if identifierInterface == nil {
continue
}
identifier, ok := identifierInterface.(*IdentifierContext)
if !ok {
continue
}
node := identifier.Identifier()
if node == nil {
continue
}
lang = node.GetText()
break
}
if lang == "" {
return
}
var funcAs *Createfunc_opt_itemContext
for _, coi := range localContext.AllCreatefunc_opt_item() {
ctx, ok := coi.(*Createfunc_opt_itemContext)
if !ok || ctx.LANGUAGE() == nil {
continue
}
as := ctx.Func_as()
if as != nil {
funcAs = ctx
break
}
}
if funcAs == nil {
return
}
funcAsContextInterface := funcAs.Func_as()
if funcAsContextInterface == nil {
return
}
funcAsContext, ok := funcAsContextInterface.(*Func_asContext)
if !ok {
return
}
sConstContextInterface := funcAsContext.Sconst(0)
if sConstContextInterface == nil {
return
}
sConstContext, ok := sConstContextInterface.(*SconstContext)
if !ok {
return
}
text := GetRoutineBodyString(sConstContext)
line := sConstContext.GetStart().GetLine()
parser := getPostgreSQLParser(text)
switch lang {
case "plpgsql":
funcAs.Func_as().(*Func_asContext).Definition = parser.Plsqlroot()
case "sql":
funcAs.Func_as().(*Func_asContext).Definition = parser.Root()
}
for _, err := range parser.parseErrors {
receiver.parseErrors = append(receiver.parseErrors, &PostgreSQLParseError{
Number: err.Number,
Offset: err.Offset,
Line: err.Line + line,
Column: err.Column,
Message: err.Message,
})
}
}
func TrimQuotes(s string) string {
if s == "" {
return s
}
return s[1 : len(s)-2]
}
func unquote(s string) string {
result := strings.Builder{}
length := len(s)
index := 0
for index < length {
c := s[index]
result.WriteByte(c)
if c == '\'' && index < length-1 && (s[index+1] == '\'') {
index++
}
index++
}
return result.String()
}
func GetRoutineBodyString(rule *SconstContext) string {
if rule.Anysconst() == nil {
return ""
}
anySConstContext := rule.Anysconst().(*AnysconstContext)
stringConstant := anySConstContext.StringConstant()
if stringConstant != nil {
return unquote(TrimQuotes(stringConstant.GetText()))
}
unicodeEscapeStringConstant := anySConstContext.UnicodeEscapeStringConstant()
if unicodeEscapeStringConstant != nil {
return TrimQuotes(unicodeEscapeStringConstant.GetText())
}
escapeStringConstant := anySConstContext.EscapeStringConstant()
if escapeStringConstant != nil {
return TrimQuotes(escapeStringConstant.GetText())
}
result := strings.Builder{}
for _, node := range anySConstContext.AllDollarText() {
result.WriteString(node.GetText())
}
return result.String()
}
func getPostgreSQLParser(script string) *PostgreSQLParser {
stream := antlr.NewInputStream(script)
lexer := NewPostgreSQLLexer(stream)
tokenStream := antlr.NewCommonTokenStream(lexer, 0)
parser := NewPostgreSQLParser(tokenStream)
errorListener := new(PostgreSQLParserErrorListener)
errorListener.grammar = parser
parser.AddErrorListener(errorListener)
return parser
}

View File

@@ -0,0 +1,51 @@
/*
PostgreSQL grammar.
The MIT License (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package parser
import "github.com/antlr4-go/antlr/v4"
type PostgreSQLParserErrorListener struct {
grammar *PostgreSQLParser
}
var _ antlr.ErrorListener = &PostgreSQLParserErrorListener{}
func (receiver PostgreSQLParserErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) {
receiver.grammar.parseErrors = append(receiver.grammar.parseErrors, &PostgreSQLParseError{
Number: 0,
Offset: 0,
Line: line,
Column: column,
Message: msg,
})
}
func (receiver PostgreSQLParserErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
// ignore
}
func (receiver PostgreSQLParserErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs *antlr.ATNConfigSet) {
// ignore
}
func (receiver PostgreSQLParserErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs *antlr.ATNConfigSet) {
// ignore
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
/*
PostgreSQL grammar.
The MIT License (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package parser
import (
"errors"
)
var (
ErrorStackEmpty = errors.New("stack empty")
)
type StringStack struct {
items []string
}
func (receiver *StringStack) Push(value string) {
receiver.items = append(receiver.items, value)
}
func (receiver *StringStack) Pop() (string, error) {
if receiver.IsEmpty() {
return "", ErrorStackEmpty
}
value := receiver.items[0]
receiver.items = receiver.items[1:]
return value, nil
}
func (receiver *StringStack) PopOrEmpty() string {
value, err := receiver.Pop()
if err != nil {
return ""
}
return value
}
func (receiver *StringStack) Peek() (string, error) {
if receiver.IsEmpty() {
return "", ErrorStackEmpty
}
return receiver.items[0], nil
}
func (receiver *StringStack) PeekOrEmpty() string {
value, err := receiver.Peek()
if err != nil {
return ""
}
return value
}
func (receiver *StringStack) Size() int {
return len(receiver.items)
}
func (receiver *StringStack) IsEmpty() bool {
return receiver.Size() == 0
}