ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Jython-dev
Jython-dev
Re: [Jython-dev] imports with parser type eval
by Mark Proctor other posts by this author
Oct 21 2004 9:17PM messages near this date
Re: [Jython-dev] imports with parser type eval | Re: [Jython-dev] imports with parser type eval
just chatting to one of the other developers, think we might be able to 
have a PythonInterpretor for each RuleSet, which should solve this 
issue. Otherwise whats potentially wrong with doing an exec with the 
following to emulate an expression:
        String tempText = stripOuterIndention( text );
        if (type.equals("eval"))
        {
            tempText = "return (" + tempText + ")";
        }
        this.text = newText.append(tempText).toString();


Mark
Oti wrote:

> IMHO you cannot eval an import statement:
>   Jython 2.1 on java1.4.2_05 (JIT: null)
>   Type "copyright", "credits" or "license" for more information.
>   >>> exec("from java.lang import String")
>   >>> eval("from java.lang import String")
>   Traceback (innermost last):
>     File "<console>", line 1, in ?
>     File "<string>", line 1  
>   	from java.lang import String
> 	^
>   SyntaxError: invalid syntax
>   >>> 
> 
> so you have to exec the imports first, e.g. like Jim suggested.
> 
> Best wishes,
> Oti.
> 
> --- Jim Adrig <jim@[...].com> wrote:
> 
>   
> 
> >If you are running these from Java, maybe something like what we do 
> >will work?
> >
> >First we 'add_package' since we have the cachedir stuff turned off:
> >
> >   // for Swing GUI building:
> >     PySystemState.add_package("javax");
> >     PySystemState.add_package("javax.swing");
> >     PySystemState.add_package("javax.swing.text");
> >     PySystemState.add_package("java.awt");         // Color, etc.
> >     PySystemState.add_package("java.awt.event");
> >
> >Then create an interpreter and 'execfile' all our standard 
> >imports/functions
> >
> >	  python.execfile( functionFileStream, functionFileName ); // pass
> >the 
> >name for parsing errors
> >
> >The 'functionFileStream' contains lots of things like:
> >
> >   from javax.swing import JCheckBox, JComboBox, JFrame, JMenuBar, 
> >JMenu, JMenuItem, JTable, JButton, JOptionPane, JRadioButton, 
> >JTextField
> >   from java.awt import Color, GridLayout, GridBagLayout
> >
> >
> >On Oct 21, 2004, at 12:45 PM, Mark Proctor wrote:
> >
> >    
> >
> >>I'm compiling expressions and blocks for use in our application, to
> >>      
> >>
> >>this we pre-append import statements declared elsewhere. It works
> >>      
> >>
> >fine 
> >    
> >
> >>when type is "exec" for blocks but fails when its "eval" for 
> >>expressions. Any ideas of how to get this to work?
> >>
> >>Mark
> >>
> >>   protected Interp(String text, Imports imports, String type)
> >>   {
> >>       this.origininalText = text;
> >>       StringBuffer newText = new StringBuffer();
> >>
> >>       if ((imports != null)&&(imports.getImportEntries() != null))
> >>       {
> >>           Iterator it =imports.getImportEntries().iterator();
> >>                     while (it.hasNext())
> >>           {                              ImportEntry importEntry =
> >>      
> >>
> >>(ImportEntry) it.next();
> >>               if (importEntry instanceof PythonImportEntry)
> >>               {
> >>                   newText.append(importEntry.getImportEntry());
> >>                   newText.append(";");
> >>                   newText.append(newline);
> >>               }
> >>           }                         }
> >>                            this.text = 
> >>newText.append(stripOuterIndention( text )).toString();
> >>
> >>       this.node = ( modType ) parser.parse( this.text, type );
> >>       this.code = Py.compile( this.node, "<jython>" );
> >>      
> >>
> 
> 
>   
> 
Attachments:
unknown1


Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved