Re: [NTG-context] doifnextcharelse

2016-01-24 Thread Wolfgang Schuster

Meer, Hans van der 
24. Januar 2016 um 15:58
Yes this works. But alas, the ultimate goal is to test against several 
characters and that seems impossible to do with standard ConTeXt 
api-macros.Let alone when these characters are . or . or ) etc.

\startluacode

function checknextstring(str)
if str == "a" then
context("A")
elseif str == "b" then
context("B")
else
context("??")
end
end

interfaces.implement { name = "readnextstring", actions = 
checknextstring,   arguments = "string" }


\stopluacode

\unprotect
\let\readnextstring\clf_readnextstring
\protect

\starttext

\readnextstring c
\readnextstring b
\readnextstring a
\readnextstring {xx}

\stoptext

Wolfgang
___
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  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] doifnextcharelse

2016-01-24 Thread Meer, Hans van der
Is it impossible to test on a blank with something alike  \doifnextcharelse ?

The implementation in the source skips blanks, but what if that is one doesn't 
want? For example to distinguish between "\abc \def" and \abc\def"?

Hans van der Meer



___
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  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] doifnextcharelse

2016-01-24 Thread Meer, Hans van der
Yes this works. But alas, the ultimate goal is to test against several 
characters and that seems impossible to do with standard ConTeXt api-macros.Let 
alone when these characters are . or . or ) etc.

Hans van der Meer

met vriendelijke groet
Hans van der Meer




> On 24 Jan 2016, at 15:13, Pablo Rodriguez  wrote:
> 
> On 01/24/2016 02:30 PM, dr. Hans van der Meer wrote:
>> I would like to differentiate on the following character being one of  X or 
>> not X.
>> But cannot get it right in \doifnextcharelse.
>> 
>> For example 
>> \def\mynextchar{\doifnextcharelse{X}{\def\Next{Y}}{\def\Next{Z}}\Next} 
>> delivers: ZX ZQ
>> then input: \mynextchar X \mynextchar Q
>> I hoped for YX ZQ, but it looks as if X tested false against X.
>> 
>> How to?
> 
> Hans,
> 
> the basic \def\mynextchar{\doifnextcharelse{x}{y}{z}} works.
> 
> With your sample:
> 
>\def\mynextchar{
>\doifnextcharelse{X}
>{\def\Next{Y}\Next}
>{\def\Next{Z}\Next}}
> 
> I hope it helps,
> 
> 
> Pablo
> -- 
> http://www.ousia.tk


___
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  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] doifnextcharelse

2016-01-24 Thread Pablo Rodriguez
On 01/24/2016 02:30 PM, dr. Hans van der Meer wrote:
> I would like to differentiate on the following character being one of  X or 
> not X.
> But cannot get it right in \doifnextcharelse.
> 
> For example 
> \def\mynextchar{\doifnextcharelse{X}{\def\Next{Y}}{\def\Next{Z}}\Next} 
> delivers: ZX ZQ
> then input: \mynextchar X \mynextchar Q
> I hoped for YX ZQ, but it looks as if X tested false against X.
> 
> How to?

Hans,

the basic \def\mynextchar{\doifnextcharelse{x}{y}{z}} works.

With your sample:

\def\mynextchar{
\doifnextcharelse{X}
{\def\Next{Y}\Next}
{\def\Next{Z}\Next}}

I hope it helps,


Pablo
-- 
http://www.ousia.tk
___
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  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

[NTG-context] doifnextcharelse

2016-01-24 Thread dr. Hans van der Meer
I would like to differentiate on the following character being one of  X or not 
X.
But cannot get it right in \doifnextcharelse.

For example 
\def\mynextchar{\doifnextcharelse{X}{\def\Next{Y}}{\def\Next{Z}}\Next} 
delivers: ZX ZQ
then input: \mynextchar X \mynextchar Q
I hoped for YX ZQ, but it looks as if X tested false against X.

How to?

Hans van der Meer

___
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  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] \doifnextcharelse problem

2004-02-27 Thread Hans Hagen
At 20:05 26/02/2004, you wrote:

commands CamelCased?
For third party extensions:

  - low level: \BNFsomething
  - high level: whatever you want (often the start/setup will not clash 
that much, maybe we need to setup a registration system)

