Skip to content

Commit 57684b2

Browse files
committed
Restructures methods in parsing table
1 parent ba9be4f commit 57684b2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/syntactes/table.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ def __init__(self, grammar: Grammar) -> None:
4848
self._grammar = grammar
4949
self._initial_state = None
5050

51+
@staticmethod
52+
def from_entries(
53+
entries: Iterable[Entry], tokens: Iterable[Token]
54+
) -> "LR0ParsingTable":
55+
"""
56+
Create a parsing table from the given entries.
57+
"""
58+
table = LR0ParsingTable(tokens)
59+
{table.add_entry(entry) for entry in entries}
60+
return table
61+
62+
@property
63+
def initial_state(self) -> LR0State:
64+
return self._initial_state
65+
5166
def get_actions(self, state: LR0State, token: Token) -> Optional[list[Action]]:
5267
"""
5368
Get the actions from state with given number with `token`.
@@ -73,27 +88,12 @@ def add_entry(self, entry: Entry) -> None:
7388
actions = row.setdefault(entry.token, list())
7489
actions.append(entry.action)
7590

76-
@staticmethod
77-
def from_entries(
78-
entries: Iterable[Entry], tokens: Iterable[Token]
79-
) -> "LR0ParsingTable":
80-
"""
81-
Create a parsing table from the given entries.
82-
"""
83-
table = LR0ParsingTable(tokens)
84-
{table.add_entry(entry) for entry in entries}
85-
return table
86-
8791
def pretty_str(self) -> str:
8892
"""
8993
Returns a pretty-formatted string representation of the table.
9094
"""
9195
return self._rules_pretty_str() + "\n\n" + self._table_pretty_str()
9296

93-
@property
94-
def initial_state(self) -> LR0State:
95-
return self._initial_state
96-
9797
def _rules_pretty_str(self) -> str:
9898
rules = [str(i) + ". " + str(r) for i, r in enumerate(self._grammar.rules)]
9999
rules_str = "\n".join(rules)

0 commit comments

Comments
 (0)