Bobby Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/67332?usp=email )

Change subject: scons: Set 'reflags' to `re.MULTILINE` in fastmodel parser
......................................................................

scons: Set 'reflags' to `re.MULTILINE` in fastmodel parser

The following error is recieved when trying to compile gem5 with later
versions of Python (Python 3.11+):

```shell
ERROR:fm_proj_ply:/Users/bobbyrbruce/Desktop/gem5/build/ALL/arch/arm/fastmodel/SConscript:220: Invalid regular expression for rule 't_STRLIT'. global flags not at the start of the expression at position 13
SyntaxError: Can't build lexer
```

The offending function is:

```python
    def t_STRLIT(self, t):
        r'(?m)"([^"])*"'
        # strip off quotes
        t.value = t.value[1:-1]
        t.lexer.lineno += t.value.count('\n')
        return t
```

The `(?m)` part of the regex expression sets a global regex flag
in-line. In this case, specifying that the character pattern `^` matches
the benginning of the string and the beginning of each line. This allows
multi-line matching.

The error occurs as, as of Python 3.11, the global regex flag in-line
must occur at the beginning of the expression, but the ply lex.py file
contains the following:

```python
c = re.compile('(?P<%s>%s)' % (fname, _get_regex(f)), self.reflags)
```
https://gem5.googlesource.com/public/gem5/+/refs/tags/v22.1.0.0/ext/ply/ply/lex.py#760

This code appends the regex specified in the function to to
`'(?P<%s>%s)'`. As such the Python global flag is not at the beginning
of the regex expression.

This patch fixes the error by removing the global in-line flag and
applying the `re.MULTILINE` flag via the Lex `reflags` parameter, thus
allowing for multiline regex matching without the in-line flag.

Change-Id: I48cdba15b355f38c2a9dc957c6e89c143e319e1e
---
M src/arch/arm/fastmodel/SConscript
1 file changed, 53 insertions(+), 1 deletion(-)



diff --git a/src/arch/arm/fastmodel/SConscript b/src/arch/arm/fastmodel/SConscript
index 9d9d183..d536c89 100644
--- a/src/arch/arm/fastmodel/SConscript
+++ b/src/arch/arm/fastmodel/SConscript
@@ -38,6 +38,7 @@
 from itertools import cycle
 import logging
 import shlex
+import re

 Import('*')

@@ -161,6 +162,7 @@

         self.lex_kwargs['debuglog'] = self.log
         self.lex_kwargs['errorlog'] = self.log
+        self.lex_kwargs['reflags'] = re.MULTILINE

     class Param(object):
         def __init__(self, is_object):
@@ -218,7 +220,7 @@
     t_ID = r'[A-Za-z_]\w*'

     def t_STRLIT(self, t):
-        r'(?m)"([^"])*"'
+        r'"([^"])*"'
         # strip off quotes
         t.value = t.value[1:-1]
         t.lexer.lineno += t.value.count('\n')

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/67332?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I48cdba15b355f38c2a9dc957c6e89c143e319e1e
Gerrit-Change-Number: 67332
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to