Lines Matching refs:line

13        line-by-line syntax: strip comments (as long as "#" is your
15 escaping the newline (ie. backslash at end of line), strip
20 report physical line number, even if the logical line in question
22 implementing line-at-a-time lookahead.
38 strip from "#" to end-of-line, as well as any whitespace
41 strip leading whitespace from each line before returning it
43 strip trailing whitespace (including line terminator!) from
44 each line before returning it
51 if a backslash is the last non-newline character on a line
52 after stripping comments and whitespace, join the following line
53 to it to form one "logical line"; if N consecutive lines end
55 form one logical line.
65 None for end-of-file: an empty string might just be a blank line (or
66 an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is
120 (filename, current line number)."""
127 def gen_error(self, msg, line=None):
129 if line is None:
130 line = self.current_line
132 if isinstance(line, (list, tuple)):
133 outmsg.append("lines %d-%d: " % tuple(line))
135 outmsg.append("line %d: " % line)
139 def error(self, msg, line=None):
140 raise ValueError("error: " + self.gen_error(msg, line))
142 def warn(self, msg, line=None):
144 line in the current file. If the current logical line in the
146 whole range, eg. "lines 3-5". If 'line' supplied, it overrides
147 the current line number; it may be a list or tuple to indicate a
149 line."""
150 sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
153 """Read and return a single logical line from the current file (or
157 single string. Updates the current line number, so calling
159 line(s) just read. Returns None on end-of-file, since the empty
167 line = self.linebuf[-1]
169 return line
174 # read the line, make it None if EOF
175 line = self.file.readline()
176 if line == '':
177 line = None
179 if self.strip_comments and line:
181 # Look for the first "#" in the line. If none, never
187 # lurking in there) and otherwise leave the line alone.
189 pos = line.find("#")
195 elif pos == 0 or line[pos-1] != "\\":
199 # (NB. this means that if the final line is all comment
202 eol = (line[-1] == '\n') and '\n' or ''
203 line = line[0:pos] + eol
205 # If all that's left is whitespace, then skip line
212 if line.strip() == "":
215 line = line.replace("\\#", "#")
217 # did previous line end with a backslash? then accumulate
220 if line is None:
221 self.warn("continuation line immediately precedes "
226 line = line.lstrip()
227 line = buildup_line + line
229 # careful: pay attention to line number when incrementing it
235 # just an ordinary line, read it as usual
237 if line is None: # eof
240 # still have to be careful about incrementing the line number!
249 line = line.strip()
251 line = line.lstrip()
253 line = line.rstrip()
255 # blank line (whether we rstrip'ed or not)? skip to next line
257 if (line == '' or line == '\n') and self.skip_blanks:
261 if line[-1] == '\\':
262 buildup_line = line[:-1]
265 if line[-2:] == '\\\n':
266 buildup_line = line[0:-2] + '\n'
270 return line
277 line = self.readline()
278 if line is None:
280 lines.append(line)
282 def unreadline(self, line):
283 """Push 'line' (a string) onto an internal buffer that will be
285 a parser with line-at-a-time lookahead."""
286 self.linebuf.append(line)