summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-03-25 19:27:12 +0000
committerSimon Tatham <anakin@pobox.com>2004-03-25 19:27:12 +0000
commit6b06f96f6c5e70a952e923a3d154f82402ec5cce (patch)
treed95e5b6635b71b8523bb8961cd7f28e8abf9fb02
parent10f4d6055c80f45b538cfc6657994b31e4abf525 (diff)
downloadhalibut-6b06f96f6c5e70a952e923a3d154f82402ec5cce.zip
halibut-6b06f96f6c5e70a952e923a3d154f82402ec5cce.tar.gz
halibut-6b06f96f6c5e70a952e923a3d154f82402ec5cce.tar.bz2
halibut-6b06f96f6c5e70a952e923a3d154f82402ec5cce.tar.xz
Introduce \. as a NOP command. The purpose of this is to act as a
zero-width delimiter between a macro invocation and text beyond it, so that you can define (say) a macro which expands to a Euro sign and then write `\eur\.2500' to avoid having space between the Euro sign and the number. [originally from svn r3982]
-rw-r--r--doc/input.but15
-rw-r--r--input.c9
-rw-r--r--inputs/test.but6
3 files changed, 26 insertions, 4 deletions
diff --git a/doc/input.but b/doc/input.but
index 587836f..7755d57 100644
--- a/doc/input.but
+++ b/doc/input.but
@@ -1201,8 +1201,19 @@ macro, using the \c{\\define} command:
\c \define{eur} \u20AC{EUR }
-Then you can just write
+Then you can just write ...
\c This is likely to cost \eur 2500 at least.
-\# FIXME: need a NOP to allow text to directly follow this. \.?
+... except that that's not terribly good, because you end up with a
+space between the Euro sign and the number. In this case, it's
+helpful to use the special \c{\\.} command, which is defined to do
+nothing at all! But it acts as a separator between your macro and
+the next character:
+
+\c This is likely to cost \eur\.2500 at least.
+
+This way, you will see no space between the Euro sign and the number
+(although, of course, there will be space between \q{EUR} and the
+number if the Euro sign is not available, because the macro
+definition specifically asked for it).
diff --git a/input.c b/input.c
index 9d165fa..95a7709 100644
--- a/input.c
+++ b/input.c
@@ -162,6 +162,7 @@ enum {
c__invalid, /* invalid command */
c__comment, /* comment command (\#) */
c__escaped, /* escaped character */
+ c__nop, /* no-op */
c__nbsp, /* nonbreaking space */
c_A, /* appendix heading */
c_B, /* bibliography entry */
@@ -231,6 +232,7 @@ static void match_kw(token *tok) {
static const struct { char const *name; int id; } keywords[] = {
{"#", c__comment}, /* comment command (\#) */
{"-", c__escaped}, /* nonbreaking hyphen */
+ {".", c__nop}, /* no-op */
{"A", c_A}, /* appendix heading */
{"B", c_B}, /* bibliography entry */
{"BR", c_BR}, /* bibliography rewrite */
@@ -360,7 +362,7 @@ token get_token(input *in) {
} else if (c == '\\') { /* tok_cmd */
c = get(in, &cpos);
if (c == '-' || c == '\\' || c == '_' ||
- c == '#' || c == '{' || c == '}') {
+ c == '#' || c == '{' || c == '}' || c == '.') {
/* single-char command */
rdadd(&rs, c);
} else if (c == 'u') {
@@ -905,6 +907,11 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx) {
break;
}
+ if (t.type == tok_cmd && t.cmd == c__nop) {
+ dtor(t), t = get_token(in);
+ continue; /* do nothing! */
+ }
+
if (t.type == tok_cmd && t.cmd == c__escaped) {
t.type = tok_word; /* nice and simple */
t.aux = 0; /* even if `\-' - nonbreaking! */
diff --git a/inputs/test.but b/inputs/test.but
index 683d19b..9eb469d 100644
--- a/inputs/test.but
+++ b/inputs/test.but
@@ -25,7 +25,9 @@ a bit]
\define{coopt} co\u00F6{-o}pt
-\versionid $Id: test.but,v 1.22 2004/03/25 19:16:28 simon Exp $
+\define{eur} \u20AC{EUR }
+
+\versionid $Id: test.but,v 1.23 2004/03/25 19:27:12 simon Exp $
\C{ch\\ap} First chapter title; for similar wrapping reasons this
chapter title will be ludicrously long. I wonder how much more
@@ -154,6 +156,8 @@ A\_paragraph\_full\_of\_nonbreaking\_spaces\_to\_test\_the\_idea\_that\_word\_wr
Use of macros: let's talk about \coopt. And about \coopt some more.
And a nested macro: \metacoopt.
+A slightly more difficult macro: \eur\.2500.
+
Oh, while I'm here: some special characters. The \\, \{ and \}
characters, to be precise. And their code equivalents, \c{\\},
\i\c{\{}, \c{\}}.