def test_misplaced_inner_parenthesis(self):
        with self.assertRaises(readerEx.MalformedListException) as cm:
            self.stream.set_stream('(()))')
            reader.read_from_stream(self.stream)

        desired_exception = cm.exception
        self.assertTrue(isinstance(desired_exception, readerEx.MalformedListException))
コード例 #2
0
 def test_symbol_in_cons(self):
     self.stream.set_stream("(define-dat-s***e 15.12345)")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeCons))
     self.assertTrue(isinstance(result.car, SchemeSymbol))
     self.assertTrue(isinstance(result.cdr.car, SchemeFloat))
     self.assertEqual(result.car.name, "define-dat-s***e")
    def test_two_consecutive_malformed_lists(self):
        with self.assertRaises(readerEx.MalformedListException) as cm:
            self.stream.set_stream('10   123)')
            result = reader.read_from_stream(self.stream)
            printer.print_scheme_object(result, self.output_stream)

        desired_exception = cm.exception
        self.assertTrue(isinstance(desired_exception, readerEx.MalformedListException))

        with self.assertRaises(readerEx.MalformedListException) as cm2:
            self.stream.set_stream('asd   1234)')
            result = reader.read_from_stream(self.stream)
            printer.print_scheme_object(result, self.output_stream)

        desired_exception = cm2.exception
        self.assertTrue(isinstance(desired_exception, readerEx.MalformedListException))
コード例 #4
0
 def test_floaty_symbol_in_nested_list(self):
     self.stream.set_stream('(123.123.123("a" test-test))')
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result.car, SchemeSymbol))
     self.assertTrue(isinstance(result.cdr.car.car, SchemeString))
     self.assertTrue(isinstance(result.cdr.car.cdr.car, SchemeSymbol))
     self.assertEqual(result.car.name, "123.123.123")
     self.assertEqual(result.cdr.car.car.content, "a")
    def test_list_with_two_items_without_opening_bracket(self):
        with self.assertRaises(readerEx.MalformedListException) as cm:
            self.stream.set_stream('10   123)')
            result = reader.read_from_stream(self.stream)
            printer.print_scheme_object(result, self.output_stream)

        desired_exception = cm.exception
        self.assertTrue(isinstance(desired_exception, readerEx.MalformedListException))
コード例 #6
0
 def test_string_in_cons(self):
     self.stream.set_stream(' ( "mic check one two one two!" 123.45)')
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeCons))
     self.assertEqual(result.car.content, "mic check one two one two!")
     self.assertTrue(isinstance(result.car, SchemeString))
     self.assertTrue(isinstance(result.cdr.car, SchemeFloat))
     self.assertEqual(result.cdr.car.value, 123.45)
コード例 #7
0
 def test_list_with_two_items(self):
     self.stream.set_stream('(     10   123.4   )')
     result = reader.read_from_stream(self.stream)
     self.assertFalse(isinstance(result, SchemeNil))
     self.assertTrue(isinstance(result, SchemeCons))
     self.assertTrue(isinstance(result.cdr, SchemeCons))
     self.assertTrue(isinstance(result.car, SchemeInteger))
     self.assertTrue(isinstance(result.cdr.car, SchemeFloat))
     self.assertTrue(isinstance(result.cdr.cdr, SchemeNil))
コード例 #8
0
def start():
    """ setting up the repl loop """
    # load std lib
    init()

    while True:

        input_string = raw_input('<scheme>: ')

        # create a stream object from string
        read_stream = utilities.StringStream(input_string)
        write_stream = utilities.StringStream()

        # retrieve parsed string as list from reader
        parsed_scheme = reader.read_from_stream(read_stream)

        # hand list over to eval
        evaluator.evaluate(parsed_scheme, write_stream)

        print write_stream.get_stream()
コード例 #9
0
 def test_list_with_symbol_and_integer(self):
     self.read_stream.set_stream("(some-variable 12345)")
     result = reader.read_from_stream(self.read_stream)
     printer.print_scheme_object(result, self.write_stream)
     self.assertEqual(self.write_stream.get_stream(), "(some-variable 12345)", "instead: " + self.write_stream.get_stream())
コード例 #10
0
 def test_float(self):
     self.read_stream.set_stream("0.34")
     result = reader.read_from_stream(self.read_stream)
     printer.print_scheme_object(result, self.write_stream)
     self.assertEqual(self.write_stream.get_stream(), "0.34", "instead: " + self.write_stream.get_stream())
コード例 #11
0
 def test_symbol_with_leading_digits(self):
     self.stream.set_stream("123asdfg")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeSymbol))
     self.assertEqual(result.name, "123asdfg")
