make lexer replace class with class_ since it's a python keyword
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 12 May 2023 06:32:16 +0000 (23:32 -0700)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:18 +0000 (19:51 +0100)
src/openpower/decoder/pseudo/lexer.py

index 87147c81a55b6395f993dc48589ddb454ab8a7ba..6cf3020b55537b4f8095b28c4b86e49120d78d7a 100644 (file)
@@ -295,6 +295,9 @@ def filter(lexer, add_endmarker=True):
             lineno = token.lineno
         yield _new_token("ENDMARKER", lineno)
 
+
+KEYWORD_REPLACEMENTS = {'class': 'class_'}
+
 ##### Lexer ######
 
 
@@ -428,6 +431,8 @@ class PowerLexer:
     def t_NAME(self, t):
         r'[a-zA-Z_][a-zA-Z0-9_]*'
         t.type = self.RESERVED.get(t.value, "NAME")
+        if t.value in KEYWORD_REPLACEMENTS:
+            t.value = KEYWORD_REPLACEMENTS[t.value]
         return t
 
     # Putting this before t_WS let it consume lines with only comments in