diff python/ppci/common.py @ 396:fb3c1f029b30

Added baselexer into c3 lexer
author Windel Bouwman
date Tue, 27 May 2014 22:19:32 +0200
parents b8ad45b3a573
children
line wrap: on
line diff
--- a/python/ppci/common.py	Fri May 23 14:28:03 2014 +0200
+++ b/python/ppci/common.py	Tue May 27 22:19:32 2014 +0200
@@ -7,13 +7,14 @@
    Source location structures
 """
 
-# Token is used in the lexical analyzer:
 class Token:
-    def __init__(self, typ, val, loc=None):
+    """
+        Token is used in the lexical analyzer. The lexical analyzer takes
+        a text and splits it into tokens.
+    """
+    def __init__(self, typ, val, loc):
         self.typ = typ
         self.val = val
-        if loc is None:
-            loc = SourceLocation('', 0, 0, 0)
         assert type(loc) is SourceLocation
         self.loc = loc
 
@@ -58,7 +59,7 @@
         self.logger = logging.getLogger('diagnostics')
 
     def addSource(self, name, src):
-        self.logger.debug('Adding source {}'.format(name))
+        self.logger.debug('Adding source, filename="{}"'.format(name))
         self.sources[name] = src
 
     def addDiag(self, d):
@@ -80,7 +81,7 @@
 
     def printError(self, e):
         def printLine(row, txt):
-            print(str(row)+':'+txt)
+            print(str(row) + ':' + txt)
         print('==============')
         if not e.loc:
             print('Error: {0}'.format(e))