Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
parsimonious.nodes.NodeVisitor Class Reference
Inheritance diagram for parsimonious.nodes.NodeVisitor:
Inheritance graph
[legend]
Collaboration diagram for parsimonious.nodes.NodeVisitor:
Collaboration graph
[legend]

Public Member Functions

 visit (self, node)
 
 generic_visit (self, node, visited_children)
 
 parse (self, text, pos=0)
 
 match (self, text, pos=0)
 
 lift_child (self, node, children)
 
- Public Member Functions inherited from parsimonious.nodes.RuleDecoratorMeta
 __new__ (metaclass, name, bases, namespace)
 

Public Attributes

 unwrapped_exceptions
 

Static Public Attributes

 grammar = None
 
tuple unwrapped_exceptions = ()
 

Protected Member Functions

 _parse_or_match (self, text, pos, method_name)
 

Detailed Description

A shell for writing things that turn parse trees into something useful

Performs a depth-first traversal of an AST. Subclass this, add methods for
each expr you care about, instantiate, and call
``visit(top_node_of_parse_tree)``. It'll return the useful stuff. This API
is very similar to that of ``ast.NodeVisitor``.

These could easily all be static methods, but that would add at least as
much weirdness at the call site as the ``()`` for instantiation. And this
way, we support subclasses that require state: options, for example, or a
symbol table constructed from a programming language's AST.

We never transform the parse tree in place, because...

* There are likely multiple references to the same ``Node`` object in a
  parse tree, and changes to one reference would surprise you elsewhere.
* It makes it impossible to report errors: you'd end up with the "error"
  arrow pointing someplace in a half-transformed mishmash of nodes--and
  that's assuming you're even transforming the tree into another tree.
  Heaven forbid you're making it into a string or something else.

Member Function Documentation

◆ _parse_or_match()

parsimonious.nodes.NodeVisitor._parse_or_match (   self,
  text,
  pos,
  method_name 
)
protected
Execute a parse or match on the default grammar, followed by a
visitation.

Raise RuntimeError if there is no default grammar specified.

◆ generic_visit()

parsimonious.nodes.NodeVisitor.generic_visit (   self,
  node,
  visited_children 
)
Default visitor method

:arg node: The node we're visiting
:arg visited_children: The results of visiting the children of that
    node, in a list

I'm not sure there's an implementation of this that makes sense across
all (or even most) use cases, so we leave it to subclasses to implement
for now.

Reimplemented in parsimonious.grammar.RuleVisitor, and sphinx_js.parsers.PathVisitor.

◆ lift_child()

parsimonious.nodes.NodeVisitor.lift_child (   self,
  node,
  children 
)
Lift the sole child of ``node`` up to replace the node.

◆ match()

parsimonious.nodes.NodeVisitor.match (   self,
  text,
  pos = 0 
)
Parse and visit some text with this Visitor's default grammar, but
don't insist on parsing all the way to the end.

``SomeVisitor().match('some_string')`` is a shortcut for
``SomeVisitor().visit(some_grammar.match('some_string'))``.

◆ parse()

parsimonious.nodes.NodeVisitor.parse (   self,
  text,
  pos = 0 
)
Parse some text with this Visitor's default grammar and return the
result of visiting it.

``SomeVisitor().parse('some_string')`` is a shortcut for
``SomeVisitor().visit(some_grammar.parse('some_string'))``.

◆ visit()

parsimonious.nodes.NodeVisitor.visit (   self,
  node 
)
Walk a parse tree, transforming it into another representation.

Recursively descend a parse tree, dispatching to the method named after
the rule in the :class:`~parsimonious.grammar.Grammar` that produced
each node. If, for example, a rule was... ::

    bold = '<b>'

...the ``visit_bold()`` method would be called. It is your
responsibility to subclass :class:`NodeVisitor` and implement those
methods.

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