From 0a146090aa9dc02f5568e9c314e11ab69b40d225 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 25 Feb 2019 20:15:27 +0100 Subject: Reorganise grammar a little bit --- libstorycode/storycode.y | 65 +++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 4199a4c..724a779 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -79,10 +79,12 @@ %type narrative %type slide %type stylesheet -%type prestitle +%type narrative_prestitle +%type slide_prestitle %type STRING %type imageframe -%type bulletpoint +%type slide_bulletpoint +%type narrative_bulletpoint %type frameopt %type geometry %type lenquad @@ -168,36 +170,38 @@ void set_style(struct scpctx *ctx, enum style_element element) %% +/* The only thing a "presentation" really needs is narrative */ presentation: stylesheet narrative { presentation_add_stylesheet(ctx->p, ctx->ss); presentation_add_narrative(ctx->p, ctx->n); } | narrative { presentation_add_narrative(ctx->p, ctx->n); } ; + +/* ------ Narrative ------ */ + narrative: narrative_el { } | narrative narrative_el { } ; narrative_el: - prestitle { narrative_add_prestitle(ctx->n, $1); } -| bulletpoint { narrative_add_bp(ctx->n, $1); } -| slide { narrative_add_slide(ctx->n, $1); } -| STRING { narrative_add_text(ctx->n, $1); } + narrative_prestitle { narrative_add_prestitle(ctx->n, $1); } +| narrative_bulletpoint { narrative_add_bp(ctx->n, $1); } +| slide { narrative_add_slide(ctx->n, $1); } +| STRING { narrative_add_text(ctx->n, $1); } ; -/* Can be in narrative or slide */ - -prestitle: +narrative_prestitle: PRESTITLE STRING { $$ = $2; } ; -bulletpoint: +narrative_bulletpoint: BP STRING { $$ = $2; } ; -/* ------ Slide contents ------ */ +/* -------- Slide -------- */ slide: SLIDE '{' slide_parts '}' { presentation_add_slide(ctx->p, ctx->s); @@ -212,13 +216,17 @@ slide_parts: ; slide_part: - prestitle { slide_add_prestitle(ctx->s, $1); str_reset(ctx); } -| imageframe { slide_add_image(ctx->s, $1, ctx->geom); - str_reset(ctx); } -| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, ctx->geom); - str_reset(ctx); } -| FOOTER { slide_add_footer(ctx->s); } -| slidetitle { slide_add_slidetitle(ctx->s, $1); str_reset(ctx); } + slide_prestitle { slide_add_prestitle(ctx->s, $1); str_reset(ctx); } +| imageframe { slide_add_image(ctx->s, $1, ctx->geom); + str_reset(ctx); } +| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, ctx->geom); + str_reset(ctx); } +| FOOTER { slide_add_footer(ctx->s); } +| slidetitle { slide_add_slidetitle(ctx->s, $1); str_reset(ctx); } +; + +slide_prestitle: + PRESTITLE STRING { $$ = $2; } ; imageframe: @@ -231,10 +239,18 @@ textframe: ; multi_line_string: - 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); } + STRING { add_str(ctx, $1); } +| multi_line_string STRING { add_str(ctx, $2); } +| slide_bulletpoint { add_str(ctx, $1); } +| multi_line_string slide_bulletpoint { add_str(ctx, $2); } +; + +slide_bulletpoint: + BP STRING { $$ = $2; } +; + +slidetitle: + SLIDETITLE STRING { $$ = $2; } ; /* There can be any number of options */ @@ -253,6 +269,7 @@ frameopt: | alignment { ctx->alignment = $1; } ; +/* Primitives for describing styles (used in frame options and stylesheets) */ geometry: length 'x' length '+' length '+' length { $$.w = $1; $$.h = $3; $$.x = $5; $$.y = $7; } @@ -279,10 +296,6 @@ alignment: | RIGHT { $$ = ALIGN_RIGHT; } ; -slidetitle: - SLIDETITLE STRING { $$ = $2; } -; - length: VALUE UNIT { $$.len = $VALUE; if ( $UNIT == 'u' ) $$.unit = LENGTH_UNIT; -- cgit v1.2.3