Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 10f054886d
Fetching contributors…

Cannot retrieve contributors at this time

executable file 40 lines (33 sloc) 1.512 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
class Node(object):
    fields = []

    def __init__(self, *args, **kwargs):
        assert len(self.fields) == len(args), \
            '%s takes %d arguments' % (self.__class__.__name__,
                                       len(self.fields))
        try:
            self.lineno = kwargs['lineno']
        except KeyError:
            self.lineno = None
        for i, field in enumerate(self.fields):
            setattr(self, field, args[i])

    def __repr__(self):
        return "%s(%s)" % (self.__class__.__name__,
                           ', '.join([repr(getattr(self, field))
                                      for field in self.fields]))



def node(name, fields):
    attrs = {'fields': fields}
    return type(name, (Node,), attrs)


Function = node('Function', ['name', 'params', 'nodes'])
InlineFunction = node('InlineFunction', ['params'])
Class = node('Class', ['name', 'nodes'])
This = node('This', []) # the most important word in php :)
Variable = node('Variable', ['name','value', 'position','type'])
Parameter = node('Parameter', ['name','value', 'position'])
Constant = node('Constant', ['name','value'])
Assignment = node('Assignment', [])
Array = node('Array', ['nodes'])
ArrayElement = node('ArrayElement', ['key', 'value', 'position'])
ArrayKeyReference = node('ArrayKeyReference', ['value'])
NewLine = node('NewLine', [])
For = node('For', ['key', 'start', 'end', 'nodes'])
ForEach = node('ForEach', ['key', 'value', 'array', 'nodes'])
Something went wrong with that request. Please try again.