RE: [Tutor] Syntax Check

2005-01-27 Thread Ryan Davis
Check out COG (http://www.nedbatchelder.com/code/cog/), a macro system for any 
language created by Ned Batchelder
(http://www.nedbatchelder.com/).

I'm not sure if that's what you're looking for, but allows some good macro 
capabilities.

Thanks,
Ryan 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Shannon
Sent: Thursday, January 27, 2005 4:35 PM
To: tutor@python.org
Subject: Re: [Tutor] Syntax Check

Chad Crabtree wrote:

> I'm trying to make a macro system that's work by just doing this
> 
> import macro
> # [...]

Perhaps you could turn things around, and make your macro preprocessor 
into an import hook?  I.E., you'd use it like --

 import macro
 module = macro.import("module_with_macros"[, macro_list])
 module.do_stuff()

Not sure if you'd need to have a list of macros in the module to be 
imported, or not.  Perhaps the macro module would hold a list of 
currently active macros, instead...

In any case, this (I think) gives you a chance to interrupt the import 
process and modify the target module before the Python parser gets it, 
which should enable you to avoid the SyntaxError problems.

(Of course, I've never messed around with hooking __import__(), so I 
could just be talking out of my ...)

Jeff Shannon
Technician/Programmer
Credit International


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Chad Crabtree
Well I don't think that it would really require that.  I could just 
define macro's in a module and just do it like so

import macro
import defined_macros as m
macro.expand(m.with(),m.assert()) 

I just thought it would be best to have definitions at the head of a 
script, or at least to have the option.

Jeff Shannon wrote:

> Perhaps you could turn things around, and make your macro
preprocessor 
> into an import hook?  I.E., you'd use it like --
>
> import macro
> module = macro.import("module_with_macros"[, macro_list])
> module.do_stuff()
>
> Not sure if you'd need to have a list of macros in the module to be

> imported, or not.  Perhaps the macro module would hold a list of 
> currently active macros, instead...
>
> In any case, this (I think) gives you a chance to interrupt the
import 
> process and modify the target module before the Python parser gets
it, 
> which should enable you to avoid the SyntaxError problems.
>
> (Of course, I've never messed around with hooking __import__(), so
I 
> could just be talking out of my ...)
>
>




__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Jeff Shannon
Chad Crabtree wrote:
I'm trying to make a macro system that's work by just doing this
import macro
# [...]
Perhaps you could turn things around, and make your macro preprocessor 
into an import hook?  I.E., you'd use it like --

import macro
module = macro.import("module_with_macros"[, macro_list])
module.do_stuff()
Not sure if you'd need to have a list of macros in the module to be 
imported, or not.  Perhaps the macro module would hold a list of 
currently active macros, instead...

In any case, this (I think) gives you a chance to interrupt the import 
process and modify the target module before the Python parser gets it, 
which should enable you to avoid the SyntaxError problems.

(Of course, I've never messed around with hooking __import__(), so I 
could just be talking out of my ...)

Jeff Shannon
Technician/Programmer
Credit International
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Chad Crabtree
Ok I'll explain what I've done so far.  I'm using tokenize to take
the 
file that imports macro; found by using  stack inspection and then 
tokenize it.  I look at all the string tokens to see if they match
they 
pattern a macro should have.  Then I pass the macro string through
the 
tokenizer again to expand this and to maintain the indentation needed

for the block.  I did this as an exercise and I thought the 'with' 
extension would be nice for my own benefit.  I thought it would be 
useful for all those syntax propositions in PEPs and stuff to
actually 
implement them to see how they work in real life.  However in it's 
current state I have to use anonymous ('''''') strings to
surround 
the macro.  I just thought it would be nice to just have python
import 
macro run the first few things with out looking to far into the file,
at 
which point macro.expand() would take over.

Now that you mention it and I'm thinking about it, it would probably 
take some sort of MacroPython->Python compiler type thing.  To get
the 
feel I'm really looking for.  I guess I was thinking it would work
like 
psyco

import psyco
psyco.full()

I hope I made myself clearer.

Alan Gauld wrote:

>>I'm trying to make a macro system that's work by just doing this
>>
>>
>
>OK, But to get your acros to use a language extension to python
>(the with syntax) you are going to have to write your own
>language interpreter/parser. Even if that just turns the 'with'
>stuff into Python.
>
>So why is the """ marker even necessary? Your interpreter doesn't
>need it - although it might make things easier... I'm still
>confused I think.
>
>Alan G.
>  
>




__ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Alan Gauld

> I'm trying to make a macro system that's work by just doing this

OK, But to get your acros to use a language extension to python
(the with syntax) you are going to have to write your own
language interpreter/parser. Even if that just turns the 'with'
stuff into Python.

So why is the """ marker even necessary? Your interpreter doesn't
need it - although it might make things easier... I'm still
confused I think.

Alan G.

>
> import macro
> class  withMacro(prefixMacro):
> pass
> mac=withMacro()
> mac.pattern("item key")
> macro.expand()
>
> g=[]
> """
> with g:
> .append('a')
> .append('b')
> .append(123)
> """
>
> I would like to not have to use the comment strings.  So when
> expand()
> is called it sucks in the file toeknizes it and expands the macro
> then
> runs the resulting modified code.
>
> Alan Gauld wrote:
>
> >>Does anyone happen to know how to turn of the syntax checking in
> >>python?  I've been working on a module driven preprocessor but I'd
> >>like to not have to use comment strings.
> >>
> >>
> >
> >So don't use them! They aren't mandatory.
> >I'm not sure I understand youir problem? Why would turning
> >off syntax checking ever help?
> >
> >Alan G.
> >
>
>
>
>
> __
> Do you Yahoo!?
> Meet the all-new My Yahoo! - Try it today!
> http://my.yahoo.com
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Chad Crabtree
I'm trying to make a macro system that's work by just doing this

import macro
class  withMacro(prefixMacro):
pass
mac=withMacro()
mac.pattern("item key")
macro.expand()

g=[]
"""
with g:
.append('a')
.append('b')
.append(123)
"""

I would like to not have to use the comment strings.  So when
expand() 
is called it sucks in the file toeknizes it and expands the macro
then 
runs the resulting modified code.

Alan Gauld wrote:

>>Does anyone happen to know how to turn of the syntax checking in 
>>python?  I've been working on a module driven preprocessor but I'd
>>like to not have to use comment strings.
>>
>>
>
>So don't use them! They aren't mandatory.
>I'm not sure I understand youir problem? Why would turning 
>off syntax checking ever help?
>
>Alan G.
>




__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Check

2005-01-27 Thread Alan Gauld
> Does anyone happen to know how to turn of the syntax checking in 
> python?  I've been working on a module driven preprocessor but I'd
> like to not have to use comment strings.

So don't use them! They aren't mandatory.
I'm not sure I understand youir problem? Why would turning 
off syntax checking ever help?

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax Check

2005-01-27 Thread Chad Crabtree
Does anyone happen to know how to turn of the syntax checking in 
python?  I've been working on a module driven preprocessor but I'd
like 
to not have to use comment strings.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor