From fc089b188d701d7361e3fe5d1606a006bd18745a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 30 Sep 2019 22:15:40 +0200 Subject: Concatenate multiple RUN_TEXTs within emphasis blocks --- libstorycode/storycode.y | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 943ba27..44a308a 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -113,6 +113,7 @@ %type text_line_with_start %type text_run %type RUN_TEXT +%type one_or_more_runs %type FONTNAME %type imageframe @@ -281,16 +282,29 @@ text_line: { $$.n_runs = 0; * _hello *there_, world* */ -/* FIXME: Adjacent RUN_TEXTs should be concatenated, otherwise escaped characters - * within modifiers won't work: - * *hello \\ backslash* - * = '*' RUN_TEXT RUN_TEXT RUN_TEXT '*' - */ text_run: RUN_TEXT { $$.text = $1; $$.type = TEXT_RUN_NORMAL; } -| '*' RUN_TEXT '*' { $$.text = $2; $$.type = TEXT_RUN_BOLD; } -| '/' RUN_TEXT '/' { $$.text = $2; $$.type = TEXT_RUN_ITALIC; } -| '_' RUN_TEXT '_' { $$.text = $2; $$.type = TEXT_RUN_UNDERLINE; } +| '*' one_or_more_runs '*' { $$.text = $2; $$.type = TEXT_RUN_BOLD; } +| '/' one_or_more_runs '/' { $$.text = $2; $$.type = TEXT_RUN_ITALIC; } +| '_' one_or_more_runs '_' { $$.text = $2; $$.type = TEXT_RUN_UNDERLINE; } + +one_or_more_runs: + RUN_TEXT { $$ = $1; } +| one_or_more_runs RUN_TEXT { char *nt; + size_t len; + len = strlen($1) + strlen($2) + 1; + nt = malloc(len); + if ( nt != NULL ) { + nt[0] = '\0'; + strcat(nt, $1); + strcat(nt, $2); + free($1); + $$ = nt; + } else { + $$ = strdup("ERROR"); + } + } +; /* -------- Slide -------- */ -- cgit v1.2.3