class_docstr: Base class for magic line parsers, designed for forgiving parsing
  of keyword lists.
docstr: Helper function to return dictionary given the parse results
  from a pyparsing.nestedExpr object (containing keywords).
  
  The ns is a dynamic namespace (typically the IPython Notebook
  namespace) used to update the class-level namespace.
docstr_tok: ["Helper","function","to","return","dictionary","given","the","parse","results","from","a","pyparsing.nestedExpr","object","(","containing","keywords",")",".","The","ns","is","a","dynamic","namespace","(","typically","the","IPython","Notebook","namespace",")","used","to","update","the","class-level","namespace","."]
code: def todict(cls, parseresult, mode="parens", ns=None):
      """
      Helper function to return dictionary given the parse results
      from a pyparsing.nestedExpr object (containing keywords).
  
      The ns is a dynamic namespace (typically the IPython Notebook
      namespace) used to update the class-level namespace.
      """
      if ns is None:
          ns = {}
      grouped, kwargs = [], {}
      tokens = cls.collect_tokens(parseresult, mode)
      # Group tokens without '=' and append to last token containing '='
      for group in groupby(tokens, lambda el: "=" in el):
          (val, items) = group
          if val is True:
              grouped += list(items)
          if val is False:
              elements = list(items)
              # Assume anything before ) or } can be joined with commas
              # (e.g. tuples with spaces in them)
              joiner = (
                  ","
                  if any(
                      ((")" in el) or ("}" in el)) for el in elements
                  )
                  else ""
              )
              grouped[-1] += joiner + joiner.join(elements)
  
      for keyword in grouped:
          # Tuple ('a', 3) becomes (,'a',3) and '(,' is never valid
          # Same for some of the other joining errors corrected here
          for fst, snd in [
              ("(,", "("),
              ("{,", "{"),
              ("=,", "="),
              (",:", ":"),
              (":,", ":"),
              (",,", ","),
              (",.", "."),
          ]:
              keyword = keyword.replace(fst, snd)
          try:
              kwargs.update(
                  eval(f"dict({keyword})", dict(cls.namespace, **ns))
              )
          except Exception:
              if cls.abort_on_eval_failure:
                  raise SyntaxError(
                      f"Could not evaluate keyword: {keyword!r}"
                  ) from None
              msg = "Ignoring keyword pair that fails to evaluate: '%s'"
              parsewarning.warning(msg % keyword)
  
      return kwargs
  
imports: from itertools import groupby
  import numpy
  import param
  import pyparsing
  from ..core.options import Cycle, Options, Palette
  from ..core.util import merge_option_dicts
  from ..operation import Compositor
  from .transform import dim
label_desc: Use image node_id 4 for calling the Parser obj's underlying member method code with example usage: obj.todict(cls, parseresult, mode, ns) and returns: kwargs