Module yeanpypa :: Class Rule
[show private | hide private]
[frames | no frames]

Class Rule

Known Subclasses:
AndRule, AnyOf, CallbackParser, Combine, IgnoreWhite, Literal, MatchWhite, NoneOf, OneOrMore, Optional, OrRule, ZeroOrMore

The basic entity of a grammar: the rule. This class doesn't provide any parsing functionality on it's own. It merely provides some basic functions shared by all Rule classes.
Method Summary
  __add__(self, second_rule)
Define an operator to concat two rules.
  __or__(self, second_rule)
Define an operator to concat two rules via OR.
  callAction(self, param)
Call the action attached to this rule.
  hide(self)
Tell this rule to not produce any token output.
  match(input_reader)
Match the given rule in the string from the given position on.
  returnToken(self, token)
Helper function encapsulating the hide()-functionality.
  setAction(self, action)
Set the action to execute on a rule match.

Class Variable Summary
NoneType action = None                                                                  
bool hide_token = False

Method Details

__add__(self, second_rule)
(Addition operator)

Define an operator to concat two rules. The expressivness of the 'pseudo-language' defined by the framework heavily relies on operator overloading. The +-operator serves as a 'followed by' expression.
Parameters:
second_rule - The right operand of the +-operator which follows this object in grammar terms.
           (type=Rule @return An AndRule-object connecting these two rule appropriately.)

__or__(self, second_rule)
(Or operator)

Define an operator to concat two rules via OR. The expressivness of the 'pseudo-language' defined by the framework heavily relies on operator overloading. The |-operator serves as a 'OR' expression, defining two alternative matches.
Parameters:
second_rule - The right operand of the +-operator which follows this object in grammar terms.
           (type=Rule @return An OrRule-object connecting these two rule appropriately.)

callAction(self, param)

Call the action attached to this rule. The given parameter is passed to the action.
Parameters:
param - The parameter (token list) to pass to the action.
           (type=list)

hide(self)

Tell this rule to not produce any token output. The rule matches its token as normal but does not return any of them

@return self

match(input_reader)

Match the given rule in the string from the given position on.
Parameters:
input_reader - The InputReader to read the input from.
           (type=InputReader)
Returns:
a list of token the rule matched.

returnToken(self, token)

Helper function encapsulating the hide()-functionality. This method returns the token if self.hide is False and None otherwise.
Parameters:
token - The toden to return
Returns:
token if self.hide==False, None otherwise

setAction(self, action)

Set the action to execute on a rule match. Action may be any callable that takes a one parameter. The parameter is a list of token the rule matched. The action may manipulate the token returned by returning a different token list.
Parameters:
action - The callable to execute if the rule matched.
           (type=Callable)
Returns:
a reference to the rule itself

Class Variable Details

action

Type:
NoneType
Value:
None                                                                  

hide_token

Type:
bool
Value:
False                                                                  

Generated by Epydoc 2.1 on Sat Feb 10 16:11:43 2007 http://epydoc.sf.net