aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-24 14:26:41 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-24 14:26:41 +0300
commit5424ff2a0969b31f84690cd19bea4e363d32e63a (patch)
treec741147fb66b4e1acc6e0a2fb7c10cc1b76dead8 /tests
parent546c03672b5b8044dbca0814eac8cbdddb898183 (diff)
downloadeclat-5424ff2a0969b31f84690cd19bea4e363d32e63a.tar.gz
eclat-5424ff2a0969b31f84690cd19bea4e363d32e63a.tar.bz2
Implement loops and variables
* lib/forlan.c: Implement loops and variables. * lib/forlangrm.y: Likewise. * lib/forlanlex.l: Likewise. * lib/forlan.h (forlan_parse): Change return type. (forlan_type): New types. (forlan_dump_tree): Change signature. (forlan_value_type) <forlan_value_boolean>: New type. * tests/tforlan.c: Update.
Diffstat (limited to 'tests')
-rw-r--r--tests/tforlan.c58
1 files changed, 52 insertions, 6 deletions
diff --git a/tests/tforlan.c b/tests/tforlan.c
index 9fc3495..550bc03 100644
--- a/tests/tforlan.c
+++ b/tests/tforlan.c
@@ -23,6 +23,7 @@
#endif
#include <errno.h>
#include <sysexits.h>
+#include <expat.h>
#include <libeclat.h>
#include "forlan.h"
#include <sys/stat.h>
@@ -33,6 +34,32 @@ usage()
printf("usage: %s [-dD] FILE [INPUT]\n");
}
+struct grecs_node *
+parse_xml(FILE *fp)
+{
+ XML_Parser parser;
+ eclat_partial_tree_t part;
+ size_t size;
+ char buffer[256];
+
+ parser = XML_ParserCreate("UTF-8");
+ if (!parser)
+ die(EX_SOFTWARE, "cannot create XML parser");
+ XML_SetElementHandler(parser,
+ eclat_partial_tree_start_handler,
+ eclat_partial_tree_end_handler);
+ XML_SetCharacterDataHandler(parser,
+ eclat_partial_tree_data_handler);
+ part = eclat_partial_tree_create();
+ XML_SetUserData(parser, part);
+
+ while ((size = fread(buffer, 1, sizeof(buffer), fp)) > 0)
+ XML_Parse(parser, buffer, size, 0);
+ XML_Parse(parser, "", 0, 1);
+
+ return eclat_partial_tree_finish(part);
+}
+
int
main(int argc, char **argv)
{
@@ -43,6 +70,7 @@ main(int argc, char **argv)
struct grecs_locus_point pt;
int rc;
int dump_option = 0;
+ forlan_eval_env_t env;
set_program_name(argv[0]);
forlan_init();
@@ -89,12 +117,30 @@ main(int argc, char **argv)
pt.line = 1;
pt.col = 0;
- rc = forlan_parse(buf, len, &pt);
- if (rc == 0) {
- if (dump_option)
- forlan_dump_tree(stdout, forlan_parse_tree);
- forlan_node_free(forlan_parse_tree);
+ env = forlan_parse(buf, len, &pt);
+ if (!env)
+ return EX_UNAVAILABLE;
+ if (dump_option)
+ forlan_dump_tree(stdout, env);
+
+ if (argv[1]) {
+ struct grecs_node *tree;
+
+ fp = fopen(argv[1], "r");
+ if (!fp)
+ die(EX_UNAVAILABLE,
+ "cannot open input file \"%s\": %s",
+ argv[1], strerror(errno));
+ tree = parse_xml(fp);
+ fclose(fp);
+
+ forlan_run(env, tree);
+ grecs_tree_free(tree);
}
- return rc ? EX_UNAVAILABLE : 0;
+
+ forlan_free_environment(env);
+
+
+ return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.