Exemple #1
0
 def __call__(self, arg):
     return Tup(_, _%style(arg))
Exemple #2
0
from ptTools.ptpatterns import prettyprint, prettyinput

from ptTools.examples.pycat.styles import style_node as style
from ptTools.examples.pycat.styles import style_depth
from ptTools.examples.pycat.styles import style_token


class CallableAnyTokenPattern(AnyPattern):    
    def __call__(self, arg):
        return Tup(_, _%style(arg))

def pdebug(node):
    import pdb; pdb.set_trace()

anytoken = CallableAnyTokenPattern()
debug = style('debug')

## The following patterns are defined here, for later reuse.
## TODO - Use a to be created TerminalPattern class.
NAME    = Tup(token.NAME, _)
NUMBER  = Tup(token.NUMBER, _)
STRING  = Tup(token.STRING, _)
NEWLINE = Tup(token.NEWLINE, Lit(''))
KEYWORD = Tup(token.NAME, Test(lambda n : keyword.iskeyword(n.string)))
IMPORT  = Tup(token.NAME, Lit('import'))
SELF    = Tup(token.NAME, Lit('self'))
SUPER   = Tup(token.NAME, Lit('super'))
CLASS   = Tup(token.NAME, Lit('class'))
DEF     = Tup(token.NAME, Lit('def'))
RAISE   = Tup(token.NAME, Lit('raise'))
BOOL    = Opt('False', 'True', 'None')