Exemple #1
0
  def handleEval(self, statement):
    """ Evaluates the statement in the current context.

    Raises MatchFailedException if the expression evaluates to False.
    """
    if not EvaluateLine(statement, self.variables):
      raise MatchFailedException(statement, self.cursor, self.variables)
Exemple #2
0
 def __if(self, statement, variables):
   if not self.__isEmpty() and abs(self.__peek()) in [ IfStack.BranchNotTaken,
                                                       IfStack.BranchNotTakenYet ]:
     self.__push(IfStack.BranchNotTaken)
   elif EvaluateLine(statement, variables):
     self.__push(IfStack.BranchTaken)
   else:
     self.__push(IfStack.BranchNotTakenYet)
Exemple #3
0
 def __elif(self, statement, variables):
   if self.__isEmpty():
     raise BadStructureException("CHECK-ELIF must be after CHECK-IF or CHECK-ELIF",
                                 statement.lineNo)
   if self.__peek() < 0:
     raise BadStructureException("CHECK-ELIF cannot be after CHECK-ELSE", statement.lineNo)
   if self.__peek() == IfStack.BranchTaken:
     self.__setLast(IfStack.BranchNotTaken)
   elif self.__peek() == IfStack.BranchNotTakenYet:
     if EvaluateLine(statement, variables):
       self.__setLast(IfStack.BranchTaken)
     # else, the CHECK-ELIF condition is False, so do nothing: the last element on the stack is
     # already set to BranchNotTakenYet.
   else:
     assert self.__peek() == IfStack.BranchNotTaken
Exemple #4
0
def testEvalGroup(statements, scope, variables):
    for statement in statements:
        if not EvaluateLine(statement, variables):
            raise MatchFailedException(statement, scope.start, variables)
Exemple #5
0
def testEvalGroup(assertions, scope, variables):
    for assertion in assertions:
        if not EvaluateLine(assertion, variables):
            raise MatchFailedException(assertion, scope.start)