Answer to Exercise 75

| ANSWER TO EXERCISE 75
| (Cf. the blackboard code in 'Toyshop'.)
    Global from_char; Global to_char;
    [ QuotedText i j f;
       i = parse->((++wn)*4-3);
       if (buffer->i=='"')
       {   for (j=i+1:j<=(buffer->1)+1:j++)
               if (buffer->j=='"') f=j;
           if (f==0) return -1;
           from_char = i+1; to_char=f-1;
           if (from_char>to_char) return -1;
           while (f> (parse->(wn*4-3))) wn++; wn++;
           return 0;
       }
       return -1;
    ];
Note that in the case of success, the word marker `wn` is moved beyond the last word accepted (since the Z-machine automatically tokenises a double-quote as a single word). The text is treated as though it were a preposition, and the positions where the quoted text starts and finishes in the raw text `buffer` are recorded, so that an action routine can easily extract the text and use it later. (Note that `""` with no text inside is not matched by this routine but only because the last `if` statement throws out that one case.)

Back to the exercise in section 27

Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.