diff options
| -rw-r--r-- | error.c | 5 | ||||
| -rw-r--r-- | halibut.h | 1 | ||||
| -rw-r--r-- | input.c | 43 |
3 files changed, 37 insertions, 12 deletions
@@ -117,6 +117,11 @@ static void do_error(int code, va_list ap) { sprintf(error, "expected `}' after cross-reference"); flags = FILEPOS; break; + case err_codequote: + fpos = *va_arg(ap, filepos *); + sprintf(error, "unable to nest \\q{...} within \\c{...} or \\cw{...}"); + flags = FILEPOS; + break; case err_missingrbrace: fpos = *va_arg(ap, filepos *); sprintf(error, "unclosed braces at end of paragraph"); @@ -221,6 +221,7 @@ enum { err_explbr, /* expected `{' after command */ err_commenteof, /* EOF inside braced comment */ err_kwexprbr, /* expected `}' after cross-ref */ + err_codequote, /* \q within \c is not supported */ err_missingrbrace, /* unclosed braces at end of para */ err_missingrbrace2, /* unclosed braces at end of file */ err_nestedstyles, /* unable to nest text styles */ @@ -612,6 +612,7 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) { word **whptr; /* to restore from \u alternatives */ word **idximplicit; /* to restore from \u alternatives */ filepos fpos; + int in_code; } *sitem; stack parsestk; struct crossparaitem { @@ -1201,21 +1202,39 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) { if (t.type != tok_lbrace) { error(err_explbr, &t.pos); } else { - wd.text = NULL; - wd.type = toquotestyle(style); - wd.alt = NULL; - wd.aux = quote_Open; - wd.fpos = t.pos; - wd.breaks = FALSE; - if (!indexing || index_visible) - addword(wd, &whptr); - if (indexing) { - rdadd(&indexstr, L'"'); - addword(wd, &idximplicit); + /* + * Enforce that \q may not be used anywhere + * within \c. (It shouldn't be necessary + * since the whole point of \c should be + * that the user wants to exercise exact + * control over the glyphs used, and + * forbidding it has the useful effect of + * relieving some backends of having to + * make difficult decisions.) + */ + int stype; + + if (style != word_Code && style != word_WeakCode) { + wd.text = NULL; + wd.type = toquotestyle(style); + wd.alt = NULL; + wd.aux = quote_Open; + wd.fpos = t.pos; + wd.breaks = FALSE; + if (!indexing || index_visible) + addword(wd, &whptr); + if (indexing) { + rdadd(&indexstr, L'"'); + addword(wd, &idximplicit); + } + stype = stack_quote; + } else { + error(err_codequote, &t.pos); + stype = stack_nop; } sitem = snew(struct stack_item); sitem->fpos = t.pos; - sitem->type = stack_quote; + sitem->type = stype; stk_push(parsestk, sitem); } break; |