Source

Castile / src / castile / ast.py

class AST(object):
    def __init__(self, type, children=None, value=None):
        # TODO 'type' should be 'tag' or 'kind' or smth; 'type' should be
        # the type, in the type system, of the value this node evaluates to
        self._type = type
        self._value = value
        if children is not None:
            self._children = children
        else:
            self._children = []
        assert isinstance(self.children, list)
        for child in self.children:
            assert isinstance(child, AST), \
              "child %r of %r is not an AST node" % (child, self)
        self.aux = None  # typechecker may populate this
        #print "created %r" % self

    @property
    def type(self):
        return self._type

    @property
    def value(self):
        return self._value

    @property
    def children(self):
        return self._children

    def __repr__(self):
        if self.value is None:
            return 'AST(%r,%r)' % (self.type, self.children)
        if not self.children:
            return 'AST(%r,value=%r)' % (self.type, self.value)
        return 'AST(%r,%r,value=%r)' % (self.type, self.children, self.value)

    def minirepr(self):
        return '%s(%s:%s)' % (
            self.type, self.value,
            ','.join([c.minirepr() for c in self.children])
        )

    def pprint(self, indent):
        h = ('  ' * indent) + self.type
        if self.value is not None:
            h += '=%r' % self.value
        h += '\n'
        for child in self.children:
            h += child.pprint(indent + 1)
        return h
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.