aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sc2_test.c6
-rw-r--r--src/storycode.l (renamed from src/sc_lex.l)23
-rw-r--r--src/storycode.y (renamed from src/sc_parse.y)70
3 files changed, 33 insertions, 66 deletions
diff --git a/src/sc2_test.c b/src/sc2_test.c
index c8f016a..f626f26 100644
--- a/src/sc2_test.c
+++ b/src/sc2_test.c
@@ -26,7 +26,13 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include "storycode.h"
+
int main(int argc, char *argv[])
{
+ printf("Here goes...\n");
+ sc_scan_string("PRESTITLE: Hello\n");
+ scparse();
+ printf("Done.\n");
return 0;
}
diff --git a/src/sc_lex.l b/src/storycode.l
index a636588..80d1a70 100644
--- a/src/sc_lex.l
+++ b/src/storycode.l
@@ -1,5 +1,5 @@
/*
- * sc_lex.l
+ * storycode.l
*
* Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
*
@@ -21,18 +21,15 @@
*/
%{
- #include "sc_parse.tab.h"
-
+ #include "storycode.tab.h"
%}
+
+%option noyywrap nounput noinput
+
%%
-StoryCode { return STORYCODE; }
-type { return TYPE; }
-end { return END; }
-[ \t\n] ;
-[0-9]+\.[0-9]+ { sclval.fval = atof(yytext); return FLOAT; }
-[0-9]+ { sclval.ival = atoi(yytext); return INT; }
-[a-zA-Z0-9]+ {
- sclval.sval = strdup(yytext);
- return STRING;
-}
+
+STYLES { return SC_STYLES; }
+PRESTITLE { return SC_PRESTITLE; }
+[a-zA-Z0-9]+ { sclval = strdup(yytext); return SC_STRING; }
+
%%
diff --git a/src/sc_parse.y b/src/storycode.y
index cb881f6..25d7bc2 100644
--- a/src/sc_parse.y
+++ b/src/storycode.y
@@ -1,5 +1,5 @@
/*
- * sc2_parse.y
+ * storycode.y
*
* Copyright © 2019 Thomas White <taw@bitwiz.org.uk>
*
@@ -21,69 +21,33 @@
*/
%{
- // stuff from flex that bison needs to know about:
extern int sclex();
extern int scparse();
- extern FILE *scin;
-
void scerror(const char *s);
%}
-%union {
- int ival;
- float fval;
- char *sval;
-}
-
-%token STORYCODE TYPE
-%token END
-
-%token <ival> INT
-%token <fval> FLOAT
-%token <sval> STRING
+%define api.value.type {char *}
+%token SC_STYLES
+%token SC_PRESTITLE
+%token SC_STRING
%%
storycode:
- header template body_section footer {
- printf("End of storycode\n");
- }
- ;
-header:
- STORYCODE FLOAT {
- printf("Reading Storycode version $2\n");
- }
- ;
-template:
- typelines
- ;
-typelines:
- typelines typeline
- | typeline
- ;
-typeline:
- TYPE STRING {
- printf("type\n");
- free($2);
- }
- ;
-body_section:
- body_lines
- ;
-body_lines:
- body_lines body_line
- | body_line
- ;
-body_line:
- INT INT INT INT STRING {
- printf("type\n");
- free($5);
- }
- ;
-footer:
- END
+ %empty
+ | scblock '\n' storycode { printf("End of storycode\n"); }
;
+scblock:
+ stylesheet
+ | prestitle
+
+stylesheet:
+ SC_STYLES ':'
+
+prestitle:
+ SC_PRESTITLE ':' SC_STRING { printf("Presentation title: '%s'\n", $1); }
+
%%
void scerror(const char *s) {