ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* regexp for matching entire footnotes
@ 2006-07-30  5:45 Steffen Wolfrum
  2006-07-30  7:08 ` Peter Münster
  2006-07-30 12:27 ` Sanjoy Mahajan
  0 siblings, 2 replies; 4+ messages in thread
From: Steffen Wolfrum @ 2006-07-30  5:45 UTC (permalink / raw)


Hi,

I have to find (highlight) footnotes with the entire footnote being  
marked/highlighted.
Constructing a regexp for this is far beyond what I can write, that's  
why I frankly ask for help here:

The problems are the (potentially) nested pairs of curled brackets  
(like for \index, \emphasize etc etc) ...

\footnote{Vgl. zur Historie \it{Name}, „Staatssekretär\index 
{Staatssekretär}}

... as the found string shouldn't stop at the first "}" that was found.


Somebody knows a syntax that ignores curled bracket pairs *included*  
in footnotes and really matches the entire note?


Steffen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regexp for matching entire footnotes
  2006-07-30  5:45 regexp for matching entire footnotes Steffen Wolfrum
@ 2006-07-30  7:08 ` Peter Münster
  2006-07-30 12:27 ` Sanjoy Mahajan
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Münster @ 2006-07-30  7:08 UTC (permalink / raw)


On Sun, 30 Jul 2006, Steffen Wolfrum wrote:

> Somebody knows a syntax that ignores curled bracket pairs *included*  
> in footnotes and really matches the entire note?

Perhaps, a regular expression is not the right tool for your needs, but you
could try something like
'[\]footnote\{[^{}]*([^{}]*\{[^{}]*\}[^{}]*)*[^{}]*\}'.
Cheers, Peter

-- 
http://pmrb.free.fr/contact/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regexp for matching entire footnotes
  2006-07-30  5:45 regexp for matching entire footnotes Steffen Wolfrum
  2006-07-30  7:08 ` Peter Münster
@ 2006-07-30 12:27 ` Sanjoy Mahajan
  2006-07-30 19:28   ` Hans Hagen
  1 sibling, 1 reply; 4+ messages in thread
From: Sanjoy Mahajan @ 2006-07-30 12:27 UTC (permalink / raw)


> I have to find (highlight) footnotes with the entire footnote being
> marked/highlighted.  The problems are the (potentially) nested pairs
> of curled brackets (like for \index, \emphasize etc etc) ...

I'm not sure what you mean by marking or highlighting the footnote.
Do you mean in the printed document, or in the source file so that you
can find and change them in some way?

> Constructing a regexp for this is far beyond what I can write,

In the Chomsky hierarchy of grammars, regular languages, which are
recognized by regexps, are below context-free grammars (CFGs).
Compared to regular languages, CFGs add a stack.  And you need a stack
to parse nested delimiters, otherwise you can't tell whether a closing
brace closes the first opening brace.  So no regexp can do what you
hope for.

You could:

1. Use emacs (or your favorite editor) to substitute \myfootnote for
   \footnote, and do some ConTeXt setup magic to make \myfootnote be
   just like \footnote except that it highlights.

2. Use Emacs, which can find balanced braces, to make a keyboard macro
   (start defining it with "C-x (").  Then:
   a. search for \footnote.  Now the point will be between the 'e'
      and the opening '{'.
   b. C-@ to set the mark.
   c. C-M-f ("alt-ctrl-f" to run 'forward-sexp') to move to the
      closing brace.  Now you'll have highlighted the {...} stuff of
      the \footnote.
   d. C-x ) to end the keyboard macro definition.

   Then you can use C-x e to go to and highlight the next footnote
   material.

But I'm not sure either is what you're trying to do?

-Sanjoy

`Never underestimate the evil of which men of power are capable.'
         --Bertrand Russell, _War Crimes in Vietnam_, chapter 1.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: regexp for matching entire footnotes
  2006-07-30 12:27 ` Sanjoy Mahajan
@ 2006-07-30 19:28   ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2006-07-30 19:28 UTC (permalink / raw)


Sanjoy Mahajan wrote:
>> I have to find (highlight) footnotes with the entire footnote being
>> marked/highlighted.  The problems are the (potentially) nested pairs
>> of curled brackets (like for \index, \emphasize etc etc) ...
>>     
>
> I'm not sure what you mean by marking or highlighting the footnote.
> Do you mean in the printed document, or in the source file so that you
> can find and change them in some way?
>
>   
>> Constructing a regexp for this is far beyond what I can write,
>>     
>
> In the Chomsky hierarchy of grammars, regular languages, which are
> recognized by regexps, are below context-free grammars (CFGs).
> Compared to regular languages, CFGs add a stack.  And you need a stack
> to parse nested delimiters, otherwise you can't tell whether a closing
> brace closes the first opening brace.  So no regexp can do what you
> hope for.
>   
lua reg exps have a way do handle nested () {} []
> You could:
>
> 1. Use emacs (or your favorite editor) to substitute \myfootnote for
>    \footnote, and do some ConTeXt setup magic to make \myfootnote be
>    just like \footnote except that it highlights.
>
> 2. Use Emacs, which can find balanced braces, to make a keyboard macro
>    (start defining it with "C-x (").  Then:
>    a. search for \footnote.  Now the point will be between the 'e'
>       and the opening '{'.
>    b. C-@ to set the mark.
>    c. C-M-f ("alt-ctrl-f" to run 'forward-sexp') to move to the
>       closing brace.  Now you'll have highlighted the {...} stuff of
>       the \footnote.
>    d. C-x ) to end the keyboard macro definition.
>
>    Then you can use C-x e to go to and highlight the next footnote
>    material.
>
> But I'm not sure either is what you're trying to do?
>   
a multistep approach is possible: 

- mark each { } with something that reflects nesting (say <{1> <{2> <}2>    <}1> etc
- you can now distinguish matching pairs and take some action
- afterwards you convert the <..> things back to { } 

(at least that is how i did such thing until now in e.g. ruby) 

Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-07-30 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-30  5:45 regexp for matching entire footnotes Steffen Wolfrum
2006-07-30  7:08 ` Peter Münster
2006-07-30 12:27 ` Sanjoy Mahajan
2006-07-30 19:28   ` Hans Hagen

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).