Skip to content

Commit 1c94ce5

Browse files
committed
Defines constructor methods for actions
1 parent b02076a commit 1c94ce5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/syntactes/_action.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ def __init__(self, actionable: Actionable, action_type: ActionType) -> None:
4343
self.actionable = actionable
4444
self.action_type = action_type
4545

46+
@staticmethod
47+
def shift(state: Actionable) -> "Action":
48+
"""
49+
Create a shift action to the given state.
50+
"""
51+
return Action(state, ActionType.SHIFT)
52+
53+
@staticmethod
54+
def reduce(rule: Actionable) -> "Action":
55+
"""
56+
Create a reduce action of the given rule.
57+
"""
58+
return Action(rule, ActionType.REDUCE)
59+
60+
@staticmethod
61+
def accept() -> "Action":
62+
"""
63+
Create an accept action.
64+
"""
65+
return Action(None, ActionType.ACCEPT)
66+
4667
def __repr__(self) -> str:
4768
return f"<Action: {self}>"
4869

0 commit comments

Comments
 (0)