コード例 #12
0
 def test_unevaled_nested_list_quote(self):
     self.input_stream.set_stream("'(a b (898 123.67 \"abcde\") c d e)")
     parsed = reader.read_from_stream(self.input_stream)
     printer.print_scheme_object(parsed, self.output_stream)
     self.assertEqual(self.output_stream.get_stream(), "(quote (a b (898 123.67 \"abcde\") c d e))")
コード例 #13
0
 def test_list_with_single_item(self):
     self.stream.set_stream('(     10   )')
     result = reader.read_from_stream(self.stream)
     self.assertFalse(isinstance(result, SchemeNil))
     self.assertTrue(isinstance(result, SchemeCons))
     self.assertTrue(isinstance(result.car, SchemeInteger))
コード例 #14
0
 def test_float_parsing_2(self):
     self.stream.set_stream("1234.")
     self.obj = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(self.obj, SchemeFloat))
コード例 #15
0
 def test_nested_quote(self):
     self.stream.set_stream("(x (a '(a b c d e f g)))")
     result = reader.read_from_stream(self.stream)
     printer.print_scheme_object(result, self.output_stream)
     self.assertEqual(self.output_stream.get_stream(), "(x (a (quote (a b c d e f g))))")
コード例 #16
0
 def test_float_value_double_point_error(self):
     self.stream.set_stream("123.123.123")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeSymbol))
     self.assertEqual(result.name, "123.123.123")
 def test_list_with_two_items_without_closing_bracket(self):
     with self.assertRaises(readerEx.MalformedListException) as cm:
         self.stream.set_stream('(     10   123')
         result = reader.read_from_stream(self.stream)
     desired_exception = cm.exception
     self.assertTrue(isinstance(desired_exception, readerEx.MalformedListException))
コード例 #18
0
 def test_negative_float_number(self):
     self.stream.set_stream("-1.0")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeFloat))
     self.assertEqual(result.value, -1.0)
コード例 #19
0
 def test_string_with_spaces(self):
     self.stream.set_stream('    "mic check one two one two!"')
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeString))
     self.assertEqual(result.content, "mic check one two one two!")
コード例 #20
0
 def test_single_string(self):
     self.stream.set_stream('"ouuuladidadida"')
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeString))
     self.assertEqual(result.content, "ouuuladidadida")
 def test_addition_with_naturals(self):
     self.input_stream.set_stream("(+ 2 3)")
     parsed = reader.read_from_stream(self.input_stream)
     evaluator.evaluate(parsed, self.output_stream)
     self.assertEqual(self.output_stream.get_stream(), "5")
コード例 #22
0
 def test_integer_leading_zeros(self):
     self.stream.set_stream("0000000132")
     self.obj = reader.read_from_stream(self.stream)
     self.assertEqual(self.obj.value, 132)
 def test_nested_list_plus_trailing(self):
     self.read_stream.set_stream("(a b c d (some-variable 12345) 10 15)")
     result = reader.read_from_stream(self.read_stream)
     printer.print_scheme_object(result, self.write_stream)
     self.assertEqual(self.write_stream.get_stream(), "(a b c d (some-variable 12345) 10 15)", "instead: " + self.write_stream.get_stream())
コード例 #24
0
 def test_single_symbol_plus(self):
     self.stream.set_stream("+")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeSymbol))
コード例 #25
0
 def test_malformed_quoted_list(self):
     with self.assertRaises(readerEx.MalformedListException) as cm:
         self.stream.set_stream('10   123)')
         reader.read_from_stream(self.stream)
コード例 #26
0
 def test_single_symbol_with_spaces(self):
     self.stream.set_stream("      my_function+### ")
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeSymbol))
     self.assertEqual(result.name, "my_function+###")
コード例 #27
0
 def test_empty_list_with_spaces(self):
     self.stream.set_stream('(         )')
     result = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(result, SchemeNil))
コード例 #28
0
 def test_float_value(self):
     self.stream.set_stream("1234.567")
     self.obj = reader.read_from_stream(self.stream)
     self.assertEqual(self.obj.value, 1234.567)
コード例 #29
0
 def test_integer_symbol_separation(self):
     self.stream.set_stream("123abcde")
     self.obj = reader.read_from_stream(self.stream)
     self.assertTrue(isinstance(self.obj, SchemeSymbol))
     self.assertEqual(self.obj.name, "123abcde")
コード例 #30
0
 def test_unevaled_integer_quote(self):
     self.input_stream.set_stream("'10")
     parsed = reader.read_from_stream(self.input_stream)
     printer.print_scheme_object(parsed, self.output_stream)
     self.assertEqual(self.output_stream.get_stream(), "(quote 10)")