From 77ef611a5a6ee3bf7456d0fb5f26f708b8433971 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 23 Feb 2019 16:44:51 +0100 Subject: Give line number in error message --- libstorycode/storycode.l | 14 +++++++++++--- libstorycode/storycode.y | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libstorycode/storycode.l b/libstorycode/storycode.l index 792637d..98f8f6a 100644 --- a/libstorycode/storycode.l +++ b/libstorycode/storycode.l @@ -29,6 +29,8 @@ #include "stylesheet.h" #include "storycode_parse.h" + + int lineno = 0; %} %option prefix="sc" @@ -56,14 +58,20 @@ SIZE { return SC_SIZE; } (?i:left) { return SC_LEFT; } (?i:center) { return SC_CENTER; } (?i:right) { return SC_RIGHT; } -.*\n { sclval.str = strdup(yytext); sclval.str[yyleng-1] = '\0'; BEGIN(0); return SC_STRING; } +.*\n { sclval.str = strdup(yytext); + sclval.str[yyleng-1] = '\0'; + BEGIN(0); + lineno++; + return SC_STRING; } "[" { return SC_SQOPEN; } "]" { return SC_SQCLOSE; } +":" { return SC_COLON; } :[ ] { BEGIN(string); } -:\n { sclval.str = strdup(""); return SC_STRING; } +:\n { sclval.str = strdup(""); lineno++; ;return SC_STRING; } [{] { return SC_OPENBRACE; } [}] { return SC_CLOSEBRACE; } -[.\n ] {} +[. ] {} +\n { lineno++; } [0-9\.]+ { sclval.val = atof(yytext); return SC_VALUE; } [uf] { sclval.character = yytext[0]; return SC_UNIT; } [+] { return SC_PLUS; } diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 1062794..b2b2afa 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -53,6 +53,7 @@ extern int sclex(); extern int scparse(); void scerror(struct scpctx *ctx, const char *s); + extern int lineno; %} %token STYLES SLIDE @@ -306,5 +307,5 @@ styledef: %% void scerror(struct scpctx *ctx, const char *s) { - printf("Storycode parse error at %i-%i\n", yylloc.first_line, yylloc.first_column); + printf("Storycode parse error at line %i\n", lineno); } -- cgit v1.2.3