Unwrap rules storage

This commit is contained in:
Devine Lu Linvega 2024-04-04 20:13:14 -07:00
parent 8702b6472b
commit c7c5a20977
3 changed files with 10 additions and 4 deletions

View File

@ -1,4 +1,4 @@
<> (?x dup) (?x ?x) <> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x) <> (?x ?y swap) (?y ?x)
foo ((A B swap) dup) (A B swap) dup

View File

@ -1,4 +1,4 @@
<> (?x dup) (?x ?x) <> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x) <> (?x ?y swap) (?y ?x)
foo ((A B swap) dup) (A B swap) dup

View File

@ -119,8 +119,14 @@ parse_rulefrag(FILE *f)
int depth = 0; int depth = 0;
char c, *origin = dict_; char c, *origin = dict_;
while(f && fread(&c, 1, 1, f) && c && c != 0xa) { while(f && fread(&c, 1, 1, f) && c && c != 0xa) {
if(c == '(') depth++; if(c == '(') {
if(c == ')') --depth; depth++;
if(depth == 1) continue;
}
if(c == ')') {
--depth;
if(depth == 0) continue;
}
if(c == ' ' && !depth) break; if(c == ' ' && !depth) break;
*dict_++ = c; *dict_++ = c;
} }