On 16 June 2010 00:03, Ross Boylan <[email protected]> wrote:
> During my parsing (with PetitParser) I'd like to retain some context as
> I go.  A simple example would be the current line number, which gets
> incremented at line ends.  A more complex example would be a current
> list of variables.
>
> I can avoid the whole problem by only retaining state after the parse
> tree is constructed, i.e., when I walk the tree.  Is it just a bad idea
> to do anything else?
>
> The methods I've thought of, and their drawbacks are
> * use a global variable (ugly and requires only one active parse at a
> time)
> * keep the state in the stream I'm parsing with a special stream class
> that holds a regular stream and the state (not sure all parsers would
> have access to the stream; requires more hacks for parse: to work, as
> opposed to parseOn:)
> * make special parser subclasses, each of which refers to the shared
> state (lots of work and lots of extra classes; possibly I'd have one
> special parser that held the state and an arbitrary real parser)
> * black magic walking up the call stack (I think Seaside uses this, but
> I'd rather avoid black magic).
> Many of these approaches might also slow things down, particularly if I
> did quick and dirty implementations that used doesNotUnderstand: to do
> the delegation for the 2nd and 3rd options.
>

I am using a parse tokens in own parser, which capturing a token's source range.
In similar manner, token could capture a line number(s) as well, or
simply reconstruct
the line number after tokenization.

> Ross Boylan
>
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



-- 
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to