Pivot to simpler approach. Passes JSONTestSuite

This commit is contained in:
2025-05-18 11:34:12 -04:00
parent 6cb7645675
commit 19208c0e0a
5 changed files with 998 additions and 13 deletions

39
src/validate.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include <fcntl.h>
#include <unistd.h>
#include "callbacks.h"
#include "parser3.h"
int main(int argc, char **argv) {
if (argc < 2) {
printf("Usage: %s <path>\n", argv[0]);
return 1;
}
int fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("open");
return 1;
}
auto c = noopCallbacks();
parser3::Parser3 parser(&c, nullptr);
for (;;) {
char buf[1024];
int l = read(fd, buf, sizeof(buf));
if (l == -1) {
perror("read");
return 1;
}
switch (parser.parse(buf, l)) {
case parser3::S_OK:
return 0;
case parser3::S_AGAIN:
continue;
case parser3::S_REJECT:
case parser3::S_OVERFLOW:
return 1;
}
if (l == 0) {
return 1;
}
}
}