]> Pileus Git - ~andy/ct/blobdiff - parse.y
update knot
[~andy/ct] / parse.y
diff --git a/parse.y b/parse.y
index 84a62be4733e0062a3d2c80711507ca1b335d383..6415b057368a7f6e097c1bc5285185f0ee903024 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 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,16 +31,22 @@ 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(char *_name, FILE *_input, GList **_data, GList **_code) {
+       name = _name;
+       yyin = _input;
        yyparse(NULL);
        *_data = data;
        *_code = code;