ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater <taco@elvenkind.com>
To: Taco Hoekwater <taco@elvenkind.com>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: {{ double braces }}
Date: Sat, 26 Jan 2008 12:41:52 +0100	[thread overview]
Message-ID: <479B1C80.3080509@elvenkind.com> (raw)
In-Reply-To: <479B10F5.6090309@elvenkind.com>

Taco Hoekwater wrote:
> 
> with lpeg, the code looks a bit harder, but is still short and
> relatively shortforward:

Here is a smarter lpeg that takes care of embedded \{ as well:

   local P, S, V = lpeg.P, lpeg.S, lpeg.V
   local matchtable = {
      "TEXT",
      TEXT = (V("FOOTNOTE") + 1)^0 * -1,
      SP = S(" \n\t")^0,
      BODY = "{"*(P("\\{")+P("\\}")+(1 - S("{}"))+V("BODY"))^0*"}",
      FOOTNOTE = "\\footnote" * V("SP") * V("BODY") / print,
   }
   lpeg.match(matchtable, data)

Quick explanation:

the symbol + is alternation, * is concatenation, - is exclusion,
^ is a repeat modifier, "" and P("") match strings, numbers
match bytes, S("") matches byte sets.

the "matchtable" describes the input data. In there,
matchtable[1] points to the "top" rule, which is "TEXT".
The other key-value pairs in the table say roughly this:

TEXT = an optional sequence [^0] of either footnote items
        [V("FOOTNOTE")] or non-footnote bytes [1], until
        the end of the data is reached [-1]
FOOTNOTE = the string '\footnote', followed by optional
        space, followed by the footnote body.
SP = zero or more occurrences of a space, tab, or newline byte
BODY = a left brace, followed by an optional sequence of
        four possible things:
        1. the string "\{" [P("\\{")]
        2. the string "\}" [P("\\}")]
        3. a byte that is not "{" nor "}"  [(1 - S("{}"))]
        4. a recursively included braced body [V("BODY")],
        followed by a right brace.

The [/print] runs the print() command on each successful
FOOTNOTE match.

Best wishes,
Taco

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


      reply	other threads:[~2008-01-26 11:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-21 14:45 Steffen Wolfrum
2008-01-21 15:02 ` Mikael Persson
2008-01-21 15:53   ` Steffen Wolfrum
2008-01-23 20:49 ` Peter Münster
2008-01-23 21:50   ` Peter Münster
2008-01-23 22:17     ` Thomas A. Schmitz
2008-01-23 23:19       ` Aditya Mahajan
2008-01-26 10:11         ` Thomas A. Schmitz
2008-02-06  7:01           ` Aditya Mahajan
2008-02-06  9:11             ` Steffen Wolfrum
2008-02-06 16:36               ` Aditya Mahajan
2008-02-06 19:20                 ` Hans van der Meer
2008-02-06 20:01                   ` Steffen Wolfrum
2008-02-06 20:16                     ` Hans van der Meer
2008-02-06 20:17               ` Otared Kavian
2008-02-12 15:09             ` Thomas A. Schmitz
2008-02-12 15:15               ` Hans Hagen
2008-02-12 17:39                 ` Aditya Mahajan
2008-02-13  8:39                   ` Taco Hoekwater
2008-02-13  9:31                     ` luigi scarso
2008-02-13 10:21                       ` Taco Hoekwater
2008-02-13 10:38                         ` luigi scarso
2008-01-26 10:52       ` Taco Hoekwater
2008-01-26 11:41         ` Taco Hoekwater [this message]

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=479B1C80.3080509@elvenkind.com \
    --to=taco@elvenkind.com \
    --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).