From 2453ffa05850d5c498dd900a4f66749e6d0c8989 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 7 Feb 2019 21:59:01 +0100 Subject: WIP --- src/sc2_test.c | 6 +++++- src/storycode.l | 5 ++++- src/storycode.y | 13 ++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sc2_test.c b/src/sc2_test.c index f626f26..5db89c4 100644 --- a/src/sc2_test.c +++ b/src/sc2_test.c @@ -26,13 +26,17 @@ #include #include +#include "storycode.tab.h" #include "storycode.h" int main(int argc, char *argv[]) { + YY_BUFFER_STATE b; + printf("Here goes...\n"); - sc_scan_string("PRESTITLE: Hello\n"); + b = sc_scan_string("PRESTITLE: Hi there\nPRESTITLE: Second title\nSTYLES:\nPRESTITLE: three"); scparse(); + sc_delete_buffer(b); printf("Done.\n"); return 0; } diff --git a/src/storycode.l b/src/storycode.l index 80d1a70..16a2375 100644 --- a/src/storycode.l +++ b/src/storycode.l @@ -30,6 +30,9 @@ STYLES { return SC_STYLES; } PRESTITLE { return SC_PRESTITLE; } -[a-zA-Z0-9]+ { sclval = strdup(yytext); return SC_STRING; } +: { return SC_COLON; } +:[ ] { return SC_COLONSPACE; } +[a-zA-Z0-9 ]+ { sclval = strdup(yytext); return SC_STRING; } +[\n] { return SC_NEWLINE; } %% diff --git a/src/storycode.y b/src/storycode.y index 25d7bc2..a5dd68a 100644 --- a/src/storycode.y +++ b/src/storycode.y @@ -29,24 +29,31 @@ %define api.value.type {char *} %token SC_STYLES %token SC_PRESTITLE +%token SC_COLON %token SC_STRING +%token SC_NEWLINE +%token SC_COLONSPACE %% storycode: %empty - | scblock '\n' storycode { printf("End of storycode\n"); } + | scblock + | scblock SC_NEWLINE storycode ; scblock: stylesheet | prestitle + ; stylesheet: - SC_STYLES ':' + SC_STYLES SC_COLON { printf("Stylesheet.\n"); } + ; prestitle: - SC_PRESTITLE ':' SC_STRING { printf("Presentation title: '%s'\n", $1); } + SC_PRESTITLE SC_COLONSPACE SC_STRING { printf("Presentation title: '%s'\n", $3); } + ; %% -- cgit v1.2.3