view python/ppci/common.py @ 301:6753763d3bec

merge codegen into ppci package
author Windel Bouwman
date Thu, 05 Dec 2013 17:02:38 +0100
parents 6aa721e7b10b
children 2c9768114877
line wrap: on
line source

from collections import namedtuple


# Token is used in the lexical analyzer:
class Token:
    def __init__(self, typ, val, loc=None):
        self.typ = typ
        self.val = val
        if loc is None:
            loc = SourceLocation('', 0, 0, 0)
        assert type(loc) is SourceLocation
        self.loc = loc

    def __repr__(self):
        return 'Token({0}, {1})'.format(self.typ, self.val)


class SourceLocation:
    def __init__(self, filename, row, col, ln):
        self.filename = filename
        self.row = row
        self.col = col
        self.length = ln

    def __repr__(self):
        return '{}, {}, {}'.format(self.filename, self.row, self.col)


SourceRange = namedtuple('SourceRange', ['p1', 'p2'])