• Home
  • Raw
  • Download

Lines Matching full:line

16        line-by-line syntax: strip comments (as long as "#" is your
18 escaping the newline (ie. backslash at end of line), strip
23 report physical line number, even if the logical line in question
25 implementing line-at-a-time lookahead.
41 strip from "#" to end-of-line, as well as any whitespace
44 strip leading whitespace from each line before returning it
46 strip trailing whitespace (including line terminator!) from
47 each line before returning it
54 if a backslash is the last non-newline character on a line
55 after stripping comments and whitespace, join the following line
56 to it to form one "logical line"; if N consecutive lines end
58 form one logical line.
66 None for end-of-file: an empty string might just be a blank line (or
67 an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is
126 (filename, current line number)."""
134 def gen_error (self, msg, line=None): argument
136 if line is None:
137 line = self.current_line
139 if isinstance(line, (list, tuple)):
140 outmsg.append("lines %d-%d: " % tuple (line))
142 outmsg.append("line %d: " % line)
147 def error (self, msg, line=None): argument
148 raise ValueError, "error: " + self.gen_error(msg, line)
150 def warn (self, msg, line=None): argument
152 line in the current file. If the current logical line in the
154 whole range, eg. "lines 3-5". If 'line' supplied, it overrides
155 the current line number; it may be a list or tuple to indicate a
157 line."""
158 sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
162 """Read and return a single logical line from the current file (or
166 single string. Updates the current line number, so calling
168 line(s) just read. Returns None on end-of-file, since the empty
177 line = self.linebuf[-1]
179 return line
184 # read the line, make it None if EOF
185 line = self.file.readline()
186 if line == '': line = None
188 if self.strip_comments and line:
190 # Look for the first "#" in the line. If none, never
196 # lurking in there) and otherwise leave the line alone.
198 pos = line.find("#")
204 elif pos == 0 or line[pos-1] != "\\":
208 # (NB. this means that if the final line is all comment
211 eol = (line[-1] == '\n') and '\n' or ''
212 line = line[0:pos] + eol
214 # If all that's left is whitespace, then skip line
221 if line.strip() == "":
225 line = line.replace("\\#", "#")
228 # did previous line end with a backslash? then accumulate
231 if line is None:
232 self.warn ("continuation line immediately precedes "
237 line = line.lstrip()
238 line = buildup_line + line
240 # careful: pay attention to line number when incrementing it
246 # just an ordinary line, read it as usual
248 if line is None: # eof
251 # still have to be careful about incrementing the line number!
261 line = line.strip()
263 line = line.lstrip()
265 line = line.rstrip()
267 # blank line (whether we rstrip'ed or not)? skip to next line
269 if (line == '' or line == '\n') and self.skip_blanks:
273 if line[-1] == '\\':
274 buildup_line = line[:-1]
277 if line[-2:] == '\\\n':
278 buildup_line = line[0:-2] + '\n'
282 return line
293 line = self.readline()
294 if line is None:
296 lines.append (line)
299 def unreadline (self, line): argument
300 """Push 'line' (a string) onto an internal buffer that will be
302 a parser with line-at-a-time lookahead."""
304 self.linebuf.append (line)