class_docstr: Parser engine.
  
  The proper usage sequence is:
  
  p = Parser(grammar, [converter])  # create instance
  p.setup([start])                  # prepare for parsing
  <for each input token>:
      if p.addtoken(...):           # parse a token; may raise ParseError
          break
  root = p.rootnode                 # root of abstract syntax tree
  
  A Parser instance may be reused by calling setup() repeatedly.
  
  A Parser instance contains state pertaining to the current token
  sequence, and should not be used concurrently by different threads
  to parse separate token sequences.
  
  See driver.py for how to get input tokens by tokenizing a file or
  string.
  
  Parsing is complete when addtoken() returns True; the root of the
  abstract syntax tree can then be retrieved from the rootnode
  instance variable.  When a syntax error occurs, addtoken() raises
  the ParseError exception.  There is no error recovery; the parser
  cannot be used after a syntax error was reported (but it can be
  reinitialized by calling setup()).
class_docstr_tok: ["Parser","engine",".","The","proper","usage","sequence","is",":","p","=","Parser","(","grammar",",","[","converter","]",")","#","create","instance","p.setup","(","[","start","]",")","#","prepare","for","parsing","<","for","each","input","token",">",":","if","p.addtoken","(","...",")",":","#","parse","a","token",";","may","raise","ParseError","break","root","=","p.rootnode","#","root","of","abstract","syntax","tree","A","Parser","instance","may","be","reused","by","calling","setup","(",")","repeatedly",".","A","Parser","instance","contains","state","pertaining","to","the","current","token","sequence",",","and","should","not","be","used","concurrently","by","different","threads","to","parse","separate","token","sequences",".","See","driver.py","for","how","to","get","input","tokens","by","tokenizing","a","file","or","string",".","Parsing","is","complete","when","addtoken","(",")","returns","True",";","the","root","of","the","abstract","syntax","tree","can","then","be","retrieved","from","the","rootnode","instance","variable",".","When","a","syntax","error","occurs",",","addtoken","(",")","raises","the","ParseError","exception",".","There","is","no","error","recovery",";","the","parser","can","not","be","used","after","a","syntax","error","was","reported","(","but","it","can","be","reinitialized","by","calling","setup","(",")",")","."]
docstr: Constructor.
  
  The grammar argument is a grammar.Grammar instance; see the
  grammar module for more information.
  
  The parser is not ready yet for parsing; you must call the
  setup() method to get it started.
  
  The optional convert argument is a function mapping concrete
  syntax tree nodes to abstract syntax tree nodes.  If not
  given, no conversion is done and the syntax tree produced is
  the concrete syntax tree.  If given, it must be a function of
  two arguments, the first being the grammar (a grammar.Grammar
  instance), and the second being the concrete syntax tree node
  to be converted.  The syntax tree is converted from the bottom
  up.
  
  **post-note: the convert argument is ignored since for Black's
  usage, convert will always be blib2to3.pytree.convert. Allowing
  this to be dynamic hurts mypyc's ability to use early binding.
  These docs are left for historical and informational value.
  
  A concrete syntax tree node is a (type, value, context, nodes)
  tuple, where type is the node type (a token or symbol number),
  value is None for symbols and a string for tokens, context is
  None or an opaque value used for error reporting (typically a
  (lineno, offset) pair), and nodes is a list of children for
  symbols, and None for tokens.
  
  An abstract syntax tree node may be anything; this is entirely
  up to the converter function.
docstr_tok: ["Constructor",".","The","grammar","argument","is","a","grammar.Grammar","instance",";","see","the","grammar","module","for","more","information",".","The","parser","is","not","ready","yet","for","parsing",";","you","must","call","the","setup","(",")","method","to","get","it","started",".","The","optional","convert","argument","is","a","function","mapping","concrete","syntax","tree","nodes","to","abstract","syntax","tree","nodes",".","If","not","given",",","no","conversion","is","done","and","the","syntax","tree","produced","is","the","concrete","syntax","tree",".","If","given",",","it","must","be","a","function","of","two","arguments",",","the","first","being","the","grammar","(","a","grammar.Grammar","instance",")",",","and","the","second","being","the","concrete","syntax","tree","node","to","be","converted",".","The","syntax","tree","is","converted","from","the","bottom","up",".","*","*","post-note",":","the","convert","argument","is","ignored","since","for","Black's","usage",",","convert","will","always","be","blib2to3.pytree.convert",".","Allowing","this","to","be","dynamic","hurts","mypyc","'s","ability","to","use","early","binding",".","These","docs","are","left","for","historical","and","informational","value",".","A","concrete","syntax","tree","node","is","a","(","type",",","value",",","context",",","nodes",")","tuple",",","where","type","is","the","node","type","(","a","token","or","symbol","number",")",",","value","is","None","for","symbols","and","a","string","for","tokens",",","context","is","None","or","an","opaque","value","used","for","error","reporting","(","typically","a","(","lineno",",","offset",")","pair",")",",","and","nodes","is","a","list","of","children","for","symbols",",","and","None","for","tokens",".","An","abstract","syntax","tree","node","may","be","anything",";","this","is","entirely","up","to","the","converter","function","."]
code: def __init__(
      self, grammar: Grammar, convert: Optional[Convert] = None
  ) -> None:
      """Constructor.
  
      The grammar argument is a grammar.Grammar instance; see the
      grammar module for more information.
  
      The parser is not ready yet for parsing; you must call the
      setup() method to get it started.
  
      The optional convert argument is a function mapping concrete
      syntax tree nodes to abstract syntax tree nodes.  If not
      given, no conversion is done and the syntax tree produced is
      the concrete syntax tree.  If given, it must be a function of
      two arguments, the first being the grammar (a grammar.Grammar
      instance), and the second being the concrete syntax tree node
      to be converted.  The syntax tree is converted from the bottom
      up.
  
      **post-note: the convert argument is ignored since for Black's
      usage, convert will always be blib2to3.pytree.convert. Allowing
      this to be dynamic hurts mypyc's ability to use early binding.
      These docs are left for historical and informational value.
  
      A concrete syntax tree node is a (type, value, context, nodes)
      tuple, where type is the node type (a token or symbol number),
      value is None for symbols and a string for tokens, context is
      None or an opaque value used for error reporting (typically a
      (lineno, offset) pair), and nodes is a list of children for
      symbols, and None for tokens.
  
      An abstract syntax tree node may be anything; this is entirely
      up to the converter function.
  
      """
      self.grammar = grammar
      # See note in docstring above. TL;DR this is ignored.
      self.convert = convert or lam_sub
      self.is_backtracking = False
      self.last_token: Optional[int] = None
  
imports: from contextlib import contextmanager
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Union, cast
  from blib2to3.pgen2.grammar import Grammar
  from blib2to3.pytree import NL, Context, Leaf, Node, RawNode, convert
  from .None import grammar, token, tokenize
label_desc: Use image node_id 1 to create a new Parser object  with example: obj = Parser(grammar, convert)