Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions
parsimonious.nodes Namespace Reference

Classes

class  Node
 
class  NodeVisitor
 
class  RegexNode
 
class  RuleDecoratorMeta
 

Functions

 rule (rule_string)
 

Detailed Description

Nodes that make up parse trees

Parsing spits out a tree of these, which you can then tell to walk itself and
spit out a useful value. Or you can walk it yourself; the structural attributes
are public.

Function Documentation

◆ rule()

parsimonious.nodes.rule (   rule_string)
Decorate a NodeVisitor ``visit_*`` method to tie a grammar rule to it.

The following will arrange for the ``visit_digit`` method to receive the
results of the ``~"[0-9]"`` parse rule::

    @rule('~"[0-9]"')
    def visit_digit(self, node, visited_children):
        ...

Notice that there is no "digit = " as part of the rule; that gets inferred
from the method name.

In cases where there is only one kind of visitor interested in a grammar,
using ``@rule`` saves you having to look back and forth between the visitor
and the grammar definition.

On an implementation level, all ``@rule`` rules get stitched together into
a :class:`~parsimonious.Grammar` that becomes the NodeVisitor's
:term:`default grammar`.

Typically, the choice of a default rule for this grammar is simple: whatever
``@rule`` comes first in the class is the default. But the choice may become
surprising if you divide the ``@rule`` calls among subclasses. At the
moment, which method "comes first" is decided simply by comparing line
numbers, so whatever method is on the smallest-numbered line will be the
default. In a future release, this will change to pick the
first ``@rule`` call on the basemost class that has one. That way, a
subclass which does not override the default rule's ``visit_*`` method
won't unintentionally change which rule is the default.