1 #=======================================================================
3 # Python Lexical Analyser
5 # Actions for use in token specifications
7 #=======================================================================
11 def perform(self
, token_stream
, text
):
14 def same_as(self
, other
):
20 Internal Plex action which causes |value| to
21 be returned as the value of the associated token
24 def __init__(self
, value
):
27 def perform(self
, token_stream
, text
):
30 def same_as(self
, other
):
31 return isinstance(other
, Return
) and self
.value
== other
.value
34 return "Return(%s)" % repr(self
.value
)
39 Internal Plex action which causes a function to be called.
42 def __init__(self
, function
):
43 self
.function
= function
45 def perform(self
, token_stream
, text
):
46 return self
.function(token_stream
, text
)
49 return "Call(%s)" % self
.function
.__name
__
51 def same_as(self
, other
):
52 return isinstance(other
, Call
) and self
.function
is other
.function
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
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
)
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
77 IGNORE is a Plex action which causes its associated token
78 to be ignored. See the docstring of Plex.Lexicon for more
81 def perform(self
, token_stream
, text
):
88 #IGNORE.__doc__ = Ignore.__doc__
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.
97 def perform(self
, token_stream
, text
):
104 #TEXT.__doc__ = Text.__doc__