edtlib: emit pinctrl names as tokens

This will be necessary to going back and forth between indexes and
names in C.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-08-16 15:29:42 -07:00 committed by Anas Nashif
commit fa2e82becd

View file

@ -1381,12 +1381,21 @@ class PinCtrl:
The name of the configuration, as given in pinctrl-names, or None if The name of the configuration, as given in pinctrl-names, or None if
there is no pinctrl-names property there is no pinctrl-names property
name_as_token:
Like 'name', but with non-alphanumeric characters converted to underscores.
conf_nodes: conf_nodes:
A list of Node instances for the pin configuration nodes, e.g. A list of Node instances for the pin configuration nodes, e.g.
the nodes pointed at by &state_1 and &state_2 in the nodes pointed at by &state_1 and &state_2 in
pinctrl-0 = <&state_1 &state_2>; pinctrl-0 = <&state_1 &state_2>;
""" """
@property
def name_as_token(self):
"See the class docstring"
return _val_as_token(self.name) if self.name is not None else None
def __repr__(self): def __repr__(self):
fields = [] fields = []
@ -1478,7 +1487,7 @@ class Property:
@property @property
def val_as_token(self): def val_as_token(self):
"See the class docstring" "See the class docstring"
return re.sub(_NOT_ALPHANUM_OR_UNDERSCORE, '_', self.val) return _val_as_token(self.val)
@property @property
def enum_index(self): def enum_index(self):
@ -2746,6 +2755,11 @@ _LOG = logging.getLogger(__name__)
# Regular expression for non-alphanumeric-or-underscore characters. # Regular expression for non-alphanumeric-or-underscore characters.
_NOT_ALPHANUM_OR_UNDERSCORE = re.compile(r'\W', re.ASCII) _NOT_ALPHANUM_OR_UNDERSCORE = re.compile(r'\W', re.ASCII)
def _val_as_token(val):
return re.sub(_NOT_ALPHANUM_OR_UNDERSCORE, '_', val)
# Custom PyYAML binding loader class to avoid modifying yaml.Loader directly, # Custom PyYAML binding loader class to avoid modifying yaml.Loader directly,
# which could interfere with YAML loading in clients # which could interfere with YAML loading in clients
class _BindingLoader(Loader): class _BindingLoader(Loader):