I understand optimize mode correctly. The one problem I have with it is that
it will *write* the lextab file on every instantiation of the lexer. While
it will *read* the lextab file (as it should), it should not *write* one if
it has already *read* one, as the file may be in a place it no longer has
write permissions to. All I am trying to do is make sure that if lex.py *
read* a lextab to build a parser, it will not end by *writing* the lextab
file, which is at best spinning the disk and at worst results in silly error
messages (*Permission denied*).
What I meant by "not maintained" is the the google-code list of bugs doesn't
seem to be doing anything, and I didn't know if filing another would
actually lead to anything. Has the project moved from google code? Should I
open a bug anyway?
BTW, my current workaround for this bug is:
# Stupid workaround
import sys
__ = sys.stderr
class Dummy:
write = lambda x: None
sys.stderr = Dummy
lex.lex(outputdir=_p[:-6]+"/build", optimize=1)
sys.stderr = __
Basically, reassigns stderr while I create the lexer so that the error
message (*Permission denied*) will not show up.
- Pavel Panchekha
On Wed, Aug 26, 2009 at 5:28 PM, David Beazley <[email protected]> wrote:
>
> I think you're not quite understanding the whole point of optimize
> mode. The primary use of optimize is to be able to run with Python -O
> and -OO flags. The latter flag has the property of stripping
> documentation strings---rendering PLY inoperable as it uses
> documentation strings for picking up grammar rules and other
> details. In order to run in those modes, you set optimize=True and
> run your program once in order to create the corresponding lextab.py
> or parsetab.py files. Once you have done that, you make sure that
> those files are always distributed with your code.
>
> I'll look at this further, but I don't think PLY's current behavior is
> a bug.
>
> Cheers,
> Dave
>
> P.S. If you don't submit a patch, it will never be incorporated into
> any version. Just because PLY releases aren't put out every week
> doesn't mean that I'm not working on it or maintaining it.
>
>
>
>
> On Aug 26, 2009, at 3:25 PM, Pavel Panchekha wrote:
>
> >
> > I've found a simple fix for the issue.
> >
> > --------
> > After line 901, add line (properly indented):
> > readfile = True
> >
> > After line 905, add line (properly indented):
> > readfile = False
> >
> > Alter line 1003 to say (properly indented):
> > if lextab and optimize and not readfile:
> > ---------
> >
> > I'd submit a patch but the developer doesn't seem that active.
> >
> > On Aug 26, 4:08 pm, Pavel Panchekha <[email protected]> wrote:
> >> Hmm, after taking a while to look through all of these, none actually
> >> address the fundamental issue I'm talking about.
> >> It's not that I need help writing out the tables, that's fine. I just
> >> need to stop lex.py from trying to write the lextab file, even in
> >> optimize mode.
> >>
> >> On Aug 20, 2:03 am, "D.Hendriks (Dennis)" <[email protected]> wrote:
> >>
> >>> Hello Pavel,
> >>
> >>> A quick search resulted in these earlier discussions, which may be
> >>> of
> >>> interest to you:
> >>
> >>> http://groups.google.com/group/ply-hack/browse_frm/thread/a799e10f9c2
> >>> ...
> >>
> >>> These earlier discussions deal among others with disabling table
> >>> files
> >>> alltogether.
> >>
> >>> The last one is an earlier post that I once posted. It is about
> >>> PlyWrapper, a wrapper around Ply that takes care of table files
> >>> and has
> >>> functionality for generating them on command, which I use in my
> >>> project
> >>> to write tables during installation, at which time the appropriate
> >>> rights are available.
> >>
> >>> Best,
> >>> Dennis
> >>
> >>> Pavel Panchekha wrote:
> >>>> Both the parser and the lexer attempt to write out parse tables
> >>>> each
> >>>> time they are run, if they have been told to do so.
> >>
> >>>> If an application that uses ply is installed in an area only root
> >>>> can
> >>>> write to, this will cause the application to crash.
> >>
> >>>> I'm currently using the following hacky fix:
> >>
> >>>> Wrap line 176 in lex.py with
> >>
> >>>> try:
> >>>> # line 176
> >>>> except IOError:
> >>>> pass
> >>
> >>>> Wrap line 2549 in yacc.py with
> >>
> >>>> try:
> >>>> # line 2549
> >>>> except IOError:
> >>>> pass
> >>
> >>>> This removed annoying error messages and program crashes.
> > >
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---