From f0b1f2625db64a5d97c0d0eeb272e30db0a1d10d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 11 Feb 2019 11:42:14 +0100 Subject: Apparently working grammar --- src/storycode.y | 132 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/storycode.y b/src/storycode.y index ee802c6..107e6d4 100644 --- a/src/storycode.y +++ b/src/storycode.y @@ -54,116 +54,120 @@ %% storycode: - %empty - | scblock storycode - ; + %empty +| storycode scblock +; scblock: - stylesheet { printf("That was the stylesheet\n"); } - | prestitle { printf("prestitle: '%s'\n", $1); } - | bulletpoint { printf("* '%s'\n", $1); } - | slide - | SC_STRING { printf("Text line '%s'\n", $1); } - ; + stylesheet { printf("That was the stylesheet\n"); } +| prestitle { printf("prestitle: '%s'\n", $1); } +| bulletpoint { printf("* '%s'\n", $1); } +| slide +| SC_STRING { printf("Text line '%s'\n", $1); } +; stylesheet: - SC_STYLES SC_OPENBRACE { printf("Here comes the stylesheet\n"); } - style_narrative { printf("Stylesheet - narrative\n"); } - style_slide { printf("Stylesheet - slide\n"); } - SC_CLOSEBRACE - ; + SC_STYLES SC_OPENBRACE { printf("Here comes the stylesheet\n"); } + style_narrative { printf("Stylesheet - narrative\n"); } + style_slide { printf("Stylesheet - slide\n"); } + SC_CLOSEBRACE +; /* Can be in narrative or slide */ prestitle: - SC_PRESTITLE SC_STRING { $$ = $2; } - ; + SC_PRESTITLE SC_STRING { $$ = $2; } +; bulletpoint: - SC_BP SC_STRING { $$ = $2; } - ; + SC_BP SC_STRING { $$ = $2; } +; /* ------ Slide contents ------ */ slide: - SC_SLIDE SC_OPENBRACE { printf("start of slide\n"); } - slide_parts - SC_CLOSEBRACE { printf("end of slide\n"); } - ; + SC_SLIDE SC_OPENBRACE { printf("start of slide\n"); } + slide_parts + SC_CLOSEBRACE { printf("end of slide\n"); } +; slide_parts: - %empty - | slide_part slide_parts - ; + %empty +| slide_parts slide_part +; slide_part: - prestitle | imageframe | textframe | SC_FOOTER | slidetitle - ; + prestitle +| imageframe +| textframe +| SC_FOOTER +| slidetitle +; imageframe: - SC_IMAGEFRAME frame_options SC_STRING - ; + SC_IMAGEFRAME frame_options SC_STRING { printf("image frame '%s'\n", $SC_STRING); } +; textframe: - SC_TEXTFRAME frame_options multi_line_string { printf("text frame '%s'\n", $1); } - ; + SC_TEXTFRAME frame_options multi_line_string { printf("text frame '%s'\n", $3); } +| SC_TEXTFRAME frame_options SC_OPENBRACE multi_line_string SC_CLOSEBRACE { printf("text frame m\n"); } multi_line_string: - SC_STRING - | SC_STRING multi_line_string - | bulletpoint - | bulletpoint multi_line_string - ; + SC_STRING { printf("string '%s'\n", $1); } +| multi_line_string SC_STRING { printf("more string '%s'\n", $2); } +| bulletpoint +| multi_line_string bulletpoint +; frame_options: - SC_FRAMEOPTS { printf("got some options: '%s'\n", $1); } - ; + SC_FRAMEOPTS { printf("got some options: '%s'\n", $1); } +; slidetitle: - SC_SLIDETITLE SC_STRING { $$ = $2; } - ; + SC_SLIDETITLE SC_STRING { $$ = $2; } +; /* ------ Stylesheet ------ */ style_narrative: - SC_NARRATIVE SC_OPENBRACE style_narrative_def SC_CLOSEBRACE { printf("narrative style\n"); } - ; + SC_NARRATIVE SC_OPENBRACE style_narrative_def SC_CLOSEBRACE { printf("narrative style\n"); } +; style_narrative_def: - %empty - | style_prestitle style_narrative_def - | styledef style_narrative_def - ; + %empty +| style_narrative_def style_prestitle +| style_narrative_def styledef +; style_slide: - SC_SLIDE SC_OPENBRACE style_slide_def SC_CLOSEBRACE { printf("slide style\n"); } - ; + SC_SLIDE SC_OPENBRACE style_slide_def SC_CLOSEBRACE { printf("slide style\n"); } +; style_slide_def: - %empty - | style_prestitle style_slide_def - | styledef style_slide_def - ; + %empty +| style_slide_def style_prestitle +| style_slide_def styledef +; style_prestitle: - SC_PRESTITLE SC_OPENBRACE styledefs SC_CLOSEBRACE { printf("prestitle style\n"); } - ; + SC_PRESTITLE SC_OPENBRACE styledefs SC_CLOSEBRACE { printf("prestitle style\n"); } +; styledefs: - %empty - | styledef styledefs - ; + %empty +| styledefs styledef +; styledef: - SC_FONT SC_STRING { printf("font def: '%s'\n", $2); } - | SC_TYPE SC_STRING { printf("type def: '%s'\n", $2); } - | SC_PAD SC_STRING { printf("pad def: '%s'\n", $2); } - | SC_FGCOL SC_STRING { printf("fgcol def: '%s'\n", $2); } - | SC_BGCOL SC_STRING { printf("bgcol def: '%s'\n", $2); } - | SC_ALIGN SC_STRING { printf("align def: '%s'\n", $2); } - ; + SC_FONT SC_STRING { printf("font def: '%s'\n", $2); } +| SC_TYPE SC_STRING { printf("type def: '%s'\n", $2); } +| SC_PAD SC_STRING { printf("pad def: '%s'\n", $2); } +| SC_FGCOL SC_STRING { printf("fgcol def: '%s'\n", $2); } +| SC_BGCOL SC_STRING { printf("bgcol def: '%s'\n", $2); } +| SC_ALIGN SC_STRING { printf("align def: '%s'\n", $2); } +; %% -- cgit v1.2.3