From 74460298da563647a6621e9112210f0bb00e13f2 Mon Sep 17 00:00:00 2001 From: "tomoki.tamura" Date: Mon, 24 May 2021 12:21:10 +0900 Subject: [PATCH 1/3] Change the description of pattern match --- internal/process_control.go | 80 ++++++++++++++----------------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/internal/process_control.go b/internal/process_control.go index ff60433..a04972f 100644 --- a/internal/process_control.go +++ b/internal/process_control.go @@ -60,68 +60,48 @@ func getLastFunction(vbscript *domain.VBScript) *domain.Function { } func isBeginNestStatement(str string) bool { - isIf, err := regexp.MatchString(domain.VBScriptIfPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - isFor, err := regexp.MatchString(domain.VBScriptForPattern, str) - if err != nil { - fmt.Printf("err: %v", err) + patterns := []string{ + domain.VBScriptIfPattern, + domain.VBScriptForPattern, + domain.VBScriptDoPattern, + domain.VBScriptWhilePattern, + domain.VBScriptSelectPattern, } - isDo, err := regexp.MatchString(domain.VBScriptDoPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - isWhile, err := regexp.MatchString(domain.VBScriptWhilePattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - isSelect, err := regexp.MatchString(domain.VBScriptSelectPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - return isIf || isFor || isDo || isWhile || isSelect + return isMatchStatement(str, patterns) } func isEndNestStatement(str string) bool { - isEndIf, err := regexp.MatchString(domain.VBScriptEndIfPattern, str) - if err != nil { - fmt.Printf("err: %v", err) + patterns := []string{ + domain.VBScriptEndIfPattern, + domain.VBScriptNextPattern, + domain.VBScriptLoopPattern, + domain.VBScriptWhileEndPattern, + domain.VBScriptEndSelectPattern, } - isNext, err := regexp.MatchString(domain.VBScriptNextPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - isLoop, err := regexp.MatchString(domain.VBScriptLoopPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } - - isWhileEnd, err := regexp.MatchString(domain.VBScriptWhileEndPattern, str) - if err != nil { - fmt.Printf("err: %v", err) - } + return isMatchStatement(str, patterns) +} - isEndSelect, err := regexp.MatchString(domain.VBScriptEndSelectPattern, str) - if err != nil { - fmt.Printf("err: %v", err) +func isIncrementStatement(str string) bool { + patterns := []string{ + domain.VBScriptElsePattern, } - return isEndIf || isNext || isLoop || isWhileEnd || isEndSelect + return isMatchStatement(str, patterns) } -func isIncrementStatement(str string) bool { - isElse, err := regexp.MatchString(domain.VBScriptElsePattern, str) - if err != nil { - fmt.Printf("err: %v", err) +func isMatchStatement(line string, patterns []string) bool { + for _, pattern := range patterns { + isMatch, err := regexp.MatchString(pattern, line) + if err != nil { + fmt.Printf("err: %v", err) + } + + if isMatch { + return true + } } - return isElse + return false } From c43cb15ced99610751bf7d36b709a6c6abe6499a Mon Sep 17 00:00:00 2001 From: "tomoki.tamura" Date: Mon, 24 May 2021 12:23:53 +0900 Subject: [PATCH 2/3] Change variable name --- domain/vbscript.go | 2 +- internal/process_control.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/domain/vbscript.go b/domain/vbscript.go index 77a510d..cc3a03e 100644 --- a/domain/vbscript.go +++ b/domain/vbscript.go @@ -10,7 +10,7 @@ const ( VBScriptDoPattern = `(?i)^(\s*?)(\t*?)(Do)($|(\s+?)|(\t+?)| While | Until )` VBScriptLoopPattern = `(?i)^(\s*?)(\t*?)(Loop)($|(\s+?)|(\t+?)| While | Until )` VBScriptWhilePattern = `(?i)^(\s*?)(\t*?)(While )` - VBScriptWhileEndPattern = `(?i)^(\s*?)(\t*?)(End While|Wend)` + VBScriptEndWhilePattern = `(?i)^(\s*?)(\t*?)(End While|Wend)` VBScriptSelectPattern = `(?i)^(\s*?)(\t*?)(Select Case )` VBScriptEndSelectPattern = `(?i)^(\s*?)(\t*?)(End Select)($|(\s+?)|(\t+?))` VBScriptFunctionPattern = `(?i)^(\s*?)(\t*?)(Private |Public (Default )?)?(Function|Sub)` diff --git a/internal/process_control.go b/internal/process_control.go index a04972f..a39a678 100644 --- a/internal/process_control.go +++ b/internal/process_control.go @@ -76,7 +76,7 @@ func isEndNestStatement(str string) bool { domain.VBScriptEndIfPattern, domain.VBScriptNextPattern, domain.VBScriptLoopPattern, - domain.VBScriptWhileEndPattern, + domain.VBScriptEndWhilePattern, domain.VBScriptEndSelectPattern, } From a2e05bc507b864ec05ca6394528b064248950821 Mon Sep 17 00:00:00 2001 From: "tomoki.tamura" Date: Mon, 24 May 2021 12:39:01 +0900 Subject: [PATCH 3/3] Change name --- internal/process_control.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/process_control.go b/internal/process_control.go index a39a678..afea1c9 100644 --- a/internal/process_control.go +++ b/internal/process_control.go @@ -68,7 +68,7 @@ func isBeginNestStatement(str string) bool { domain.VBScriptSelectPattern, } - return isMatchStatement(str, patterns) + return isMatchString(str, patterns) } func isEndNestStatement(str string) bool { @@ -80,7 +80,7 @@ func isEndNestStatement(str string) bool { domain.VBScriptEndSelectPattern, } - return isMatchStatement(str, patterns) + return isMatchString(str, patterns) } func isIncrementStatement(str string) bool { @@ -88,10 +88,10 @@ func isIncrementStatement(str string) bool { domain.VBScriptElsePattern, } - return isMatchStatement(str, patterns) + return isMatchString(str, patterns) } -func isMatchStatement(line string, patterns []string) bool { +func isMatchString(line string, patterns []string) bool { for _, pattern := range patterns { isMatch, err := regexp.MatchString(pattern, line) if err != nil {