]> Pileus Git - ~andy/ct/commitdiff
I forget what these changes do
authorAndy Spencer <andy753421@gmail.com>
Wed, 21 Dec 2011 06:28:52 +0000 (06:28 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 03:38:31 +0000 (03:38 +0000)
(but they're obviously better)

ct.c
example/html.ct
knot/overhand.txt
parse.y
scan.l

diff --git a/ct.c b/ct.c
index 93eac2e425d3073dca322f99ebbf5faa9c229fa0..b9114a9b256182de7a3fdf0307d8d965a35a4500 100644 (file)
--- a/ct.c
+++ b/ct.c
@@ -4,10 +4,12 @@
 
 #include "parse.h"
 
-gpointer parse(FILE *input, GList **data, GList **code);
+gpointer parse(FILE *input, const char *name,
+               GList **data, GList **code);
 
 int main(int argc, char **argv)
 {
+       const char *name = "stdin";
         /* Parse arguments */
         char *option_output = NULL;
         GOptionEntry entries[] = {
@@ -21,8 +23,10 @@ int main(int argc, char **argv)
 
        /* Handle input and output */
        FILE *input = stdin;
-       if (argv[1] && !g_str_equal(input, "-"))
+       if (argv[1] && !g_str_equal(input, "-")) {
+               name  = argv[1];
                input = fopen(argv[1], "r");
+       }
        if (!input)
                g_error("invalid input file");
 
@@ -41,7 +45,7 @@ int main(int argc, char **argv)
        /* Start compiling */
        GList *data = NULL;
        GList *code = NULL;
-       parse(input, &data, &code);
+       parse(input, name, &data, &code);
        data = g_list_reverse(data);
        code = g_list_reverse(code);
 
index d08df11c5cb526ab27c5093be231cd82465b2565..7f36cc9746f1670e9eaa525f19360cfaadf3e46a 100644 (file)
@@ -11,6 +11,8 @@ Content-Type: application/xhtml+xml; charset=UTF-8
 <html>
        <body>
                <% body(); %>
+
+               <a><%= "%05.2f" %></a>
        </body>
 </html>
 <% } %>
index 6dc976d7a18f8d53ab85a020110dbb3e99816e5c..de5057ba9141ce846980d5337f357f23a404ec0c 100644 (file)
@@ -2,3 +2,18 @@
 .-|-
 '|'
  |
+
+ _ _
+( \ )
+ / /
+/ " \
+
+-. _ _ .-
+  \ \ \
+  \" "/
+   '-'
+
+  _ _
+ / \ \
+--' '|-
+ '---'
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);
 }
diff --git a/scan.l b/scan.l
index c1b61e7082daf98c6828748d41aab2d7de71e67a..44e7af6d89245bf28b6a298f8949697793d61a8d 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -7,17 +7,19 @@
 %option noyywrap
 %option nounput
 %option noinput
+%option yylineno
 /* %option nodebug */
 START [ \t]*<%
-END   [ \t]*%>[ \t]*
+END   [ \t]*%>
 DATA  ([^<\n]|<[^%])*\n*
 CODE  [ \t\n]([^%\n]|%[^>])*\n*
-%s IN FMT
+%s IN
 %%
 [[:space:]]*\n   { debug("NL    [%s]"); }
 <INITIAL>{START} { debug("START [%s]"); yylval = g_strdup(yytext); BEGIN(IN);      return START; }
 <INITIAL>{DATA}  { debug("DATA  [%s]"); yylval = g_strdup(yytext);                 return DATA;  }
 <IN>{END}        { debug("END   [%s]"); yylval = g_strdup(yytext); BEGIN(INITIAL); return END;   }
 <IN>=            { debug("OUT   [%s]"); yylval = g_strdup(yytext);                 return OUT;   }
+<IN>%            { debug("FMT   [%s]"); yylval = g_strdup(yytext);                 return FMT;   }
 <IN>{CODE}       { debug("CODE  [%s]"); yylval = g_strdup(yytext);                 return DATA;  }
 %%