@@ -52,16 +52,16 @@ def __init__(self, lhs, rhs):
5252 elif isinstance (lhs , list | tuple ) and lhs and all (isinstance (_ , str ) and _ for _ in lhs ):
5353 self .lhs = tuple (lhs )
5454 else :
55- raise ValueError ('The left-hand side is not a nonempty str, nor a tuple (or list) of nonempty str. ' )
55+ raise ValueError ('The left-hand side is not a nonempty str, nor a tuple (or list) of nonempty str' )
5656 if isinstance (rhs , list | tuple ):
5757 if not rhs :
5858 self .rhs = (ε ,)
5959 elif all (isinstance (_ , str ) and _ for _ in rhs ):
6060 self .rhs = tuple (rhs )
6161 else :
62- raise ValueError ('The right-hand side is not an empty tuple (or list), or a tuple (or list) of nonempty str. ' )
62+ raise ValueError ('The right-hand side is not an empty tuple (or list), or a tuple (or list) of nonempty str' )
6363 else :
64- raise ValueError ('The right-hand side is not a tuple (or list). ' ) # noqa: TRY004
64+ raise ValueError ('The right-hand side is not a tuple (or list)' ) # noqa: TRY004
6565 if ε in self .rhs and len (self .rhs ) != 1 :
6666 raise ValueError ('The right-hand side contains ε but has more than one symbol' )
6767
@@ -91,7 +91,7 @@ def is_epsilon(self):
9191 @classmethod
9292 def from_string (cls , prods , context_free = True ): # pragma: no cover
9393 """Deprecated. Use Productions.from_string."""
94- deprecation_warning ('The function "from_string" has been moved to Productions. ' )
94+ deprecation_warning ('The function "from_string" has been moved to Productions' )
9595 return Productions .from_string (prods , context_free )
9696
9797 @classmethod
@@ -244,9 +244,9 @@ class Item(Production):
244244
245245 def __init__ (self , lhs , rhs , pos = 0 ):
246246 if not isinstance (lhs , str ) and lhs :
247- raise ValueError ('The left-hand side must be a str. ' )
247+ raise ValueError ('The left-hand side must be a str' )
248248 if pos < 0 or pos > len (rhs ):
249- raise ValueError ('The dot position is invalid. ' )
249+ raise ValueError ('The dot position is invalid' )
250250 self .pos = pos
251251 super ().__init__ (lhs , rhs )
252252
@@ -318,11 +318,11 @@ def __init__(self, N, T, P, S):
318318 f'The set of terminals and nonterminals are not disjoint, but have { set (self .N & self .T )} in common.'
319319 )
320320 if self .S not in self .N :
321- raise ValueError ('The start symbol is not a nonterminal. ' )
321+ raise ValueError ('The start symbol is not a nonterminal' )
322322 if self .is_context_free :
323323 bad_prods = tuple (P for P in self .P if P .lhs not in self .N )
324324 if bad_prods :
325- raise ValueError (f'The following productions have a left-hand side that is not a nonterminal: { bad_prods } . ' )
325+ raise ValueError (f'The following productions have a left-hand side that is not a nonterminal: { bad_prods } ' )
326326 bad_prods = tuple (P for P in self .P if not (set (P .as_type0 ().lhs ) | set (P .rhs )).issubset (self .N | self .T | {ε }))
327327 if bad_prods :
328328 raise ValueError (
@@ -374,7 +374,7 @@ def from_string(cls, prods, context_free=True):
374374 T = symbols - N - {ε }
375375 G = cls (N , T , P , S )
376376 if context_free and not G .is_context_free : # pragma: no cover
377- raise ValueError ('The resulting grammar is not context-free, even if so requested. ' )
377+ raise ValueError ('The resulting grammar is not context-free, even if so requested' )
378378 return G
379379
380380 def alternatives (self , N ):
@@ -404,7 +404,7 @@ def restrict_to(self, symbols):
404404 ValueError: in case the *start symbol* is not among the one to keep.
405405 """
406406 if self .S not in symbols :
407- raise ValueError ('The start symbol must be present among the symbols to keep. ' )
407+ raise ValueError ('The start symbol must be present among the symbols to keep' )
408408 return Grammar (self .N & symbols , self .T & symbols , (P for P in self .P if ({P .lhs } | set (P .rhs )) <= symbols ), self .S )
409409
410410
@@ -551,7 +551,7 @@ def _step(derivation, prod, pos):
551551 prod = self .__ensure_prod_idx__ (prod )
552552 P = derivation .G .P [prod ].as_type0 ()
553553 if sf [pos : pos + len (P .lhs )] != P .lhs :
554- raise ValueError (f'Cannot apply { P } at position { pos } of { HAIR_SPACE .join (sf )} . ' )
554+ raise ValueError (f'Cannot apply { P } at position { pos } of { HAIR_SPACE .join (sf )} ' )
555555 copy = Derivation (derivation .G , self .start )
556556 copy ._sf = tuple (_ for _ in sf [:pos ] + P .rhs + sf [pos + len (P .lhs ) :] if _ != ε )
557557 copy ._steps = (* derivation ._steps , (prod , pos ))
0 commit comments