commit e2f55c2356725ddc5ba42ae36bca6deffdc15c47
parent 28476526f86abe770d02adb0c6cc86867e363133
Author: erai <erai@omiltem.net>
Date: Sat, 14 Sep 2024 18:35:15 -0400
discard peg space nodes
Diffstat:
5 files changed, 12 insertions(+), 39 deletions(-)
diff --git a/cc3.c b/cc3.c
@@ -19,7 +19,7 @@ main(argc: int, argv: **byte, envp: **byte) {
fclose(f);
peg = peg_new(argv[1], src, len, &a);
- node = peg_parse(peg);
+ node = peg_parse(peg, P_sp);
peg_free(peg);
out = fopen(1, &a);
diff --git a/parsepeg.c b/parsepeg.c
@@ -191,24 +191,12 @@ p_primary(c: *peg): int {
ok = p_any(c);
}
if !ok { choice(c);
- ok = p_any(c);
- }
- if !ok { choice(c);
- ok = p_literal(c);
- }
- if !ok { choice(c);
ok = p_literal(c);
}
if !ok { choice(c);
ok = p_class(c);
}
if !ok { choice(c);
- ok = p_class(c);
- }
- if !ok { choice(c);
- ok = p_call(c);
- }
- if !ok { choice(c);
ok = p_call(c);
}
if ok { commit(c); } else { fail(c); }
@@ -273,9 +261,6 @@ p_class(c: *peg): int {
if !ok { choice(c);
ok = any(c);
}
- if !ok { choice(c);
- ok = any(c);
- }
if ok { commit(c); } else { fail(c); }
}
if !ok { ok = 1; break; }
@@ -344,22 +329,6 @@ p_sp(c: *peg): int {
}
}
}
- if !ok { choice(c);
- ok = literal(c, "//");
- if ok {
- loop {
- choice(c);
- choice(c);
- ok = charset(c, "\x0a\x0d");
- if ok { fail(c); fail(c); ok = 0; } else { ok = 1; }
- if ok {
- ok = any(c);
- }
- if !ok { ok = 1; break; }
- commit(c);
- }
- }
- }
if ok { commit(c); } else { fail(c); }
if !ok { ok = 1; break; }
commit(c);
diff --git a/peg.c b/peg.c
@@ -517,7 +517,7 @@ main(argc: int, argv: **byte, envp: **byte) {
c.out = out;
c.p = peg_new(filename, src, len, c.a);
- node = peg_parse(c.p);
+ node = peg_parse(c.p, P_sp);
translate(&c, node);
diff --git a/peglib.c b/peglib.c
@@ -215,7 +215,7 @@ any(c: *peg): int {
return 1;
}
-construct(c: *peg): *peg_node {
+construct(c: *peg, sp: int): *peg_node {
var i: int;
var j: int;
var nargs: int;
@@ -250,8 +250,12 @@ construct(c: *peg): *peg_node {
break;
}
- *link = c.nstack[j];
- link = &c.nstack[j].next;
+ if c.nstack[j].tag != sp {
+ *link = c.nstack[j];
+ link = &c.nstack[j].next;
+ } else {
+ free(c.a, c.nstack[j]:*byte);
+ }
j = j + 1;
}
@@ -307,7 +311,7 @@ peg_new(filename: *byte, src: *byte, len: int, a: *alloc): *peg {
return c;
}
-peg_parse(c: *peg): *peg_node {
+peg_parse(c: *peg, sp: int): *peg_node {
choice(c);
if !p_grammar(c) {
fdputs(2, "syntax error at ");
@@ -327,7 +331,7 @@ peg_parse(c: *peg): *peg_node {
exit(1);
}
commit(c);
- return construct(c);
+ return construct(c, sp);
}
peg_reset(c: *peg, src: *byte, len: int) {
diff --git a/watch.sh b/watch.sh
@@ -1,6 +1,6 @@
#!/bin/sh
clear
-sh -e ./build.sh
+time sh -e ./build.sh
echo status $?
: < ~/.post
exec "$0"