]> Pileus Git - ~andy/ct/blobdiff - parse.y
I forget what these changes do
[~andy/ct] / parse.y
diff --git a/parse.y b/parse.y
index 84a62be4733e0062a3d2c80711507ca1b335d383..f4ce105bea9f2d94b79aab66c5473e963bdaf352 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -5,12 +5,14 @@
 extern FILE *yyin;
 int yylex(void);
 void yyerror(gpointer node, char const *s);
-static GList *code = NULL;
-static GList *data = NULL;
+extern int yylineno;
+static const char *name;
+static GList *code;
+static GList *data;
 %}
 %error-verbose
 %parse-param {gpointer root};
-%token START END DATA OUT
+%token START END DATA FMT OUT
 %%
 
 input : all | all input ;
@@ -20,11 +22,13 @@ all   : data | code | print ;
 data  : DATA {
        static int i = 0;
        data = g_list_prepend(data, g_strdup_printf(
+               "#line %d \"%s\"\n"
                "static char data%d[] = \"%s\";\n",
-               i, g_strescape($1, "")));
+               yylineno, name, i, g_strescape($1, "")));
        code = g_list_prepend(code, g_strdup_printf(
+               "#line %d \"%s\"\n"
                "fwrite(data%d, sizeof(data%d)-1, 1, stdout);\n",
-               i, i));
+               yylineno, name, i, i));
        i++;
 };
 
@@ -32,18 +36,26 @@ code  : START DATA END {
        code = g_list_prepend(code, g_strdup_printf("%s\n", $2));
 };
 
-print : START OUT DATA END {
+print : START FMT DATA END {
        code = g_list_prepend(code, g_strdup_printf("printf(%s);\n", $3));
 };
 
+print : START OUT DATA END {
+       code = g_list_prepend(code, g_strdup_printf("printf(\"%%s\", %s);\n", $3));
+};
+
 %%
-gpointer parse(FILE *input, GList **_data, GList **_code) {
+gpointer parse(FILE *input, const char *_name,
+               GList **_data, GList **_code)
+{
        yyin = input;
+       name = _name;
        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);
 }