In my BNF module I use " as an active character that begins and ends terminals in the grammar:
<regex>: <branch> ; <branch>, "|", <regex>.
Now, the above doesn't quite work as written, as \ is still active (and so is, in fact | as we're really inside a \starttabulate.
What I would like for the "" pair to do is work as a wrapper for \type{}, so that everything in-between is passed on to \type{}. Is there a way of getting them to do that?
This is my current definition:
\gdef"% {\ifBNFoutsidestring% \global\BNFoutsidestringfalse% \begingroup% \BNFunsetcatcodes% \catcode`"@@active% @@bnfterminalstart% \else% @@bnfterminalstop% \endgroup% \global\BNFoutsidestringtrue% \fi}
I figured something like
\long\gdef"#1"% {\type{#1}}
might work, but it didn't. It chokes on "." where . is also an activated character for terminating a production in the grammar.
Any suggestions on how to go about this? I mean, the obvious solution is simply to write
<regex>: <branch> ; <branch>, "\type{|}", <regex>.
instead, but I would like to keep the input as clean as possible. nikolai
-- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
At 01:20 30/05/2004, you wrote:
In my BNF module I use " as an active character that begins and ends terminals in the grammar:
<regex>: <branch> ; <branch>, "|", <regex>.
Now, the above doesn't quite work as written, as \ is still active (and so is, in fact | as we're really inside a \starttabulate.
What I would like for the "" pair to do is work as a wrapper for \type{}, so that everything in-between is passed on to \type{}. Is there a way of getting them to do that?
This is my current definition:
\gdef"% {\ifBNFoutsidestring% \global\BNFoutsidestringfalse% \begingroup% \BNFunsetcatcodes% \catcode`"@@active% @@bnfterminalstart% \else% @@bnfterminalstop% \endgroup% \global\BNFoutsidestringtrue% \fi}
I figured something like
\long\gdef"#1"% {\type{#1}}
might work, but it didn't. It chokes on "." where . is also an activated character for terminating a production in the grammar.
Any suggestions on how to go about this? I mean, the obvious solution is simply to write
<regex>: <branch> ; <branch>, "\type{|}", <regex>.
instead, but I would like to keep the input as clean as possible. nikolai
\definestartstop[BNF][before=\startlines\setups{myBNF},after=\stoplines]
\startsetups[myBNF] \defineactivecharacter " {\bgroup\tttf\setupinlineverbatim\defineactivecharacter " {\egroup}} \defineactivecharacter < {\mathematics{\string<}} \defineactivecharacter > {\mathematics{\string>}} \stopsetups
\starttext
\startBNF <regex>: <branch> ; <branch>, "|", <regex>. \stopBNF
\stoptext
(cross your fingers that this does not interfere with reading files, but normally < > " are taken care of)
an alternative is to write a plugin forthe verbatim environment (see verb-ini to get an idea of what nasty things are involved with catcode changes).
Hans
* Hans Hagen pragma@wxs.nl [Jun 01, 2004 21:20]:
\definestartstop[BNF][before=\startlines\setups{myBNF},after=\stoplines]
\startsetups[myBNF] \defineactivecharacter " {\bgroup\tttf\setupinlineverbatim\defineactivecharacter " {\egroup}} \defineactivecharacter < {\mathematics{\string<}} \defineactivecharacter > {\mathematics{\string>}} \stopsetups
\starttext
\startBNF <regex>: <branch> ; <branch>, "|", <regex>. \stopBNF
\stoptext
(cross your fingers that this does not interfere with reading files, but normally < > " are taken care of)
It actually worked! Thank you so much for the example. I'll probably rewrite my module a bit to work more like your example above actually, but it even worked in the context of my module. Wow, this really saved my ass.
an alternative is to write a plugin forthe verbatim environment (see verb-ini to get an idea of what nasty things are involved with catcode changes).
Yeah, I was thinking of that actually, but didn't realize it as a possibility until I'd written a lot of code...guess I should rethink now.
Thank you Hans, nikolai
-- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
Nikolai Weibull context-list@pcppopper.org writes:
[...]
\startBNF <regex>: <branch> ; <branch>, "|", <regex>. \stopBNF
[...]
It actually worked! Thank you so much for the example. I'll probably rewrite my module a bit to work more like your example above actually,
[...]
So, did you complete your module? Is it ready for the public yet?
Patrick
* Patrick Gundlach pg@levana.de [Jun 23, 2004 17:12]:
So, did you complete your module? Is it ready for the public yet?
Yes. I haven't put it anywhere yet, but here's the 0.3 version of it. It even includes working module documentation! Read the =README for more information.
Thank you for showing interest, nikolai -- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
Hello Nikolai,
after I loooong time I finally managed to try your bnf module. It looks very good. And it even works with \mainlanguage[de] (it wasn't obvious, because you use "..." as a delimiter).
Thanks for it,
Patrick
(Hehe, one has to love age-old threads that are still active ;-)
* Patrick Gundlach patrick@gundla.ch [Dec 02, 2004 15:30]:
after I loooong time I finally managed to try your bnf module. It looks very good. And it even works with \mainlanguage[de] (it wasn't obvious, because you use "..." as a delimiter).
Thank you, I hope to make it _the_ BNF module for ConTeXt some day ;-). About the delimiters, if you know of a better way to do this, then please tell me, I've gone through about 3 different ways of doing this, but the current one, using \defineactivecharacter, has worked best so far. nikolai
Nikolai Weibull wrote:
(Hehe, one has to love age-old threads that are still active ;-)
- Patrick Gundlach patrick@gundla.ch [Dec 02, 2004 15:30]:
after I loooong time I finally managed to try your bnf module. It looks very good. And it even works with \mainlanguage[de] (it wasn't obvious, because you use "..." as a delimiter).
Thank you, I hope to make it _the_ BNF module for ConTeXt some day ;-). About the delimiters, if you know of a better way to do this, then please tell me, I've gone through about 3 different ways of doing this, but the current one, using \defineactivecharacter, has worked best so far.
i haven't looked into it but since it's a language, i can imagine that you misuse that fact: \language[bnf] or so, since languages can have specifics (active things) and encodings associated; you just don't have patterns then
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 -----------------------------------------------------------------