Re: [gtk-list] Re: g_scanner funtions what for?
- From: Tim Janik <timj gtk org>
- To: Andreas Tille <tille physik uni-halle de>
- cc: GTK User-List <gtk-list redhat com>
- Subject: Re: [gtk-list] Re: g_scanner funtions what for?
- Date: Wed, 17 Mar 1999 15:47:04 +0100 (CET)
On Wed, 17 Mar 1999, Andreas Tille wrote:
> On Wed, 17 Mar 1999, Tim Janik wrote:
>
> > andreas, look at this more closely, lets s/scanner->token/foo/,
> > s/G_TOKEN_FLOAT/1/ and s/G_TOKEN_STRING/2/:
> >
> > if (foo != 1 || foo != 2)
> > ...
> >
> > literally:
> > IF foo is not equal to 1 OR foo is not equal to 2
> >
> > so to get beyond this condition, you require scanner->token to be
> > ==G_TOKEN_FLOAT *and* ==G_TOKEN_STRING at the same time, obviously impossible.
> >
> > so if at all, you want
> > if (scanner->token != G_TOKEN_FLOAT && scanner->token != G_TOKEN_STRING)
> ... stupid mistake of mine
>
> > but i doubt that this is your problem, see below.
> in dead.
>
> > > If I set "Datum: J02161999\n" (the '-' int the former string caused trouble)
> > > or
> > >
> > > test text:1: error: scanner: digit is beyond radix
> > >
> > > if I leave "Datum: 02161999\n" ... a string of spaces only. I expect
> > > that I have to configure the scanner to read strings (like a date or
> > > a name), but I can't find any way how to do that.
> >
> > you need to understand that the scanner will parse it's input and
> > tokenize it, it is up to you to interpret these tokens, not define
> > their types before they get parsed, e.g. watch gscanner parse a string:
> [... detailed and very helpful explanation snipped ...]
> It seems me that I quite understand the working and so I tried to
> modify your ping-pong example step by step. I failed when deleting
> the ';' as line delimiter. Would you please have a look at the
> example what is wrong in my interpretation?
#ifdef _I_WANT_IN_DEAD_A_SEMIKOLON_
/* make sure the next token is a ';' */
if (g_scanner_peek_next_token (scanner) != ';')
{
/* not so, eat up the non-semicolon and error out */
g_scanner_get_next_token (scanner);
return ';';
}
#endif
g_scanner_get_next_token (scanner);
will always read the next token into scanner->token, but
g_scanner_peek_next_token() will only make sure that
scanner->next_token is up to date, to actually *read* it
you have to call g_scanner_get_next_token() again, the token
is then moved from scanner->next_token to scanner->token.
so g_scanner_peek_next_token() alowes for a one-token-look-ahead
so before the switch, i asure that the next token is a ';' with checking
the g_scanner_peek_next_token() return value (or scanner->next_token for
taht matter).
then the example switch() es on the current token type and grabs it's value
and after the switch, i do
g_scanner_get_next_token (scanner);
without an extra check, because i *know* this is the ';', i checked that in
advance. so you need to also
switch ()
{
.......
}
#ifdef _I_WANT_IN_DEAD_A_SEMIKOLON_
g_scanner_get_next_token (scanner);
#endif
after the switch.
>
> Kind regards
>
> Andreas.
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]