workaround for old libffi
[m6w6/ext-psi] / idl / main.c
index c4664be36b45d426523d69d9487a0bfb0f0520ea..db88740e2ef5be487836dc0ebbef2769713e0561 100644 (file)
@@ -2,56 +2,35 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "main.h"
-
-static int TRACE;
-
-static void loop(PSI_Lexer *L, void *P)
-{
-       token_t t;
-       PSI_Token *T = NULL;
-
-       if (TRACE) {
-               PSI_ParserTrace(stdout, "> ");
-       }
-
-       while (-1 != (t = PSI_LexerScan(L))) {
-               if (!(T = PSI_TokenAlloc(L, t))) {
-                       break;
-               }
-
-               if (TRACE) {
-                       printf("# Token: <%s>(%d)\n", T->text, t);
-               }
-
-               PSI_Parser(P, t, T, L);
-       }
-       PSI_Parser(P, 0, T, L);
-}
+#include "parser.h"
+#include "validator.h"
 
 int main(int argc, char *argv[])
 {
-       PSI_Lexer L;
+       PSI_Parser P;
        PSI_Validator V;
-       void *P = PSI_ParserAlloc(malloc);
+       unsigned flags = 0;
 
-       TRACE = !!getenv("TRACE");
+       if (getenv("TRACE")) {
+               flags |= PSI_PARSER_DEBUG;
+       }
 
-       if (!PSI_LexerInit(&L, argv[1])) {
-               perror("Failed to init lexer");
+       if (!PSI_ParserInit(&P, argv[1], flags)) {
+               perror("Failer to init parser");
                return 1;
        }
 
-       loop(&L, P);
-
-       PSI_ParserFree(P, free);
+       while (-1 != PSI_ParserScan(&P)) {
+               PSI_ParserParse(&P, PSI_TokenAlloc(&P));
+       };
+       PSI_ParserParse(&P, NULL);
 
-       if (!PSI_ValidatorInit(&V, &L)) {
+       if (!PSI_ValidatorInit(&V, &P)) {
                perror("Failed to init validator");
                return 2;
        }
 
-       PSI_LexerDtor(&L);
+       PSI_ParserDtor(&P);
 
        if (PSI_ValidatorValidate(&V)) {
                printf("Whoa! VALID.\n");