aboutsummaryrefslogtreecommitdiff
path: root/libstorycode
diff options
context:
space:
mode:
Diffstat (limited to 'libstorycode')
-rw-r--r--libstorycode/narrative.c30
-rw-r--r--libstorycode/narrative.h31
-rw-r--r--libstorycode/storycode.l65
-rw-r--r--libstorycode/storycode.y202
4 files changed, 328 insertions, 0 deletions
diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c
new file mode 100644
index 0000000..971af82
--- /dev/null
+++ b/libstorycode/narrative.c
@@ -0,0 +1,30 @@
+/*
+ * narrative.c
+ *
+ * Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
diff --git a/libstorycode/narrative.h b/libstorycode/narrative.h
new file mode 100644
index 0000000..096ace5
--- /dev/null
+++ b/libstorycode/narrative.h
@@ -0,0 +1,31 @@
+/*
+ * narrative.h
+ *
+ * Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef NARRATIVE_H
+#define NARRATIVE_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#endif /* NARRATIVE_H */
diff --git a/libstorycode/storycode.l b/libstorycode/storycode.l
new file mode 100644
index 0000000..a64fbec
--- /dev/null
+++ b/libstorycode/storycode.l
@@ -0,0 +1,65 @@
+/*
+ * storycode.l
+ *
+ * Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+%{
+ #define YYDEBUG 1
+ #include "storycode.tab.h"
+%}
+
+%option noyywrap nounput noinput
+%s string
+
+%%
+
+STYLES { return SC_STYLES; }
+PRESTITLE { return SC_PRESTITLE; }
+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; }
+(?i:left) { return SC_LEFT; }
+(?i:center) { return SC_CENTER; }
+(?i:right) { return SC_RIGHT; }
+<string>.*\n { sclval = strdup(yytext); sclval[yyleng-1] = '\0'; BEGIN(0); return SC_STRING; }
+"[" { return SC_SQOPEN; }
+"]" { return SC_SQCLOSE; }
+:[ ] { BEGIN(string); }
+:\n { sclval = strdup(""); return SC_STRING; }
+[{] { return SC_OPENBRACE; }
+[}] { return SC_CLOSEBRACE; }
+[.\n ] {}
+[0-9\.]+ { /* FIXME: lval */ return SC_VALUE; }
+[uf] { return SC_UNIT; }
+[+] { return SC_PLUS; }
+[x] { return SC_TIMES; }
+
+
+%%
diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y
new file mode 100644
index 0000000..625f080
--- /dev/null
+++ b/libstorycode/storycode.y
@@ -0,0 +1,202 @@
+/*
+ * storycode.y
+ *
+ * Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+%{
+ extern int sclex();
+ extern int scparse();
+ void scerror(const char *s);
+%}
+
+%define api.value.type {char *}
+%define api.token.prefix {SC_}
+%token STYLES SLIDE
+%token NARRATIVE
+%token PRESTITLE
+%token SLIDETITLE
+%token FOOTER
+%token TEXTFRAME
+%token IMAGEFRAME
+%token BP
+
+%token FONT TYPE PAD ALIGN FGCOL BGCOL
+
+%token LEFT CENTER RIGHT
+
+%token STRING
+%token OPENBRACE CLOSEBRACE
+%token SQOPEN SQCLOSE
+%token PLUS TIMES
+%token UNIT VALUE
+
+%%
+
+presentation:
+ stylesheet narrative
+| narrative
+;
+
+narrative:
+ narrative_el
+| narrative narrative_el
+;
+
+narrative_el:
+ prestitle { printf("prestitle: '%s'\n", $1); }
+| bulletpoint { printf("* '%s'\n", $1); }
+| slide
+| STRING { printf("Text line '%s'\n", $1); }
+;
+
+/* Can be in narrative or slide */
+
+prestitle:
+ PRESTITLE STRING { $$ = $2; }
+;
+
+bulletpoint:
+ BP STRING { $$ = $2; }
+;
+
+
+/* ------ Slide contents ------ */
+
+slide:
+ SLIDE OPENBRACE { printf("start of slide\n"); }
+ slide_parts
+ CLOSEBRACE { printf("end of slide\n"); }
+;
+
+slide_parts:
+ %empty
+| slide_parts slide_part
+;
+
+slide_part:
+ prestitle
+| imageframe
+| textframe
+| FOOTER
+| slidetitle
+;
+
+imageframe:
+ IMAGEFRAME frame_options STRING { printf("image frame '%s'\n", $STRING); }
+;
+
+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"); }
+
+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); }
+;
+
+/* There can be any number of options */
+frame_options:
+ %empty
+| frame_options frame_option
+;
+
+/* Each option is enclosed in square brackets */
+frame_option:
+ SQOPEN frameopt SQCLOSE { printf("got an option: '%s'\n", $2); }
+;
+
+frameopt:
+ geometry
+| alignment
+;
+
+geometry:
+ length TIMES length PLUS length PLUS length { $$ = "geom"; printf("Geometry\n"); }
+;
+
+alignment:
+ LEFT
+| CENTER
+| RIGHT
+;
+
+slidetitle:
+ SLIDETITLE STRING { $$ = $2; }
+;
+
+length:
+ VALUE UNIT
+;
+
+
+/* ------ Stylesheet ------ */
+
+stylesheet:
+ STYLES OPENBRACE { printf("Here comes the stylesheet\n"); }
+ style_narrative { printf("Stylesheet - narrative\n"); }
+ style_slide { printf("Stylesheet - slide\n"); }
+ CLOSEBRACE
+;
+
+style_narrative:
+ NARRATIVE OPENBRACE style_narrative_def CLOSEBRACE { printf("narrative style\n"); }
+;
+
+style_narrative_def:
+ %empty
+| style_narrative_def style_prestitle
+| style_narrative_def styledef
+;
+
+style_slide:
+ SLIDE OPENBRACE style_slide_def CLOSEBRACE { printf("slide style\n"); }
+;
+
+style_slide_def:
+ %empty
+| style_slide_def style_prestitle
+| style_slide_def styledef
+;
+
+style_prestitle:
+ PRESTITLE OPENBRACE styledefs CLOSEBRACE { printf("prestitle style\n"); }
+;
+
+styledefs:
+ %empty
+| styledefs styledef
+;
+
+styledef:
+ FONT STRING { printf("font def: '%s'\n", $2); }
+| TYPE STRING { printf("type def: '%s'\n", $2); }
+| PAD STRING { printf("pad def: '%s'\n", $2); }
+| FGCOL STRING { printf("fgcol def: '%s'\n", $2); }
+| BGCOL STRING { printf("bgcol def: '%s'\n", $2); }
+| ALIGN STRING { printf("align def: '%s'\n", $2); }
+;
+
+%%
+
+void scerror(const char *s) {
+ printf("Error\n");
+}