Quick fix to lex errors at the repl with unbalanced parens

master
sloum 2 years ago
parent 26f693c73a
commit c041e61673

@ -501,3 +501,24 @@ func createTimeFormatString(s string) string {
return out.String()
}
// Used by REPL to know if another input line
// should be offered before parsing
func stringParensMatch(s string) bool {
t := Tokenize(s)
count := 0
for _, v := range t {
switch v {
case "(":
count++
case ")":
count--
}
}
if count > 0 {
return false
}
// If count is negative still return true, the
// parser will handle erroring
return true
}

@ -264,9 +264,7 @@ func Repl() {
}
text.WriteString(in)
text.WriteRune('\n')
open := strings.Count(text.String(), "(") + strings.Count(text.String(), "{")
closed := strings.Count(text.String(), ")") + strings.Count(text.String(), "}")
if open > closed {
if !stringParensMatch(text.String()){
cont = true
} else {
cont = false

Loading…
Cancel
Save