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
34for returning one line code at a time.
45"""
56
89
910
1011class 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
7476class 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