for macros in documents:

  - \CamelCased

is fine

Hans  

___
ntg-context mailing list
[EMAIL PROTECTED]
http://www.ntg.nl/mailman/listinfo/ntg-context


[NTG-context] \doifnextcharelse problem

2004-02-26 Thread Nikolai Weibull
It seems that I can't get \definecomplexorsimpleempty to work right.
The command I define works fine unless the simple version is called, in
which case the first character in the body of the command is checked
\doifnextcharelse[... which thus fails but in some manner eats it (even
though it is output).  The problem with the \doifnextcharelse is that
the character it checks against is \catcode'd to \@@active, but it won't
work when the character has been checked.  Is there any way to fix this?

I understand if my problem isn't that clear, so I've attached the module.
The idea is to be able to write
  \startbnfgrammar
: .
: "0";"1".
  \stopbnfgrammar
and this is then typeset as a table, but currently you're forced to write
  \startbnfgrammar[]
: .
: "0";"1".
  \stopbnfgrammar
or the first < in  gets eaten by \doifnextcharelse and the
\def<{... won't be called causing problems down the line when the > is
encountered, which expands into a \egroup which stops tex as there is no
matching \bgroup.  Now, is there any way to get \doifnextcharelse to
properly deal with \catcode'd characters (such as my <) that it
encounters when looking for other characters (such as the [ for optional
arguments to commands)?  I'd really like to resolve this, so any
comments or tips are appreciated.

Second, is there any good reference to programming TeX?  I mean, one can
figure out most stuff from reading CONTEXT's source for example, but it
would be great to find out the exact implications of builtins such as
\relax and so on.
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);}


m-bnf.tex
Description: TeX document


Re: [NTG-context] \doifnextcharelse problem

2004-02-26 Thread Hans Hagen
At 17:38 26/02/2004, you wrote:

which case the first character in the body of the command is checked
\doifnextcharelse[... which thus fails but in some manner eats it (even
tricky indeed (will think about it)

go the etex way:

\definecomplexorsimpleempty\startbnfgrammar

\long\def\complexstartbnfgrammar[#1]#2\stopbnfgrammar
  {\bgroup%
   \global\firstruletrue%
   \global\newruletrue%
   \global\donerulefalse%
   \setupbnfgrammar[#1]%
   \setcatcodes%
   \starttable[|r|c|l|]\scantokens{#2}\LR\stoptable
   \egroup}
beware, use

\def\BNFsomecommand

to avoid future nameclashes; also, no % are needed after a \cs:

\long\def\complexstartbnfgrammar[#1]#2\stopbnfgrammar
  {\bgroup
   \global\firstruletrue
   \global\newruletrue
   \global\donerulefalse
   \setupbnfgrammar[#1]%
   \setcatcodes
   \starttable[|r|c|l|]\scantokens{#2}\LR\stoptable
   \egroup}
I assume that you know that \setcatcodes is an internal command

Hans  

___
ntg-context mailing list
[EMAIL PROTECTED]
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] \doifnextcharelse problem

2004-02-26 Thread Nikolai Weibull
* Hans Hagen <[EMAIL PROTECTED]> [Feb 26, 2004 19:10]:
> go the etex way:

great!  thanks, that worked.

> no % are needed after a \cs:

hm, OK.  This is a good reason why it would be good to have a tex
programming reference, so that one'd know when it's necessary and when
it's not.

> I assume that you know that \setcatcodes is an internal command

yeah, I saw it somewhere.  I figured that it was a good name though and
that I'd use it too.  I figured that the \unprotect deal with the
nameclash.  Am I, in fact, overruling the internal one now?  If so, how
should one avoid cases like this?  Should I have all my module's
commands CamelCased?

Also, is there some repository of CONTEXT modules out there?  I can't
find a reference on pragma-ade.com nor ntg.nl, but maybe I've missed it.
Anyway, thanks Hans for such a quick and thorough response, and also for
a great typesetting environment; TeX has never been easier,
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);}
___
ntg-context mailing list
[EMAIL PROTECTED]
http://www.ntg.nl/mailman/listinfo/ntg-context