Skip to content

Commit 73e8a43

Browse files
committed
Documented the feeders
1 parent 03ea0c6 commit 73e8a43

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

mathics_scanner/feed.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88

99

1010
class LineFeeder(metaclass=ABCMeta):
11+
"""
12+
An abstract representation for a feeder. The purpose of a feeder is to
13+
mediate the consumption of characters between the tokeniser and the actual
14+
file being scaned, as well to store messages regarding tokenization errors.
15+
"""
1116
def __init__(self, filename):
17+
"""
18+
@param: filename A string that describes the source of the feeder, i.e.
19+
the filename that is being feed.
20+
"""
1221
self.messages = []
1322
self.lineno = 0
1423
self.filename = filename
@@ -29,13 +38,19 @@ def empty(self):
2938
return
3039

3140
def message(self, sym, tag, *args):
41+
"""
42+
Append a generic message of type ``sym`` to the message queue.
43+
"""
3244
if sym == "Syntax":
3345
message = self.syntax_message(sym, tag, *args)
3446
else:
3547
message = [sym, tag] + list(args)
3648
self.messages.append(message)
3749

3850
def syntax_message(self, sym, tag, *args):
51+
"""
52+
Append a message concerning syntax errors to the message queue.
53+
"""
3954
if len(args) > 3:
4055
raise ValueError("Too many args.")
4156
message = [sym, tag]
@@ -49,16 +64,22 @@ def syntax_message(self, sym, tag, *args):
4964
assert len(message) == 7
5065
return message
5166

67+
# TODO: Rethink this (this is only usefull for core, not anyone else)
5268
def send_messages(self, evaluation):
5369
for message in self.messages:
5470
evaluation.message(*message)
5571
self.messages = []
5672

5773

5874
class MultiLineFeeder(LineFeeder):
59-
"Feeds one line at a time."
75+
"A feeder that feeds one line at a time."
6076

6177
def __init__(self, lines, filename=""):
78+
"""
79+
@param: lines The source of the feeder (a string).
80+
@param: filename A string that describes the source of the feeder, i.e.
81+
the filename that is being feed.
82+
"""
6283
super(MultiLineFeeder, self).__init__(filename)
6384
self.lineno = 0
6485
if isinstance(lines, str):
@@ -79,9 +100,14 @@ def empty(self):
79100

80101

81102
class SingleLineFeeder(LineFeeder):
82-
"Feeds all the code as a single line."
103+
"A feeder that feeds all the code as a single line."
83104

84105
def __init__(self, code, filename=""):
106+
"""
107+
@param: code The source of the feeder (a string).
108+
@param: filename A string that describes the source of the feeder, i.e.
109+
the filename that is being feed.
110+
"""
85111
super().__init__(filename)
86112
self.code = code
87113
self._empty = False
@@ -98,9 +124,14 @@ def empty(self):
98124

99125

100126
class FileLineFeeder(LineFeeder):
101-
"Feeds lines from an open file object"
127+
"A feeder that feeds lines from an open ``File`` object"
102128

103129
def __init__(self, fileobject, trace_fn=None):
130+
"""
131+
@param: fileobject The source of the feeder (a string).
132+
@param: filename A string that describes the source of the feeder,
133+
i.e. the filename that is being feed.
134+
"""
104135
super().__init__(fileobject.name)
105136
self.fileobject = fileobject
106137
self.lineno = 0
@@ -122,3 +153,4 @@ def feed(self):
122153

123154
def empty(self):
124155
return self.eof
156+

0 commit comments

Comments
 (0)