Skip to content

Commit 6864950

Browse files
committed
Small changes
blacken buffers, go over docstrings
1 parent 5958c69 commit 6864950

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

mathics_scanner/errors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
#!/usr/bin/env python3
21
# -*- coding: utf-8 -*-
32

43

54
class TranslateError(Exception):
6-
"""A generic class of tokenization errors"""
5+
"""A generic class of tokenization errors. This exception is subclassed by other tokenization errors"""
6+
77
pass
88

99

1010
class ScanError(TranslateError):
1111
"""A generic scanning error"""
12+
1213
pass
1314

1415

1516
class InvalidSyntaxError(TranslateError):
1617
"""Invalid syntax"""
18+
1719
pass
1820

1921

2022
class IncompleteSyntaxError(TranslateError):
2123
"""More characters were expected to form a valid token"""
22-
pass
2324

25+
pass

mathics_scanner/feed.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# -*- coding: utf-8 -*-
12
"""
2-
Rather than trying to parse all the code at once this module implements methods
3+
Rather than trying to parse all the lines of code at once, this module implements methods
34
for returning one line code at a time.
45
"""
56

@@ -8,14 +9,15 @@
89

910

1011
class LineFeeder(metaclass=ABCMeta):
12+
"""An abstract representation for reading lines of characters, a
13+
"feeder". The purpose of a feeder is to mediate the consumption of
14+
characters between the tokeniser and the actual file being scaned,
15+
as well to store messages regarding tokenization errors.
1116
"""
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-
"""
16-
def __init__(self, filename):
17+
18+
def __init__(self, filename: str):
1719
"""
18-
@param: filename A string that describes the source of the feeder, i.e.
20+
:param filename: A string that describes the source of the feeder, i.e.
1921
the filename that is being feed.
2022
"""
2123
self.messages = []
@@ -28,16 +30,16 @@ def feed(self):
2830
Consume and return next line of code. Each line should be followed by a
2931
newline character. Returns '' after all lines are consumed.
3032
"""
31-
return
33+
return ""
3234

3335
@abstractmethod
3436
def empty(self):
3537
"""
3638
Return True once all lines have been consumed.
3739
"""
38-
return
40+
return True
3941

40-
def message(self, sym, tag, *args):
42+
def message(self, sym: str, tag, *args):
4143
"""
4244
Append a generic message of type ``sym`` to the message queue.
4345
"""
@@ -47,7 +49,7 @@ def message(self, sym, tag, *args):
4749
message = [sym, tag] + list(args)
4850
self.messages.append(message)
4951

50-
def syntax_message(self, sym, tag, *args):
52+
def syntax_message(self, sym: str, tag, *args):
5153
"""
5254
Append a message concerning syntax errors to the message queue.
5355
"""
@@ -64,11 +66,11 @@ def syntax_message(self, sym, tag, *args):
6466
assert len(message) == 7
6567
return message
6668

67-
# TODO: Rethink this (this is only usefull for core, not anyone else)
68-
def send_messages(self, evaluation):
69-
for message in self.messages:
70-
evaluation.message(*message)
71-
self.messages = []
69+
# # TODO: Rethink this?
70+
# def syntax_message(self, sym: str, tag, *args):
71+
# for message in self.messages:
72+
# evaluation.message(*message)
73+
# self.messages = []
7274

7375

7476
class MultiLineFeeder(LineFeeder):
@@ -138,7 +140,7 @@ def __init__(self, fileobject, trace_fn=None):
138140
self.eof = False
139141
self.trace_fn = trace_fn
140142

141-
def feed(self):
143+
def feed(self) -> str:
142144
result = self.fileobject.readline()
143145
while result == "\n":
144146
result = self.fileobject.readline()
@@ -151,6 +153,5 @@ def feed(self):
151153
self.eof = True
152154
return result
153155

154-
def empty(self):
156+
def empty(self) -> bool:
155157
return self.eof
156-

0 commit comments

Comments
 (0)