Skip to content

Commit

Permalink
Merge pull request #23 from deresmos/feature/gardening
Browse files Browse the repository at this point in the history
Gardening
  • Loading branch information
sattosan authored Sep 28, 2022
2 parents 4df4626 + a2e05bc commit 4a9a270
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 51 deletions.
2 changes: 1 addition & 1 deletion domain/vbscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
80 changes: 30 additions & 50 deletions internal/process_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 isMatchString(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.VBScriptEndWhilePattern,
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 isMatchString(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 isMatchString(str, patterns)
}

func isIncrementStatement(str string) bool {
isElse, err := regexp.MatchString(domain.VBScriptElsePattern, str)
if err != nil {
fmt.Printf("err: %v", err)
func isMatchString(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
}

0 comments on commit 4a9a270

Please sign in to comment.