Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
lib2to3.pgen2.driver.Driver Class Reference
Inheritance diagram for lib2to3.pgen2.driver.Driver:
Inheritance graph
[legend]
Collaboration diagram for lib2to3.pgen2.driver.Driver:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def parse_tokens
def parse_stream_raw
def parse_stream
def parse_file
def parse_string

Public Attributes

 grammar
 logger
 convert
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 28 of file driver.py.


Constructor & Destructor Documentation

def lib2to3.pgen2.driver.Driver.__init__ (   self,
  grammar,
  convert = None,
  logger = None 
)

Definition at line 30 of file driver.py.

00030 
00031     def __init__(self, grammar, convert=None, logger=None):
00032         self.grammar = grammar
00033         if logger is None:
00034             logger = logging.getLogger()
00035         self.logger = logger
00036         self.convert = convert

Here is the caller graph for this function:


Member Function Documentation

def lib2to3.pgen2.driver.Driver.parse_file (   self,
  filename,
  encoding = None,
  debug = False 
)
Parse a file and return the syntax tree.

Definition at line 94 of file driver.py.

00094 
00095     def parse_file(self, filename, encoding=None, debug=False):
00096         """Parse a file and return the syntax tree."""
00097         stream = codecs.open(filename, "r", encoding)
00098         try:
00099             return self.parse_stream(stream, debug)
00100         finally:
00101             stream.close()

Here is the call graph for this function:

def lib2to3.pgen2.driver.Driver.parse_stream (   self,
  stream,
  debug = False 
)
Parse a stream and return the syntax tree.

Definition at line 90 of file driver.py.

00090 
00091     def parse_stream(self, stream, debug=False):
00092         """Parse a stream and return the syntax tree."""
00093         return self.parse_stream_raw(stream, debug)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pgen2.driver.Driver.parse_stream_raw (   self,
  stream,
  debug = False 
)
Parse a stream and return the syntax tree.

Definition at line 85 of file driver.py.

00085 
00086     def parse_stream_raw(self, stream, debug=False):
00087         """Parse a stream and return the syntax tree."""
00088         tokens = tokenize.generate_tokens(stream.readline)
00089         return self.parse_tokens(tokens, debug)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pgen2.driver.Driver.parse_string (   self,
  text,
  debug = False 
)
Parse a string and return the syntax tree.

Definition at line 102 of file driver.py.

00102 
00103     def parse_string(self, text, debug=False):
00104         """Parse a string and return the syntax tree."""
00105         tokens = tokenize.generate_tokens(generate_lines(text).__next__)
00106         return self.parse_tokens(tokens, debug)
00107 

Here is the call graph for this function:

def lib2to3.pgen2.driver.Driver.parse_tokens (   self,
  tokens,
  debug = False 
)
Parse a series of tokens and return the syntax tree.

Definition at line 37 of file driver.py.

00037 
00038     def parse_tokens(self, tokens, debug=False):
00039         """Parse a series of tokens and return the syntax tree."""
00040         # XXX Move the prefix computation into a wrapper around tokenize.
00041         p = parse.Parser(self.grammar, self.convert)
00042         p.setup()
00043         lineno = 1
00044         column = 0
00045         type = value = start = end = line_text = None
00046         prefix = ""
00047         for quintuple in tokens:
00048             type, value, start, end, line_text = quintuple
00049             if start != (lineno, column):
00050                 assert (lineno, column) <= start, ((lineno, column), start)
00051                 s_lineno, s_column = start
00052                 if lineno < s_lineno:
00053                     prefix += "\n" * (s_lineno - lineno)
00054                     lineno = s_lineno
00055                     column = 0
00056                 if column < s_column:
00057                     prefix += line_text[column:s_column]
00058                     column = s_column
00059             if type in (tokenize.COMMENT, tokenize.NL):
00060                 prefix += value
00061                 lineno, column = end
00062                 if value.endswith("\n"):
00063                     lineno += 1
00064                     column = 0
00065                 continue
00066             if type == token.OP:
00067                 type = grammar.opmap[value]
00068             if debug:
00069                 self.logger.debug("%s %r (prefix=%r)",
00070                                   token.tok_name[type], value, prefix)
00071             if p.addtoken(type, value, (prefix, start)):
00072                 if debug:
00073                     self.logger.debug("Stop.")
00074                 break
00075             prefix = ""
00076             lineno, column = end
00077             if value.endswith("\n"):
00078                 lineno += 1
00079                 column = 0
00080         else:
00081             # We never broke out -- EOF is too soon (how can this happen???)
00082             raise parse.ParseError("incomplete input",
00083                                    type, value, (prefix, start))
00084         return p.rootnode

Here is the caller graph for this function:


Member Data Documentation

Definition at line 35 of file driver.py.

Definition at line 31 of file driver.py.

Definition at line 34 of file driver.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: