You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re-factor repetition production class to use an optional separator
Addition of a `separator` parameter allows arguably a neater taxonomy of production classes, with `CommaSeparatedRepetitionProduction` now extending `RepetitionProduction` and using a separator value. This also will allow expressing repetition productions that employ arbitrary separators. It also reduces amount of code required for expressing productions of both kinds and then some.
"""Variant of `parse` for productions of the ` ` combinator variety (see "juxtaposing components" at https://drafts.csswg.org/css-values-4/#component-combinators)."""
:param element: The production expressing the repeating part of this production
89
90
:param min: The minimum amount of times the parser must accept input, i.e. the minimum number of repetitions of token sequences accepted by the parser
90
91
:param max: The maximum amount of times the parser will be called, i.e. the maximum number of repetitions that may be consumed in the input; the value of `None` implies no maximum (i.e. no upper bound on repetition)
92
+
:param separator: A production expressing the "delimiting" part between any two repetitions of the `element` production; if omitted or `None`, there's _no_ delimiting part -- repetitions are _adjacent_
91
93
"""
92
94
assertmin>=0
93
95
assertmaxisNoneormax>0
94
96
assertmaxisNoneormin<=max
95
97
self.min=min
96
98
self.max=max
97
99
self.element=element
100
+
ifseparator:
101
+
self.separator=separator
98
102
99
103
classOptionalProduction(RepetitionProduction):
100
104
"""Class of productions equivalent to `RepetitionProduction` with no lower bound and accepting no repetition of the element, meaning the element is expressed at most once.
whitespace=RepetitionProduction(TokenProduction(WhitespaceToken), min=1) # The white-space production; presence of white-space expressed with this production, is _mandatory_ (`min=1`); the definition was "hoisted" here because a) it depends on `RepetitionProduction` and `TokenProduction` definitions, which must thus precede it, and b) because the `CommaSeparatedRepetitionParser` definition that follows, depends on it, in turn
"""Class of productions that express a non-empty comma-separated repetition (CSR) of a production element.
124
129
125
-
Unlike `RepetitionProduction` which permits arbitrary number of the production element, this class does not currently implement arbitrary repetition bounds. The delimiting part (a comma optionally surrounded by white-space) is mandatory, which implies at least one repetition (two expressions of the element). Disregarding the delimiting behaviour, productions of this class thus behave like those of `RepetitionProduction` with `2` for `min` and `None` for `max` property values.
126
-
127
130
Implements the `#` notation as defined at http://drafts.csswg.org/css-values-4/#mult-comma.
128
131
"""
129
-
delimiter=ConcatenationProduction(OptionalProduction(AlternativesProduction(whitespace, TokenProduction(CommentToken))), TokenProduction(CommaToken), OptionalProduction(AlternativesProduction(whitespace, TokenProduction(CommentToken)))) # The production expressing the delimiter to use with the repetition, a comma with [optional] white-space around it
130
-
element: Production
131
-
def__init__(self, element: Production):
132
-
"""
133
-
:param element: A production to use for expressing the repeating part in this production
134
-
"""
135
-
self.element=element
132
+
separator=ConcatenationProduction(OWS, TokenProduction(CommaToken), OWS) # A comma with [optional] white-space around it
assertmin>=1# "one or more times" (ref. definition); the spec. does not define whether a minimum of zero is permitted, so we err on the safer side
135
+
super().__init__(element, min, max)
136
136
137
137
classFormatter:
138
138
"""Class of objects that offer procedures for serializing productions into streams of text formatted per the [value definition syntax](https://drafts.csswg.org/css-values-4/#value-defs)."""
0 commit comments