From 7741b2e1dd76140d6c7571ed1402f89651ef04a0 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Thu, 14 Mar 2013 21:03:33 -0400 Subject: [PATCH] Adding in #! as a comment --- TODO | 5 ----- bin/hy | 9 ++++++++- eg/nonfree/halting-problem/halting.hy | 5 ++++- hy/lex/states.py | 21 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) mode change 100644 => 100755 eg/nonfree/halting-problem/halting.hy diff --git a/TODO b/TODO index 0914a33..faee659 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,6 @@ - New Builtins: + While - + Pass - - New macros: + loop @@ -26,7 +24,6 @@ - Better Exception handling + linenos in the dump - + except IOError as E: # <-- implement - Tuples @@ -36,8 +33,6 @@ - car / cdr / first / rest - - hyrepl - - pyc compiler - core tests (odd? even? true? false?) which diff --git a/bin/hy b/bin/hy index 08edab5..bb8226e 100755 --- a/bin/hy +++ b/bin/hy @@ -1,11 +1,18 @@ #!/usr/bin/env python +import hy import sys + +if len(sys.argv) > 1: + from hy.importer import import_file_to_module + import_file_to_module("__main__", sys.argv[1]) + sys.exit(0) # right? + + import ast import code import readline -import hy from hy.lex.states import Idle, LexException from hy.lex.machine import Machine from hy.compiler import hy_compile diff --git a/eg/nonfree/halting-problem/halting.hy b/eg/nonfree/halting-problem/halting.hy old mode 100644 new mode 100755 index b8060f0..450669f --- a/eg/nonfree/halting-problem/halting.hy +++ b/eg/nonfree/halting-problem/halting.hy @@ -1,5 +1,8 @@ +#!/usr/bin/env hy + ; Very much a knockoff (straight port) of Dan Gulotta's 2013 MIT Mystery Hunt -; puzzle "The Halting Problem". +; puzzle "The Halting Problem". His Copyright terms are unclear, so presume +; that this is distributable, but not free. (defn evaluate [f] ((f (lambda [x] (+ x 1))) 0)) diff --git a/hy/lex/states.py b/hy/lex/states.py index 190deaa..98b9bda 100644 --- a/hy/lex/states.py +++ b/hy/lex/states.py @@ -271,6 +271,9 @@ class Idle(State): if char == ";": return Comment + if char == "#": + return Hash + if char in WHITESPACE: return @@ -292,3 +295,21 @@ class Comment(State): if char == "\n": return Idle + + +class Hash(State): + """ + Hash state + """ + + def process(self, char): + """ + State transitions: + + - ! - Comment + """ + + if char == "!": + return Comment + + raise LexException("Unknown char (Hash state): `%s`" % (char))