# Path: mom/Policy/Parser.py
# class Parser(GenericParser):
#     def __init__(self, start='value'):
#         GenericParser.__init__(self, start)
# 
#     def mklist(self, args):
#         if len(args) == 2:
#             return []
#         return args[1]
# 
#     def p_value_list(self, args):
#         '''
#           value_list ::= value
#           value_list ::= value_list value
#         '''
#         if len(args) == 1:
#             return [args[0]]
#         return args[0] + [args[1]]
# 
#     def p_list(self, args):
#         '''
#           list ::= ( )
#           list ::= ( value_list )
#         '''
#         return self.mklist(args)
# 
#     def p_bracket_list(self, args):
#         '''
#           bracket_list ::= [ ]
#           bracket_list ::= [ value_list ]
#         '''
#         return self.mklist(args)
# 
#     def p_curly_list(self, args):
#         '''
#           curly_list ::= { }
#           curly_list ::= { value_list }
#         '''
#         return [Token('symbol', 'eval')] + self.mklist(args)
# 
#     def p_value(self, args):
#         '''
#           value ::= operator
#           value ::= number
#           value ::= operator
#           value ::= symbol
#           value ::= string
#           value ::= single_quote_string
#           value ::= list
#           value ::= curly_list
#           value ::= bracket_list
#          '''
#         return args[0]


import unittest
from mom.Policy import Parser
        pol = """           # Again, these bahave according to Python rules
        (and 1 1 "")          # "" evaluates to false
        (and 0 0 1)           #   as does 0 -- the first false value is returned
        (and 1 1 2)           # If all values are true, the last value is returned
        (or "" "" 17)          # or returns the first true value encountered
        (or "" "" "")          # if all values are false, or returns the last one
        (and 1 2 3 4 5 6 7 8 9 0)
        (or 0)
        """
        self.verify(pol, [ "", 0, 2, 17, "", 0, 0 ])

    def test_vars(self):
        pol = """
        (defvar foo "bar")
        (defvar a 5)
        (defvar b 6)
        (+ a b)
        (set a 8)
        (+ a b)
        (* foo 2)
        (defvar e3 7)
        (+ 1 e3)        # Make sure e3 is not mistaken for scientific notation
        """
        self.verify(pol, [ 'bar', 5, 6, 11, 8, 14, "barbar", 7, 8 ])

    def test_funcs(self):
        pol = """
        (def foo () 10)
        (def bar (a)
            (* 2 a))

# Path: mom/Policy/Parser.py
# class Parser(GenericParser):
#     def __init__(self, start='value'):
#         GenericParser.__init__(self, start)
# 
#     def mklist(self, args):
#         if len(args) == 2:
#             return []
#         return args[1]
# 
#     def p_value_list(self, args):
#         '''
#           value_list ::= value
#           value_list ::= value_list value
#         '''
#         if len(args) == 1:
#             return [args[0]]
#         return args[0] + [args[1]]
# 
#     def p_list(self, args):
#         '''
#           list ::= ( )
#           list ::= ( value_list )
#         '''
#         return self.mklist(args)
# 
#     def p_bracket_list(self, args):
#         '''
#           bracket_list ::= [ ]
#           bracket_list ::= [ value_list ]
#         '''
#         return self.mklist(args)
# 
#     def p_curly_list(self, args):
#         '''
#           curly_list ::= { }
#           curly_list ::= { value_list }
#         '''
#         return [Token('symbol', 'eval')] + self.mklist(args)
# 
#     def p_value(self, args):
#         '''
#           value ::= operator
#           value ::= number
#           value ::= operator
#           value ::= symbol
#           value ::= string
#           value ::= single_quote_string
#           value ::= list
#           value ::= curly_list
#           value ::= bracket_list
#          '''
#         return args[0]


# Path: tests/ParserTests.py
import unittest
from mom.Policy import Parser

        pol = """           # Again, these bahave according to Python rules
        (and 1 1 "")          # "" evaluates to false
        (and 0 0 1)           #   as does 0 -- the first false value is returned
        (and 1 1 2)           # If all values are true, the last value is returned
        (or "" "" 17)          # or returns the first true value encountered
        (or "" "" "")          # if all values are false, or returns the last one
        (and 1 2 3 4 5 6 7 8 9 0)
        (or 0)
        """
        self.verify(pol, [ "", 0, 2, 17, "", 0, 0 ])

    def test_vars(self):
        pol = """
        (defvar foo "bar")
        (defvar a 5)
        (defvar b 6)
        (+ a b)
        (set a 8)
        (+ a b)
        (* foo 2)
        (defvar e3 7)
        (+ 1 e3)        # Make sure e3 is not mistaken for scientific notation
        """
        self.verify(pol, [ 'bar', 5, 6, 11, 8, 14, "barbar", 7, 8 ])

    def test_funcs(self):
        pol = """
        (def foo () 10)
        (def bar (a)
            (* 2 a))

        (/ (foo) (bar 5))