ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
Cc: gundlach@irb.cs.uni-dortmund.de, ntg-context@ntg.nl
Subject: Re: xml comments
Date: Tue, 27 Nov 2001 10:43:54 +0100	[thread overview]
Message-ID: <5.1.0.14.1.20011127104108.02f06868@server-1> (raw)
In-Reply-To: <20011127093741.6f948a32.taco@elvenkind.com>

At 09:37 AM 11/27/2001 +0100, Taco Hoekwater wrote:
>"Hans Hagen" <pragma@wxs.nl> wrote:
> > At 03:20 PM 11/26/2001 +0100, Patrick Gundlach wrote:
> > >Hi,
> > >
> > >xml comments have a bug (!?): spaces are critical at the
> > >beginning of a comment.
> >
> > you may try (and play with):
> >
> > \long\def\xparseXMLescape !#1#2#3{\parseXMLescape{#1#2}#3}
>
>Adding #3 is safe, sort of. <! is always followed by one of the language's
>keywords, and <!-- is by far the shortest of those. Just watch out
>that <!----> is a valid comment (although very unlikely to appear).
>
>The string "<!-- crap -->" is actually a comment that starts with
>a space. The comment itself in this case is: " crap ".
>
>It is possible to take advantage of the fact that '<!--' is the only
>keyword that starts with the same character twice, so the 'best' thing
>to do is something along these lines:
>
>\long\def\xparseXMLescape!#1#2%
>   {\if#1#2%
>      \@EA\handleXMLcomment
>     \else
>      \@EA\doxparseXMLescape
>     \fi#1#2}
>
>\def\handleXMLcomment--#1-->{}
>
>\def\doxparseXMLescape#1 {\parseXMLescape{#1}}

yesterday i found out that i needed both alternatives , so i came up with:

\long\def\xparseXMLescape !#1#2%
   {\if#1-%
      \if#2-%
        \expandafter\expandafter\expandafter\xxparseXMLescape
      \else
        \expandafter\expandafter\expandafter\xyparseXMLescape
      \fi
    \else
      \expandafter\xyparseXMLescape
    \fi#1#2}

\long\def\xxparseXMLescape --#1{\parseXMLescape{--}#1}
\long\def\xyparseXMLescape #1  {\parseXMLescape{#1}}

so far this one works ok.

indeed, if we assume that #1 and #1 are the same and -, we can have a 
faster alternative, but we may want to play safe. How does this keyword 
mechanism work? Are there only officially registered ones?

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


  reply	other threads:[~2001-11-27  9:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-26 14:20 Patrick Gundlach
2001-11-26 15:03 ` Hans Hagen
2001-11-26 15:07 ` Hans Hagen
2001-11-27  8:37   ` Taco Hoekwater
2001-11-27  9:43     ` Hans Hagen [this message]
2001-11-27 13:21       ` Taco Hoekwater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.1.20011127104108.02f06868@server-1 \
    --to=pragma@wxs.nl \
    --cc=gundlach@irb.cs.uni-dortmund.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).