Better walk()

This commit is contained in:
Devine Lu Linvega 2024-04-04 19:37:03 -07:00
parent 689fa77380
commit 070317d22d
2 changed files with 8 additions and 8 deletions

View File

@ -1,4 +1,4 @@
<> (swap ?x ?y) (?y ?x) <> (swap ?x ?y) (?y ?x)
(swap 123 456) (swap (123) (456))

View File

@ -18,15 +18,15 @@ walk(char *s)
{ {
int depth = 0; int depth = 0;
char c; char c;
while((c = *s++)) { if(s[0] == '(') {
if(c == '(') depth++; while((c = *s++)) {
if(c == ')') { if(c == '(') depth++;
--depth; if(c == ')') --depth;
if(!depth) break; if(!depth) return s;
} }
if(depth == 0 && c == ' ') return s - 1;
if(depth < 1 && c == ' ') { return s - 1; }
} }
while((c = *s++))
if(spacer(c)) return s - 1;
return s; return s;
} }