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

Classes

class  Compound
 
class  Expression
 
class  Literal
 
class  Lookahead
 
class  OneOf
 
class  Quantifier
 
class  Regex
 
class  Sequence
 
class  TokenMatcher
 

Functions

 is_callable (value)
 
 expression (callable, rule_name, grammar)
 
 Not (term)
 
 ZeroOrMore (member, name='')
 
 OneOrMore (member, name='', min=1)
 
 Optional (member, name='')
 

Variables

 IN_PROGRESS = object()
 

Detailed Description

Subexpressions that make up a parsed grammar

These do the parsing.

Function Documentation

◆ expression()

parsimonious.expressions.expression (   callable,
  rule_name,
  grammar 
)
Turn a plain callable into an Expression.

The callable can be of this simple form::

    def foo(text, pos):
        '''If this custom expression matches starting at text[pos], return
        the index where it stops matching. Otherwise, return None.'''
        if the expression matched:
            return end_pos

If there child nodes to return, return a tuple::

    return end_pos, children

If the expression doesn't match at the given ``pos`` at all... ::

    return None

If your callable needs to make sub-calls to other rules in the grammar or
do error reporting, it can take this form, gaining additional arguments::

    def foo(text, pos, cache, error, grammar):
        # Call out to other rules:
        node = grammar['another_rule'].match_core(text, pos, cache, error)
        ...
        # Return values as above.

The return value of the callable, if an int or a tuple, will be
automatically transmuted into a :class:`~parsimonious.Node`. If it returns
a Node-like class directly, it will be passed through unchanged.

:arg rule_name: The rule name to attach to the resulting
    :class:`~parsimonious.Expression`
:arg grammar: The :class:`~parsimonious.Grammar` this expression will be a
    part of, to make delegating to other rules possible