From 070317d22d7b4e66e566f80723291be19eb11189 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 19:37:03 -0700 Subject: [PATCH] Better walk() --- examples/test.modal | 2 +- src/modal.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/test.modal b/examples/test.modal index 312e9f4..c9e0aa4 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,4 +1,4 @@ <> (swap ?x ?y) (?y ?x) -(swap 123 456) +(swap (123) (456)) diff --git a/src/modal.c b/src/modal.c index 9f6600a..c10fe55 100644 --- a/src/modal.c +++ b/src/modal.c @@ -18,15 +18,15 @@ walk(char *s) { int depth = 0; char c; - while((c = *s++)) { - if(c == '(') depth++; - if(c == ')') { - --depth; - if(!depth) break; + if(s[0] == '(') { + while((c = *s++)) { + if(c == '(') depth++; + if(c == ')') --depth; + 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; }