From 24c20239779d0ec616adde651c594c7bf08d58c7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 19 Feb 2019 18:17:56 +0100 Subject: WIP --- libstorycode/storycode.y | 51 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'libstorycode/storycode.y') diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 654dec3..433b158 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -44,6 +44,7 @@ %{ #include + #include extern int sclex(); extern int scparse(); @@ -75,10 +76,8 @@ %type stylesheet %type prestitle %type STRING -%type textframe %type imageframe %type bulletpoint -%type multi_line_string %type frameopt %type geometry /* FIXME: Should have its own type */ %type slidetitle @@ -93,12 +92,33 @@ ctx->n = narrative_new(); ctx->ss = stylesheet_new(); ctx->s = slide_new(); + + ctx->n_str = 0; + ctx->max_str = 32; + ctx->str = malloc(ctx->max_str*sizeof(char *)); + if ( ctx->str == NULL ) ctx->max_str = 0; } %{ void frameopts_reset(struct scpctx *ctx) { } + + void str_reset(struct scpctx *ctx) + { + ctx->n_str = 0; + } + + void add_str(struct scpctx *ctx, char *str) + { + if ( ctx->n_str == ctx->max_str ) { + char **nstr = realloc(ctx->str, (ctx->max_str+32)*sizeof(char *)); + if ( nstr == NULL ) return; + ctx->max_str += 32; + } + + ctx->str[ctx->n_str++] = str; + } %} %% @@ -148,11 +168,15 @@ slide_parts: ; slide_part: - prestitle { slide_add_prestitle(ctx->s, $1); } -| imageframe { slide_add_image(ctx->s, $1, ctx->geom); frameopts_reset(ctx); } -| textframe { slide_add_text(ctx->s, $1, ctx->geom); frameopts_reset(ctx); } + prestitle { slide_add_prestitle(ctx->s, $1); str_reset(ctx); } +| imageframe { slide_add_image(ctx->s, $1, ctx->geom); + frameopts_reset(ctx); + str_reset(ctx); } +| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, ctx->geom); + frameopts_reset(ctx); + str_reset(ctx); } | FOOTER { slide_add_footer(ctx->s); } -| slidetitle { slide_add_slidetitle(ctx->s, $1); } +| slidetitle { slide_add_slidetitle(ctx->s, $1); str_reset(ctx); } ; imageframe: @@ -160,14 +184,15 @@ imageframe: ; textframe: - TEXTFRAME frame_options multi_line_string { printf("text frame '%s'\n", $3); } -| TEXTFRAME frame_options OPENBRACE multi_line_string CLOSEBRACE { printf("text frame m\n"); } + TEXTFRAME frame_options multi_line_string { } +| TEXTFRAME frame_options OPENBRACE multi_line_string CLOSEBRACE { } +; multi_line_string: - STRING { printf("string '%s'\n", $1); } -| multi_line_string STRING { printf("more string '%s'\n", $2); } -| bulletpoint { printf("string *%s\n", $1); } -| multi_line_string bulletpoint { printf("more string *%s\n", $1); } + STRING { add_str(ctx, $1); } +| multi_line_string STRING { add_str(ctx, $2); } +| bulletpoint { add_str(ctx, $1); } +| multi_line_string bulletpoint { add_str(ctx, $2); } ; /* There can be any number of options */ @@ -178,7 +203,7 @@ frame_options: /* Each option is enclosed in square brackets */ frame_option: - SQOPEN frameopt SQCLOSE { printf("got an option: '%s'\n", $2); } + SQOPEN frameopt SQCLOSE { } ; frameopt: -- cgit v1.2.3