Skip to content

Commit 7e9baec

Browse files
committed
Defines conflicts method in parsing table
1 parent f49ce44 commit 7e9baec

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/syntactes/parsing_table/table.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from syntactes import Grammar, Token
44
from syntactes._action import Action
55
from syntactes._state import LR0State
6-
from syntactes.parsing_table import Entry
6+
from syntactes.parsing_table import Conflict, Entry
77

88
Row: TypeAlias = dict[Token, list[Action]]
99

@@ -64,10 +64,17 @@ def pretty_str(self) -> str:
6464
"""
6565
return self._rules_pretty_str() + "\n\n" + self._table_pretty_str()
6666

67-
def conflicts(self) -> list:
67+
def conflicts(self) -> list[Conflict]:
6868
"""
6969
Retuns a list with all the conflicts in the parsing table.
7070
"""
71+
conflicts = []
72+
for state, row in self.rows.items():
73+
for token, actions in row.items():
74+
if len(actions) > 1:
75+
conflicts.append(Conflict(state, token, actions))
76+
77+
return conflicts
7178

7279
def _rules_pretty_str(self) -> str:
7380
rules = [str(i) + ". " + str(r) for i, r in enumerate(self._grammar.rules)]

0 commit comments

Comments
 (0)