aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-10 10:59:20 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-10 10:59:20 +0100
commitb94dd665e3cc321a7deba7458fbb8cd1196d262c (patch)
treeefeb8035e1c7f68f12e31fa457e461bece471427 /src
parent2453ffa05850d5c498dd900a4f66749e6d0c8989 (diff)
Mostly working grammar
Diffstat (limited to 'src')
-rw-r--r--src/sc2_test.c17
-rw-r--r--src/storycode.l27
-rw-r--r--src/storycode.y126
3 files changed, 157 insertions, 13 deletions
diff --git a/src/sc2_test.c b/src/sc2_test.c
index 5db89c4..6f9977f 100644
--- a/src/sc2_test.c
+++ b/src/sc2_test.c
@@ -25,18 +25,33 @@
#include <stdlib.h>
#include <glib.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include "storycode.tab.h"
#include "storycode.h"
+extern int scdebug;
+
int main(int argc, char *argv[])
{
YY_BUFFER_STATE b;
+ GFile *file;
+ GBytes *bytes;
+ const char *text;
+ size_t len;
+
+ file = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/demo.sc");
+ bytes = g_file_load_bytes(file, NULL, NULL, NULL);
+ text = g_bytes_get_data(bytes, &len);
+ //scdebug = 1;
printf("Here goes...\n");
- b = sc_scan_string("PRESTITLE: Hi there\nPRESTITLE: Second title\nSTYLES:\nPRESTITLE: three");
+ b = sc_scan_string(text);
scparse();
sc_delete_buffer(b);
printf("Done.\n");
+
+ g_bytes_unref(bytes);
+
return 0;
}
diff --git a/src/storycode.l b/src/storycode.l
index 16a2375..e470daa 100644
--- a/src/storycode.l
+++ b/src/storycode.l
@@ -21,18 +21,37 @@
*/
%{
+ #define YYDEBUG 1
#include "storycode.tab.h"
%}
%option noyywrap nounput noinput
+%s string
%%
STYLES { return SC_STYLES; }
PRESTITLE { return SC_PRESTITLE; }
-: { return SC_COLON; }
-:[ ] { return SC_COLONSPACE; }
-[a-zA-Z0-9 ]+ { sclval = strdup(yytext); return SC_STRING; }
-[\n] { return SC_NEWLINE; }
+SLIDETITLE { return SC_SLIDETITLE; }
+NARRATIVE { return SC_NARRATIVE; }
+SLIDE { return SC_SLIDE; }
+BP { return SC_BP; }
+TYPE { return SC_TYPE; }
+TEXT { return SC_TEXTFRAME; }
+IMAGE { return SC_IMAGEFRAME; }
+FOOTER { return SC_FOOTER; }
+FONT { return SC_FONT; }
+PAD { return SC_PAD; }
+ALIGN { return SC_ALIGN; }
+FGCOL { return SC_FGCOL; }
+BGCOL { return SC_BGCOL; }
+<string>.*\n { sclval = strdup(yytext); sclval[yyleng-1] = '\0'; BEGIN(0); return SC_STRING; }
+"[".*"]" { sclval = strdup(yytext); return SC_FRAMEOPTS; }
+:[ ] { BEGIN(string); }
+:\n { sclval = strdup(""); return SC_STRING; }
+[{] { return SC_OPENBRACE; }
+[}] { return SC_CLOSEBRACE; }
+[.\n ] {}
+
%%
diff --git a/src/storycode.y b/src/storycode.y
index a5dd68a..ee802c6 100644
--- a/src/storycode.y
+++ b/src/storycode.y
@@ -28,31 +28,141 @@
%define api.value.type {char *}
%token SC_STYLES
+%token SC_SLIDE
+%token SC_NARRATIVE
%token SC_PRESTITLE
-%token SC_COLON
+%token SC_SLIDETITLE
+%token SC_FOOTER
+%token SC_TEXTFRAME
+%token SC_IMAGEFRAME
+%token SC_BP
+
+%token SC_FRAMEOPTS
+
+%token SC_FONT
+%token SC_TYPE
+%token SC_PAD
+%token SC_ALIGN
+%token SC_FGCOL
+%token SC_BGCOL
+
%token SC_STRING
%token SC_NEWLINE
-%token SC_COLONSPACE
+%token SC_OPENBRACE
+%token SC_CLOSEBRACE
%%
storycode:
%empty
- | scblock
- | scblock SC_NEWLINE storycode
+ | scblock storycode
;
scblock:
- stylesheet
- | prestitle
+ 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_COLON { printf("Stylesheet.\n"); }
+ 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_COLONSPACE SC_STRING { printf("Presentation title: '%s'\n", $3); }
+ SC_PRESTITLE SC_STRING { $$ = $2; }
+ ;
+
+bulletpoint:
+ 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"); }
+ ;
+
+slide_parts:
+ %empty
+ | slide_part slide_parts
+ ;
+
+slide_part:
+ prestitle | imageframe | textframe | SC_FOOTER | slidetitle
+ ;
+
+imageframe:
+ SC_IMAGEFRAME frame_options SC_STRING
+ ;
+
+textframe:
+ SC_TEXTFRAME frame_options multi_line_string { printf("text frame '%s'\n", $1); }
+ ;
+
+multi_line_string:
+ SC_STRING
+ | SC_STRING multi_line_string
+ | bulletpoint
+ | bulletpoint multi_line_string
+ ;
+
+frame_options:
+ SC_FRAMEOPTS { printf("got some options: '%s'\n", $1); }
+ ;
+
+slidetitle:
+ SC_SLIDETITLE SC_STRING { $$ = $2; }
+ ;
+
+
+/* ------ Stylesheet ------ */
+
+style_narrative:
+ 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
+ ;
+
+style_slide:
+ 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
+ ;
+
+style_prestitle:
+ SC_PRESTITLE SC_OPENBRACE styledefs SC_CLOSEBRACE { printf("prestitle style\n"); }
+ ;
+
+styledefs:
+ %empty
+ | styledef styledefs
+ ;
+
+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); }
;
%%