Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
build.manifestparser.ExpressionParser Class Reference

List of all members.

Public Member Functions

def __init__
def value
def advance
def expression
def parse

Public Attributes

 text
 valuemapping
 strict
 token
 iter

Private Member Functions

def _tokenize

Static Private Attributes

 __call__ = parse

Detailed Description

Definition at line 204 of file manifestparser.py.


Constructor & Destructor Documentation

def build.manifestparser.ExpressionParser.__init__ (   self,
  text,
  valuemapping,
  strict = False 
)
Initialize the parser with input |text|, and |valuemapping| as
a dict mapping identifier names to values.

Definition at line 205 of file manifestparser.py.

00205 
00206     def __init__(self, text, valuemapping, strict=False):
00207         """
00208         Initialize the parser with input |text|, and |valuemapping| as
00209         a dict mapping identifier names to values.
00210         """
00211         self.text = text
00212         self.valuemapping = valuemapping
00213         self.strict = strict


Member Function Documentation

Lex the input text into tokens and yield them in sequence.

Definition at line 214 of file manifestparser.py.

00214 
00215     def _tokenize(self):
00216         """
00217         Lex the input text into tokens and yield them in sequence.
00218         """
00219         # scanner callbacks
00220         def bool_(scanner, t): return bool_token(t)
00221         def identifier(scanner, t): return ident_token(t)
00222         def integer(scanner, t): return int_token(t)
00223         def eq(scanner, t): return eq_op_token()
00224         def neq(scanner, t): return neq_op_token()
00225         def or_(scanner, t): return or_op_token()
00226         def and_(scanner, t): return and_op_token()
00227         def lparen(scanner, t): return lparen_token()
00228         def rparen(scanner, t): return rparen_token()
00229         def string_(scanner, t): return string_token(t)
00230         def not_(scanner, t): return not_op_token()
00231 
00232         scanner = re.Scanner([
00233             (r"true|false", bool_),
00234             (r"[a-zA-Z_]\w*", identifier),
00235             (r"[0-9]+", integer),
00236             (r'("[^"]*")|(\'[^\']*\')', string_),
00237             (r"==", eq),
00238             (r"!=", neq),
00239             (r"\|\|", or_),
00240             (r"!", not_),
00241             (r"&&", and_),
00242             (r"\(", lparen),
00243             (r"\)", rparen),
00244             (r"\s+", None), # skip whitespace
00245             ])
00246         tokens, remainder = scanner.scan(self.text)
00247         for t in tokens:
00248             yield t
00249         yield end_token()

def build.manifestparser.ExpressionParser.advance (   self,
  expected 
)
Assert that the next token is an instance of |expected|, and advance
to the next token.

Definition at line 260 of file manifestparser.py.

00260 
00261     def advance(self, expected):
00262         """
00263         Assert that the next token is an instance of |expected|, and advance
00264         to the next token.
00265         """
00266         if not isinstance(self.token, expected):
00267             raise Exception, "Unexpected token!"
00268         self.token = self.iter.next()
        
def build.manifestparser.ExpressionParser.expression (   self,
  rbp = 0 
)
Parse and return the value of an expression until a token with
right binding power greater than rbp is encountered.

Definition at line 269 of file manifestparser.py.

00269 
00270     def expression(self, rbp=0):
00271         """
00272         Parse and return the value of an expression until a token with
00273         right binding power greater than rbp is encountered.
00274         """
00275         t = self.token
00276         self.token = self.iter.next()
00277         left = t.nud(self)
00278         while rbp < self.token.lbp:
00279             t = self.token
00280             self.token = self.iter.next()
00281             left = t.led(self, left)
00282         return left

Parse and return the value of the expression in the text
passed to the constructor. Raises a ParseError if the expression
could not be parsed.

Definition at line 283 of file manifestparser.py.

00283 
00284     def parse(self):
00285         """
00286         Parse and return the value of the expression in the text
00287         passed to the constructor. Raises a ParseError if the expression
00288         could not be parsed.
00289         """
00290         try:
00291             self.iter = self._tokenize()
00292             self.token = self.iter.next()
00293             return self.expression()
00294         except:
00295             raise ParseError("could not parse: %s; variables: %s" % (self.text, self.valuemapping))

def build.manifestparser.ExpressionParser.value (   self,
  ident 
)
Look up the value of |ident| in the value mapping passed in the
constructor.

Definition at line 250 of file manifestparser.py.

00250 
00251     def value(self, ident):
00252         """
00253         Look up the value of |ident| in the value mapping passed in the
00254         constructor.
00255         """
00256         if self.strict:
00257             return self.valuemapping[ident]
00258         else:
00259             return self.valuemapping.get(ident, None)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 296 of file manifestparser.py.

Definition at line 290 of file manifestparser.py.

Definition at line 212 of file manifestparser.py.

Definition at line 210 of file manifestparser.py.

Definition at line 267 of file manifestparser.py.

Definition at line 211 of file manifestparser.py.


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