diff --git a/scripts/dts/python-devicetree/src/devicetree/edtlib.py b/scripts/dts/python-devicetree/src/devicetree/edtlib.py index a2ef70e5aa9..9e7dc1baaac 100644 --- a/scripts/dts/python-devicetree/src/devicetree/edtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/edtlib.py @@ -1552,7 +1552,7 @@ class PinCtrl: @property def name_as_token(self): "See the class docstring" - return _val_as_token(self.name) if self.name is not None else None + return str_as_token(self.name) if self.name is not None else None def __repr__(self): fields = [] @@ -1645,7 +1645,7 @@ class Property: @property def val_as_token(self): "See the class docstring" - return _val_as_token(self.val) + return str_as_token(self.val) @property def enum_index(self): @@ -2929,7 +2929,12 @@ _LOG = logging.getLogger(__name__) _NOT_ALPHANUM_OR_UNDERSCORE = re.compile(r'\W', re.ASCII) -def _val_as_token(val): +def str_as_token(val): + """Return a canonical representation of a string as a C token. + + This converts special characters in 'val' to underscores, and + returns the result.""" + return re.sub(_NOT_ALPHANUM_OR_UNDERSCORE, '_', val)