class_docstr: Compiles a grammar. This will take the parse tree of a regular expression
  and compile the grammar.
  
  :param root_node: :class~`.regex_parser.Node` instance.
  :param escape_funcs: `dict` mapping variable names to escape callables.
  :param unescape_funcs: `dict` mapping variable names to unescape callables.
docstr: Yield all the regular expressions matching a prefix of the grammar
  defined by the `Node` instance.
  
  This can yield multiple expressions, because in the case of on OR
  operation in the grammar, we can have another outcome depending on
  which clause would appear first. E.g. "(A|B)C" is not the same as
  "(B|A)C" because the regex engine is lazy and takes the first match.
  However, because we the current input is actually a prefix of the
  grammar which meight not yet contain the data for "C", we need to know
  both intermediate states, in order to call the appropriate
  autocompletion for both cases.
  
  :param root_node: The :class:`Node` instance for which we generate the grammar.
  :param create_group_func: A callable which takes a `Node` and returns the next
      free name for this node.
docstr_tok: ["Yield","all","the","regular","expressions","matching","a","prefix","of","the","grammar","defined","by","the","`","Node","`","instance",".","This","can","yield","multiple","expressions",",","because","in","the","case","of","on","OR","operation","in","the","grammar",",","we","can","have","another","outcome","depending","on","which","clause","would","appear","first",".","E.g",".","``","(","A|B",")","C","''","is","not","the","same","as","''","(","B|A",")","C","''","because","the","regex","engine","is","lazy","and","takes","the","first","match",".","However",",","because","we","the","current","input","is","actually","a","prefix","of","the","grammar","which","meight","not","yet","contain","the","data","for","``","C","''",",","we","need","to","know","both","intermediate","states",",","in","order","to","call","the","appropriate","autocompletion","for","both","cases",".",":","param","root_node",":","The",":","class",":","`","Node","`","instance","for","which","we","generate","the","grammar",".",":","param","create_group_func",":","A","callable","which","takes","a","`","Node","`","and","returns","the","next","free","name","for","this","node","."]
code: def _transform_prefix(cls, root_node, create_group_func):
      """
      Yield all the regular expressions matching a prefix of the grammar
      defined by the `Node` instance.
  
      This can yield multiple expressions, because in the case of on OR
      operation in the grammar, we can have another outcome depending on
      which clause would appear first. E.g. "(A|B)C" is not the same as
      "(B|A)C" because the regex engine is lazy and takes the first match.
      However, because we the current input is actually a prefix of the
      grammar which meight not yet contain the data for "C", we need to know
      both intermediate states, in order to call the appropriate
      autocompletion for both cases.
  
      :param root_node: The :class:`Node` instance for which we generate the grammar.
      :param create_group_func: A callable which takes a `Node` and returns the next
          free name for this node.
      """
  
      def transform(node):
          # Generate regexes for all permutations of this OR. Each node
          # should be in front once.
          if isinstance(node, Any):
              for c in node.children:
                  for r in transform(c):
                      yield "(?:%s)?" % r
  
          # For a sequence. We can either have a match for the sequence
          # of all the children, or for an exact match of the first X
          # children, followed by a partial match of the next children.
          elif isinstance(node, Sequence):
              for i in range(len(node.children)):
                  a = [
                      cls._transform(c, create_group_func)
                      for c in node.children[:i]
                  ]
                  for c in transform(node.children[i]):
                      yield "(?:%s)" % ("".join(a) + c)
  
          elif isinstance(node, Regex):
              yield "(?:%s)?" % node.regex
  
          elif isinstance(node, Lookahead):
              if node.negative:
                  yield "(?!%s)" % cls._transform(
                      node.childnode, create_group_func
                  )
              else:
                  # Not sure what the correct semantics are in this case.
                  # (Probably it's not worth implementing this.)
                  raise Exception(
                      "Positive lookahead not yet supported."
                  )
  
          elif isinstance(node, Variable):
              # (Note that we should not append a '?' here. the 'transform'
              # method will already recursively do that.)
              for c in transform(node.childnode):
                  yield "(?P<%s>%s)" % (create_group_func(node), c)
  
          elif isinstance(node, Repeat):
              # If we have a repetition of 8 times. That would mean that the
              # current input could have for instance 7 times a complete
              # match, followed by a partial match.
              prefix = cls._transform(node.childnode, create_group_func)
  
              for c in transform(node.childnode):
                  if node.max_repeat:
                      repeat_sign = "{,%i}" % (node.max_repeat - 1)
                  else:
                      repeat_sign = "*"
                  yield "(?:%s)%s%s(?:%s)?" % (
                      prefix,
                      repeat_sign,
                      ("" if node.greedy else "?"),
                      c,
                  )
  
          else:
              raise TypeError("Got %r" % node)
  
      for r in transform(root_node):
          yield "^%s$" % r
  
imports: from __future__ import unicode_literals
  import re
  from six.moves import range
  from .regex_parser import Any, Sequence, Regex, Variable, Repeat, Lookahead
  from .regex_parser import parse_regex, tokenize_regex
label_desc: Use image node_id 5 for calling the _CompiledGrammar obj's underlying member method code with example usage: obj._transform_prefix(cls, root_node, create_group_func) without return types