aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_productions.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-07-25 15:24:22 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-07-25 15:24:22 -0700
commit4f8d4f378cffa71b4e80bfa2049e2152b429615c (patch)
tree32886a368b1a9ce1917bf7e4316e3a235e629e33 /parse_productions.cpp
parent3e3eefc2dcb2e0e31b224703a063e05dc8c67996 (diff)
AST no templates
Diffstat (limited to 'parse_productions.cpp')
-rw-r--r--parse_productions.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/parse_productions.cpp b/parse_productions.cpp
new file mode 100644
index 00000000..82bdd0b9
--- /dev/null
+++ b/parse_productions.cpp
@@ -0,0 +1,63 @@
+#include "parse_productions.h"
+
+using namespace parse_productions;
+
+#define PRODUCTIONS(sym) static const Production_t sym##_productions
+
+PRODUCTIONS(job_list) =
+ {
+ {},
+ {symbol_job, symbol_job_list},
+ {parse_token_type_end, symbol_job_list}
+ };
+
+
+
+/* A job_list is a list of jobs, separated by semicolons or newlines */
+
+DEC(job_list) {
+ symbol_job_list,
+ {
+ {},
+ {symbol_job, symbol_job_list},
+ {parse_token_type_end, symbol_job_list}
+ },
+ resolve_job_list
+};
+
+static int resolve_job_list(parse_token_type_t token_type, parse_keyword_t token_keyword)
+ {
+ switch (token_type)
+ {
+ case parse_token_type_string:
+ // 'end' is special
+ switch (token_keyword)
+ {
+ case parse_keyword_end:
+ case parse_keyword_else:
+ // End this job list
+ return 0;
+
+ default:
+ // Normal string
+ return 1;
+ }
+
+ case parse_token_type_pipe:
+ case parse_token_type_redirection:
+ case parse_token_type_background:
+ return 1;
+
+ case parse_token_type_end:
+ // Empty line
+ return 2;
+
+ case parse_token_type_terminate:
+ // no more commands, just transition to empty
+ return 0;
+ break;
+
+ default:
+ return NO_PRODUCTION;
+ }
+ } \ No newline at end of file