1
#=======================================================================
3
# Python Lexical Analyser
5
# Actions for use in token specifications
7
#=======================================================================
11
def same_as(self, other):
17
Internal Plex action which causes |value| to
18
be returned as the value of the associated token
23
def __init__(self, value):
26
def perform(self, token_stream, text):
29
def same_as(self, other):
30
return isinstance(other, Return) and self.value == other.value
33
return "Return(%s)" % repr(self.value)
38
Internal Plex action which causes a function to be called.
43
def __init__(self, function):
44
self.function = function
46
def perform(self, token_stream, text):
47
return self.function(token_stream, text)
50
return "Call(%s)" % self.function.__name__
52
def same_as(self, other):
53
return isinstance(other, Call) and self.function is other.function
58
Begin(state_name) is a Plex action which causes the Scanner to
59
enter the state |state_name|. See the docstring of Plex.Lexicon
65
def __init__(self, state_name):
66
self.state_name = state_name
68
def perform(self, token_stream, text):
69
token_stream.begin(self.state_name)
72
return "Begin(%s)" % (self.state_name,)
74
def same_as(self, other):
75
return isinstance(other, Begin) and self.state_name == other.state_name
80
IGNORE is a Plex action which causes its associated token
81
to be ignored. See the docstring of Plex.Lexicon for more
84
def perform(self, token_stream, text):
91
IGNORE.__doc__ = Ignore.__doc__
95
TEXT is a Plex action which causes the text of a token to
96
be returned as the value of the token. See the docstring of
97
Plex.Lexicon for more information.
100
def perform(self, token_stream, text):
107
TEXT.__doc__ = Text.__doc__