anneli has asked for the wisdom of the Perl Monks concerning the following question:
Dear sisters and brothers,
I'm using Parse::Lex to generate lexers for a lexer/parser for Erlang source that I'm writing.
Fortunately or unfortunately, when you bootstrap a Lex object, it creates symbol table entries in the calling package for the tokens you've defined for the lexer. The code doing that is Parse/Token.pm, saying:
sub exportTo { my $self = shift; my $inpkg = $self->inpkg; unless (defined $inpkg) { $inpkg = caller; # (caller(0))[0]; $self->inpkg($inpkg); } my $name = $self->name; no strict 'refs'; if ($^W and defined ${"$inpkg" . "::" . "$name"}) { require Carp; Carp::carp "the '${inpkg}::$name' token is already defined"; } ${"$inpkg" . "::" . "$name"} = $self; $self; }
I'm trying to make my generated lexers at least vaguely re-entrant, so the lexer symbol table is being recreated each time you make a new lexer, meaning I'm getting these lovely "the 'XYZ::ABC' token is already defined" errors. It looks like there's no such thing as an anonymous package, so I can't enter one of those before generating the symbols.
Is there other way (possibly involving black magic) to get these tokens to go elsewhere, or otherwise stop this happening? (preferably without having to mess up Parse::Lex)
Yours in deep respect,
Anneli
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Stopping a package from infesting my namespace
by armstd (Friar) on Oct 08, 2011 at 22:37 UTC | |
by anneli (Pilgrim) on Oct 08, 2011 at 23:37 UTC | |
by armstd (Friar) on Oct 09, 2011 at 02:20 UTC | |
by anneli (Pilgrim) on Oct 09, 2011 at 03:34 UTC | |
Re: Stopping a package from infesting my namespace
by GrandFather (Saint) on Oct 09, 2011 at 00:04 UTC | |
by anneli (Pilgrim) on Oct 09, 2011 at 03:37 UTC | |
Re: Stopping a package from infesting my namespace
by Jenda (Abbot) on Oct 10, 2011 at 11:59 UTC | |
by anneli (Pilgrim) on Oct 10, 2011 at 21:31 UTC |