Skip to content

Commit

Permalink
Try a port to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
olafleur committed May 15, 2014
1 parent 7d2b95e commit bfc12ff
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions diylisp/asserts.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from types import LispError
from parser import unparse
from .types import LispError
from .parser import unparse


def assert_exp_length(ast, length):
Expand Down
2 changes: 1 addition & 1 deletion diylisp/ast.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from types import Closure
from .types import Closure

"""
This module contains a few simple helper functions for
Expand Down
8 changes: 4 additions & 4 deletions diylisp/evaluator.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from types import Environment, LispError, Closure
from ast import is_boolean, is_atom, is_symbol, is_list, is_closure, is_integer
from asserts import assert_exp_length, assert_valid_definition, assert_boolean
from parser import unparse
from .types import Environment, LispError, Closure
from .ast import is_boolean, is_atom, is_symbol, is_list, is_closure, is_integer
from .asserts import assert_exp_length, assert_valid_definition, assert_boolean
from .parser import unparse

"""
This is the Evaluator module. The `evaluate` function below is the heart
Expand Down
6 changes: 3 additions & 3 deletions diylisp/interpreter.py
Expand Up @@ -2,9 +2,9 @@

from os.path import dirname, join

from evaluator import evaluate
from parser import parse, unparse, parse_multiple
from types import Environment
from .evaluator import evaluate
from .parser import parse, unparse, parse_multiple
from .types import Environment


def interpret(source, env=None):
Expand Down
4 changes: 2 additions & 2 deletions diylisp/parser.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

import re
from ast import is_boolean, is_list
from types import LispError
from .ast import is_boolean, is_list
from .types import LispError

"""
This is the parser module, with the `parse` function which you'll implement as part 1 of
Expand Down
46 changes: 23 additions & 23 deletions diylisp/repl.py
Expand Up @@ -4,9 +4,9 @@
import sys
from os.path import dirname, relpath, join

from types import LispError, Environment
from parser import remove_comments
from interpreter import interpret, interpret_file
from .types import LispError, Environment
from .parser import remove_comments
from .interpreter import interpret, interpret_file

# importing this gives readline goodness when running on systems
# where it is supported (i.e. UNIX-y systems)
Expand All @@ -15,35 +15,35 @@

def repl():
"""Start the interactive Read-Eval-Print-Loop"""
print
print " " + faded(" \`. T ")
print " Welcome to " + faded(" .--------------.___________) \ | T ")
print " the DIY-lisp " + faded(" |//////////////|___________[ ] ! T | ")
print " REPL " + faded(" `--------------' ) ( | ! ")
print " " + faded(" '-' ! ")
print faded(" use ^D to exit")
print
print()
print(" " + faded(" \`. T "))
print(" Welcome to " + faded(" .--------------.___________) \ | T "))
print(" the DIY-lisp " + faded(" |//////////////|___________[ ] ! T | "))
print(" REPL " + faded(" `--------------' ) ( | ! "))
print(" " + faded(" '-' ! "))
print(faded(" use ^D to exit"))
print()

env = Environment()
interpret_file(join(dirname(relpath(__file__)), '..', 'stdlib.diy'), env)
while True:
try:
source = read_expression()
print interpret(source, env)
except LispError, e:
print colored("!", "red"),
print faded(str(e.__class__.__name__) + ":"),
print str(e)
print(interpret(source, env))
except LispError as e:
print(colored("!", "red"))
print(faded(str(e.__class__.__name__) + ":"))
print(str(e))
except KeyboardInterrupt:
msg = "Interupted. " + faded("(Use ^D to exit)")
print "\n" + colored("! ", "red") + msg
print("\n" + colored("! ", "red") + msg)
except EOFError:
print faded("\nBye! o/")
print(faded("\nBye! o/"))
sys.exit(0)
except Exception, e:
print colored("! ", "red") + faded("The Python is showing through…")
print faded(" " + str(e.__class__.__name__) + ":"),
print str(e)
except Exception as e:
print(colored("! ", "red") + faded("The Python is showing through…"))
print(faded(" " + str(e.__class__.__name__) + ":"))
print(str(e))


def read_expression():
Expand All @@ -64,7 +64,7 @@ def read_expression():
def read_line(prompt):
"""Return touple of user input line and number of unclosed parens"""

line = raw_input(colored(prompt, "grey", "bold"))
line = input(colored(prompt, "grey", "bold"))
line = remove_comments(line + "\n")
return line, line.count("(") - line.count(")")

Expand Down
2 changes: 1 addition & 1 deletion repl
Expand Up @@ -7,6 +7,6 @@ from diylisp.interpreter import interpret_file
from diylisp.repl import repl

if len(sys.argv) > 1:
print interpret_file(sys.argv[1])
print(interpret_file(sys.argv[1]))
else:
repl()

0 comments on commit bfc12ff

Please sign in to comment.