Skip to content

Commit fcc5b29

Browse files
committed
update indexed_grammar docs
1 parent eba54b1 commit fcc5b29

File tree

15 files changed

+279
-467
lines changed

15 files changed

+279
-467
lines changed

pyformlang/cfg/formal_grammar.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,22 @@ def __init__(self,
3838

3939
@property
4040
def variables(self) -> Set[Variable]:
41-
"""Gets the variables of the grammar.
42-
43-
Returns
44-
-------
45-
The variables of the grammar.
46-
"""
41+
"""Gets the variables of the grammar."""
4742
return self._variables
4843

4944
@property
5045
def terminals(self) -> Set[Terminal]:
51-
"""Gets the terminals of the grammar.
52-
53-
Returns
54-
-------
55-
The terminals of the grammar.
56-
"""
46+
"""Gets the terminals of the grammar."""
5747
return self._terminals
5848

5949
@property
6050
def productions(self) -> Set[Production]:
61-
"""Gets the productions of the grammar.
62-
63-
Returns
64-
-------
65-
The productions of the grammar.
66-
"""
51+
"""Gets the productions of the grammar."""
6752
return self._productions
6853

6954
@property
7055
def start_symbol(self) -> Optional[Variable]:
71-
"""Gets the start symbol of the grammar.
72-
73-
Returns
74-
-------
75-
The start symbol of the grammar.
76-
"""
56+
"""Gets the start symbol of the grammar."""
7757
return self._start_symbol
7858

7959
def add_production(self, production: Production) -> None:

pyformlang/finite_automaton/deterministic_finite_automaton.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def remove_start_state(self, state: Hashable) -> int:
113113
The initial state to remove.
114114
115115
Returns
116-
----------
116+
-------
117117
1 is correctly removed.
118118
119119
Examples
@@ -408,7 +408,7 @@ def is_equivalent_to(self, other: "DeterministicFiniteAutomaton") -> bool:
408408
409409
Returns
410410
-------
411-
Whether the two automata are equivalent or not
411+
Whether the two automata are equivalent or not.
412412
413413
Examples
414414
--------

pyformlang/finite_automaton/epsilon_nfa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def __and__(self, other: "EpsilonNFA") -> "EpsilonNFA":
395395
The other Epsilon NFA.
396396
397397
Returns
398-
---------
398+
-------
399399
The intersection of the two Epsilon NFAs.
400400
"""
401401
return self.get_intersection(other)

pyformlang/finite_automaton/finite_automaton.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def add_transition(self,
8080
8181
Returns
8282
-------
83-
Always 1
83+
Always 1.
8484
8585
Examples
8686
--------
@@ -109,7 +109,7 @@ def add_transitions(self, transitions_list: \
109109
110110
Returns
111111
-------
112-
Always 1
112+
Always 1.
113113
114114
Examples
115115
--------
Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""
2-
Representation of a consumption rule, i.e. a rule that consumes something on \
3-
the stack
1+
"""Representation of a consumption rule.
2+
3+
A rule that consumes something on the stack.
44
"""
55

66
from typing import List, Set, Hashable, Any
@@ -12,96 +12,73 @@
1212

1313

1414
class ConsumptionRule(ReducedRule):
15-
""" Contains a representation of a consumption rule, i.e. a rule of the \
16-
form:
17-
C[ r sigma] -> B[sigma]
15+
"""Representation of a consumption rule.
16+
17+
It is a rule of form:
18+
C[r sigma] -> B[sigma]
1819
1920
Parameters
2021
----------
21-
f_param : any
22-
The consumed symbol
23-
left : any
24-
The non terminal on the left (here C)
25-
right : any
26-
The non terminal on the right (here B)
22+
f_param:
23+
The consumed symbol, "r" here.
24+
left_term:
25+
The non terminal on the left, "C" here.
26+
right_term:
27+
The non terminal on the right, "B" here.
2728
"""
2829

2930
def __init__(self,
3031
f_param: Hashable,
3132
left_term: Hashable,
3233
right_term: Hashable) -> None:
34+
"""Initializes the consumption rule."""
3335
self._f = to_terminal(f_param)
3436
self._left_term = to_variable(left_term)
3537
self._right_term = to_variable(right_term)
3638

3739
@property
3840
def f_parameter(self) -> Terminal:
39-
"""Gets the symbol which is consumed
40-
41-
Returns
42-
----------
43-
f : any
44-
The symbol being consumed by the rule
45-
"""
41+
"""Gets the symbol consumed by the rule."""
4642
return self._f
4743

4844
@property
4945
def production(self) -> Terminal:
46+
"""Gets the symbol produced by the rule."""
5047
raise NotImplementedError
5148

5249
@property
5350
def left_term(self) -> Variable:
54-
"""Gets the symbol on the left of the rule
55-
56-
left : any
57-
The left symbol of the rule
58-
"""
51+
"""Gets a nonterminal on the left of the rule."""
5952
return self._left_term
6053

6154
@property
6255
def right_term(self) -> Variable:
63-
"""Gets the symbol on the right of the rule
64-
65-
right : any
66-
The right symbol
67-
"""
56+
"""Gets a nonterminal on the right of the rule."""
6857
return self._right_term
6958

7059
@property
7160
def right_terms(self) -> List[CFGObject]:
72-
"""Gives the non-terminals on the right of the rule
73-
74-
Returns
75-
---------
76-
right_terms : iterable of any
77-
The right terms of the rule
78-
"""
61+
"""Gets a list of right terms of the rule."""
7962
return [self._right_term]
8063

8164
@property
8265
def non_terminals(self) -> Set[Variable]:
83-
"""Gets the non-terminals used in the rule
84-
85-
non_terminals : iterable of any
86-
The non_terminals used in the rule
87-
"""
66+
"""Gets the nonterminals used in the rule."""
8867
return {self._left_term, self._right_term}
8968

9069
@property
9170
def terminals(self) -> Set[Terminal]:
92-
"""Gets the terminals used in the rule
93-
94-
terminals : set of any
95-
The terminals used in the rule
96-
"""
71+
"""Gets the terminals used in the rule."""
9772
return {self._f}
9873

9974
def __eq__(self, other: Any) -> bool:
75+
"""Checks if the rule is equal to the given object."""
10076
if not isinstance(other, ConsumptionRule):
10177
return False
10278
return other.left_term == self.left_term \
10379
and other.right_term == self.right_term \
10480
and other.f_parameter == self.f_parameter
10581

10682
def __repr__(self) -> str:
83+
"""Gets a string representation of the rule."""
10784
return f"{self._left_term} [ {self._f} ] -> {self._right_term}"
Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
"""
2-
A representation of a duplication rule, i.e. a rule that duplicates the stack
1+
"""Representation of a duplication rule.
2+
3+
A rule that duplicates the stack.
34
"""
45

56
from typing import List, Set, Hashable, Any
@@ -11,90 +12,73 @@
1112

1213

1314
class DuplicationRule(ReducedRule):
14-
"""Represents a duplication rule, i.e. a rule of the form:
15+
"""Representation of a duplication rule.
16+
17+
It is a rule of form:
1518
A[sigma] -> B[sigma] C[sigma]
1619
1720
Parameters
1821
----------
19-
left_term : any
20-
The non-terminal on the left of the rule (A here)
21-
right_term0 : any
22-
The first non-terminal on the right of the rule (B here)
23-
right_term1 : any
24-
The second non-terminal on the right of the rule (C here)
22+
left_term:
23+
The non-terminal on the left of the rule, "A" here.
24+
right_term0:
25+
The first non-terminal on the right of the rule, "B" here.
26+
right_term1:
27+
The second non-terminal on the right of the rule, "C" here.
2528
"""
2629

2730
def __init__(self,
2831
left_term: Hashable,
2932
right_term0: Hashable,
3033
right_term1: Hashable) -> None:
34+
"""Initializes the duplication rule."""
3135
self._left_term = to_variable(left_term)
3236
self._right_terms = (to_variable(right_term0),
3337
to_variable(right_term1))
3438

3539
@property
3640
def f_parameter(self) -> Terminal:
41+
"""Gets the symbol consumed by the rule."""
3742
raise NotImplementedError
3843

3944
@property
4045
def production(self) -> Terminal:
46+
"""Gets the symbol produced by the rule."""
4147
raise NotImplementedError
4248

4349
@property
4450
def left_term(self) -> Variable:
45-
"""Gives the non-terminal on the left of the rule
46-
47-
Returns
48-
---------
49-
left_term : any
50-
The left term of the rule
51-
"""
51+
"""Gets a nonterminal on the left of the rule."""
5252
return self._left_term
5353

5454
@property
5555
def right_term(self) -> CFGObject:
56+
"""Gets the single right term of the rule."""
5657
raise NotImplementedError
5758

5859
@property
5960
def right_terms(self) -> List[CFGObject]:
60-
"""Gives the non-terminals on the right of the rule
61-
62-
Returns
63-
---------
64-
right_terms : iterable of any
65-
The right terms of the rule
66-
"""
61+
"""Gets a list of right terms of the rule."""
6762
return list(self._right_terms)
6863

6964
@property
7065
def non_terminals(self) -> Set[Variable]:
71-
"""Gives the set of non-terminals used in this rule
72-
73-
Returns
74-
---------
75-
non_terminals : iterable of any
76-
The non terminals used in this rule
77-
"""
66+
"""Gets the nonterminals used in the rule."""
7867
return {self._left_term, *self._right_terms}
7968

8069
@property
8170
def terminals(self) -> Set[Terminal]:
82-
"""Gets the terminals used in the rule
83-
84-
Returns
85-
----------
86-
terminals : set of any
87-
The terminals used in this rule
88-
"""
71+
"""Gets the terminals used in the rule."""
8972
return set()
9073

9174
def __eq__(self, other: Any) -> bool:
75+
"""Checks if the rule is equal to the given object."""
9276
if not isinstance(other, DuplicationRule):
9377
return False
9478
return other.left_term == self._left_term \
9579
and other.right_terms == self.right_terms
9680

9781
def __repr__(self) -> str:
98-
"""Gives a string representation of the rule, ignoring the sigmas"""
82+
"""Gets a string representation of the rule."""
9983
return f"{self._left_term} -> " \
10084
+ f"{self._right_terms[0]} {self._right_terms[1]}"

0 commit comments

Comments
 (0)