diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-15 14:10:20 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-15 14:11:01 -0500 |
| commit | 0b063a10249558ede919bcd7f67c6aa563ba74ab (patch) | |
| tree | 80f4db74de258b8664db52e1c5e430b820667201 /flake8/processor.py | |
| parent | 576d1f6c85b321f4a9897a386af8815a7ca779d4 (diff) | |
| download | flake8-0b063a10249558ede919bcd7f67c6aa563ba74ab.tar.gz | |
Run checks expecting an AST
Diffstat (limited to 'flake8/processor.py')
| -rw-r--r-- | flake8/processor.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/flake8/processor.py b/flake8/processor.py index d75256b..1dc27a1 100644 --- a/flake8/processor.py +++ b/flake8/processor.py @@ -10,6 +10,7 @@ from flake8 import defaults from flake8 import exceptions from flake8 import utils +PyCF_ONLY_AST = 1024 NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) # Work around Python < 2.6 behaviour, which does not generate NL after # a comment which is on a line by itself. @@ -172,6 +173,10 @@ class FileProcessor(object): (previous_row, previous_column) = end return comments, logical, mapping + def build_ast(self): + """Build an abstract syntax tree from the list of lines.""" + return compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) + def build_logical_line(self): """Build a logical line from the current tokens list.""" comments, logical, mapping_list = self.build_logical_line_tokens() @@ -223,6 +228,10 @@ class FileProcessor(object): except tokenize.TokenError as exc: raise exceptions.InvalidSyntax(exc.message, exception=exc) + def line_for(self, line_number): + """Retrieve the physical line at the specified line number.""" + return self.lines[line_number - 1] + def next_line(self): """Get the next line from the list.""" if self.line_number >= self.total_lines: |
