Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cython / src / Cython / Plex / Actions.py
blobee6e0f987d4ebd92df2b88d7d022902d93610c6b
1 #=======================================================================
3 # Python Lexical Analyser
5 # Actions for use in token specifications
7 #=======================================================================
9 class Action(object):
11 def perform(self, token_stream, text):
12 pass # abstract
14 def same_as(self, other):
15 return self is other
18 class Return(Action):
19 """
20 Internal Plex action which causes |value| to
21 be returned as the value of the associated token
22 """
24 def __init__(self, value):
25 self.value = value
27 def perform(self, token_stream, text):
28 return self.value
30 def same_as(self, other):
31 return isinstance(other, Return) and self.value == other.value
33 def __repr__(self):
34 return "Return(%s)" % repr(self.value)
37 class Call(Action):
38 """
39 Internal Plex action which causes a function to be called.
40 """
42 def __init__(self, function):
43 self.function = function
45 def perform(self, token_stream, text):
46 return self.function(token_stream, text)
48 def __repr__(self):
49 return "Call(%s)" % self.function.__name__
51 def same_as(self, other):
52 return isinstance(other, Call) and self.function is other.function
55 class Begin(Action):
56 """
57 Begin(state_name) is a Plex action which causes the Scanner to
58 enter the state |state_name|. See the docstring of Plex.Lexicon
59 for more information.
60 """
62 def __init__(self, state_name):
63 self.state_name = state_name
65 def perform(self, token_stream, text):
66 token_stream.begin(self.state_name)
68 def __repr__(self):
69 return "Begin(%s)" % self.state_name
71 def same_as(self, other):
72 return isinstance(other, Begin) and self.state_name == other.state_name
75 class Ignore(Action):
76 """
77 IGNORE is a Plex action which causes its associated token
78 to be ignored. See the docstring of Plex.Lexicon for more
79 information.
80 """
81 def perform(self, token_stream, text):
82 return None
84 def __repr__(self):
85 return "IGNORE"
87 IGNORE = Ignore()
88 #IGNORE.__doc__ = Ignore.__doc__
90 class Text(Action):
91 """
92 TEXT is a Plex action which causes the text of a token to
93 be returned as the value of the token. See the docstring of
94 Plex.Lexicon for more information.
95 """
97 def perform(self, token_stream, text):
98 return text
100 def __repr__(self):
101 return "TEXT"
103 TEXT = Text()
104 #TEXT.__doc__ = Text.__doc__