Skip to content

Commit 458dcc0

Browse files
committed
Uniformed messages removing final dot
1 parent 0eccdcc commit 458dcc0

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/liblet/automaton.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,18 @@ def __init__(self, N, T, transitions, q0, F):
134134
self.F = set(F)
135135
if self.N & self.T:
136136
raise ValueError(
137-
f'The set of states and input symbols are not disjoint, but have {letstr(set(self.N & self.T))} in common.'
137+
f'The set of states and input symbols are not disjoint, but have {letstr(set(self.N & self.T))} in common'
138138
)
139139
if self.q0 not in self.N:
140-
raise ValueError(f'The specified q0 ({letstr(q0)}) is not a state.')
140+
raise ValueError(f'The specified q0 ({letstr(q0)}) is not a state')
141141
if not self.F <= self.N:
142-
raise ValueError(f'The accepting states {letstr(self.F - self.N)} in F are not states.')
142+
raise ValueError(f'The accepting states {letstr(self.F - self.N)} in F are not states')
143143
bad_trans = tuple(
144144
t for t in transitions if t.frm not in self.N or t.to not in self.N or t.label not in (self.T | {ε})
145145
)
146146
if bad_trans:
147147
raise ValueError(
148-
f'The following transitions contain states or symbols that are neither states nor input symbols: {bad_trans}.'
148+
f'The following transitions contain states or symbols that are neither states nor input symbols: {bad_trans}'
149149
)
150150

151151
def δ(self, X, x):
@@ -284,7 +284,7 @@ class TopDownInstantaneousDescription(InstantaneousDescription):
284284
def __init__(self, G, word=None):
285285
super().__init__(G)
286286
if HASH in (G.N | G.T):
287-
raise ValueError('The ' + HASH + ' sign must not belong to terminal, or nonterminals.')
287+
raise ValueError('The ' + HASH + ' sign must not belong to terminal, or nonterminals')
288288
if word is not None:
289289
self.tape = (*tuple(word), HASH)
290290
self.stack = Stack([HASH, G.S])
@@ -311,7 +311,7 @@ def match(self):
311311
if self.top() != ε:
312312
c.head_pos += 1
313313
return c
314-
raise ValueError('The top of the stack and tape head symbol are not equal.')
314+
raise ValueError('The top of the stack and tape head symbol are not equal')
315315

316316
def predict(self, P):
317317
"""Performs a prediction move, given the specified production.
@@ -334,7 +334,7 @@ def predict(self, P):
334334
for X in reversed(P.rhs):
335335
c.stack.push(X)
336336
return c
337-
raise ValueError('The top of the stack does not correspond to the production lhs.')
337+
raise ValueError('The top of the stack does not correspond to the production lhs')
338338

339339

340340
class BottomUpInstantaneousDescription(InstantaneousDescription):
@@ -376,7 +376,7 @@ def shift(self, consume=True):
376376
c.stack.push(Tree(c.head()))
377377
c.head_pos += 1
378378
else:
379-
raise ValueError('The head is already at the end of the tape.')
379+
raise ValueError('The head is already at the end of the tape')
380380
else:
381381
c.stack.push(Tree(ε))
382382
return c
@@ -392,13 +392,13 @@ def reduce(self, P):
392392
A new updated instantaneous description.
393393
"""
394394
if P not in self.G.P:
395-
raise ValueError('The production does not belong to the grammar.')
395+
raise ValueError('The production does not belong to the grammar')
396396
if not self.stack:
397-
raise ValueError('The stack is empty.')
397+
raise ValueError('The stack is empty')
398398
c = copy(self)
399399
children = [c.stack.pop() for _ in P.rhs][::-1]
400400
if tuple(t.root for t in children) != P.rhs:
401-
raise ValueError('The rhs does not correspond to the symbols on the stack.')
401+
raise ValueError('The rhs does not correspond to the symbols on the stack')
402402
c.stack.push(Tree(P.lhs, children))
403403
c.steps = (P, *c.steps)
404404
return c

src/liblet/display.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class Table:
666666

667667
def __init__(self, ndim=1, element=lambda: None, no_reassign=False, fmt=None):
668668
if ndim not in {1, 2}:
669-
raise ValueError('The ndim must be 1, or 2.')
669+
raise ValueError('The ndim must be 1, or 2')
670670
self.ndim = ndim
671671
if ndim == 1:
672672
self.data = defaultdict(element)
@@ -801,7 +801,7 @@ def _repr_html_(self):
801801

802802
def pyast2tree(node):
803803
"""Deprecated. Use Tree.from_pyast instead."""
804-
deprecation_warning('The function "pyast2tree" has been absorbed in Tree (as from_pyast factory method).')
804+
deprecation_warning('The function "pyast2tree" has been absorbed in Tree (as from_pyast factory method)')
805805
return (
806806
Tree(
807807
{'type': 'ast', 'name': node.__class__.__name__},
@@ -893,7 +893,7 @@ def fmt(r, c):
893893

894894
def cyk2table(TABLE):
895895
"""Deprecated. Use CYKTable instead."""
896-
deprecation_warning('The function "cyk2table" has been absorbed in CYKTable.')
896+
deprecation_warning('The function "cyk2table" has been absorbed in CYKTable')
897897
t = CYKTable()
898898
for il, v in TABLE.items():
899899
t[il] = v
@@ -902,7 +902,7 @@ def cyk2table(TABLE):
902902

903903
def prods2table(G):
904904
"""Deprecated. Use Productions instead"""
905-
deprecation_warning('The function "prods2table" has been absorbed in Productions.')
905+
deprecation_warning('The function "prods2table" has been absorbed in Productions')
906906
return HTML(Productions(G.P)._repr_html_())
907907

908908

src/liblet/grammar.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

src/liblet/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ def warn(msg):
2323

2424
def first(s):
2525
"""Deprecated. Use set.pop"""
26-
deprecation_warning('The function "first" is now deprecated, please use "pop" instead.')
26+
deprecation_warning('The function "first" is now deprecated, please use "pop" instead')
2727
return next(iter(s)) if s else None
2828

2929

3030
def peek(s): # pragma: nocover
3131
"""Deprecated. Use first"""
32-
deprecation_warning('The function "peek" is now deprecated, please use "first" instead.')
32+
deprecation_warning('The function "peek" is now deprecated, please use "first" instead')
3333
return first(s)
3434

3535

@@ -104,7 +104,7 @@ def dequeue(self):
104104
return self.Q.popleft()
105105

106106
def copy(self): # pragma: nocover
107-
deprecation_warning('The copy method is deprecated, use the copy module.')
107+
deprecation_warning('The copy method is deprecated, use the copy module')
108108
return self.__copy__()
109109

110110
def __copy__(self):
@@ -179,7 +179,7 @@ def pop(self):
179179
return self.S.pop()
180180

181181
def copy(self): # pragma: nocover
182-
deprecation_warning('The copy method is deprecated, use the copy module.')
182+
deprecation_warning('The copy method is deprecated, use the copy module')
183183
return self.__copy__()
184184

185185
def __copy__(self):

0 commit comments

Comments
 (0)