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


In reply to Stopping a package from infesting my namespace by anneli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.