Exemplo n.º 1
0
 def from_string(cls, string, logic):
     try:
         tokens = tokenizer.tokenize(logic, string)
         return Ast(tokens)
     except errors.TokenizeError:
         raise
     except errors.ParserError:
         raise
 def test_tokenize_M(self):
     expression = 'M_1 p'
     for logic in self.logics:
         computed = tokenize(logic, expression)
         expected = [
             tokens.AgentOperator('1', operators.Agent.possible),
             tokens.Proposition('p'),
         ]
         self.assertEqual(computed, expected)
 def test_tokenize_I(self):
     expression = 'I p'
     for logic in self.logics:
         computed = tokenize(logic, expression)
         expected = [
             tokens.UnaryOperator(operators.Unary.implicit),
             tokens.Proposition('p'),
         ]
         self.assertEqual(computed, expected)
 def test_tokenize_biimplication(self):
     expression = 'p <-> q'
     for logic in self.logics:
         computed = tokenize(logic, expression)
         expected = [
             tokens.Proposition('p'),
             tokens.BinaryOperator(operators.Binary.biimplication),
             tokens.Proposition('q')
         ]
         self.assertEqual(computed, expected)
 def test_tokenize_brackets(self):
     expression = '(p & q)'
     for logic in self.logics:
         computed = tokenize(logic, expression)
         expected = [
             tokens.BracketOpen(),
             tokens.Proposition('p'),
             tokens.BinaryOperator(operators.Binary.conjunction),
             tokens.Proposition('q'),
             tokens.BracketClose()
         ]
         self.assertEqual(computed, expected)
 def test_tokenize_proposition(self):
     expression = 'p'
     for logic in self.logics:
         computed = tokenize(logic, expression)
         expected = [tokens.Proposition('p')]
         self.assertItemsEqual(computed, expected)