Skip to content

Commit

Permalink
zcbor.py: Improve comments around regexes.
Browse files Browse the repository at this point in the history
Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
  • Loading branch information
oyvindronningstad committed Sep 28, 2023
1 parent 72213ad commit 89a9d0f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions zcbor/zcbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ def cddl_regexes_init(self):

self_type = type(self)

# The "range_types" match the contents of brackets i.e. (), [], and {},
# and strings, i.e. ' or "
range_types = [
(r'\[(?P<item>(?>[^[\]]+|(?R))*)\]',
lambda m_self, list_str: m_self.type_and_value(
Expand All @@ -791,9 +793,8 @@ def cddl_regexes_init(self):
range_types_regex = range_types_regex.replace("item", "it%dem" % i, 1)

# The following regexes match different parts of the element. The order of the list is
# important because it implements the operator precendence defined in the CDDL spec. Note
# that some regexes are inserted afterwards because they involve a match of a concatenation
# of all the initial regexes (with a '|' between each element).
# important because it implements the operator precendence defined in the CDDL spec.
# The range_types are separate because they are reused in one of the other regexes.
self_type.cddl_regexes[self_type] = range_types + [
(r'\/\/\s*(?P<item>.+?)(?=\/\/|\Z)',
lambda m_self, union_str: m_self.union_add_value(
Expand Down

0 comments on commit 89a9d0f

Please sign in to comment.