]> Pileus Git - ~andy/ct/blobdiff - parse.y
Add timestamp checking
[~andy/ct] / parse.y
diff --git a/parse.y b/parse.y
index 84a62be4733e0062a3d2c80711507ca1b335d383..530215c6e1ef720243d7274b0f34141e490b70a3 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -3,19 +3,21 @@
 #include <stdio.h>
 #include <glib.h>
 extern FILE *yyin;
+extern int   yylineno;
 int yylex(void);
 void yyerror(gpointer node, char const *s);
+static const char *name = NULL;
 static GList *code = NULL;
 static GList *data = NULL;
 %}
 %error-verbose
 %parse-param {gpointer root};
-%token START END DATA OUT
+%token START END DATA OUT FMT
 %%
 
 input : all | all input ;
 
-all   : data | code | print ;
+all   : data | code | out | fmt ;
 
 data  : DATA {
        static int i = 0;
@@ -29,21 +31,30 @@ data  : DATA {
 };
 
 code  : START DATA END {
+       code = g_list_prepend(code, g_strdup_printf("#line %d \"%s\"\n", yylineno, name));
        code = g_list_prepend(code, g_strdup_printf("%s\n", $2));
 };
 
-print : START OUT DATA END {
+out : START OUT DATA END {
+       code = g_list_prepend(code, g_strdup_printf("printf(\"%%s\", %s);\n", $3));
+};
+
+fmt : START FMT DATA END {
        code = g_list_prepend(code, g_strdup_printf("printf(%s);\n", $3));
 };
 
 %%
-gpointer parse(FILE *input, GList **_data, GList **_code) {
-       yyin = input;
+gpointer parse(const char *_name, FILE *_input,
+               GList **_data, GList **_code)
+{
+       name = _name;
+       yyin = _input;
        yyparse(NULL);
        *_data = data;
        *_code = code;
        return NULL;
 }
-void yyerror(gpointer root, char const *s) {
+void yyerror(gpointer root, char const *s)
+{
        g_error("[%s]\n", s);
 }