From e9709abf3962517cfe9338feb916d26cf1557e9f Mon Sep 17 00:00:00 2001 From: Richard Harrington Date: Wed, 26 Jun 2013 15:59:01 -0400 Subject: [PATCH] first commit --- .gitignore | 12 +++++++ README.md | 35 +++++++++++++++++++ doc/intro.md | 3 ++ project.clj | 7 ++++ src/hs_robotwar/core.clj | 62 ++++++++++++++++++++++++++++++++++ test/hs_robotwar/core_test.clj | 7 ++++ 6 files changed, 126 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 doc/intro.md create mode 100644 project.clj create mode 100644 src/hs_robotwar/core.clj create mode 100644 test/hs_robotwar/core_test.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc2ff39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/target +/lib +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +.lein-deps-sum +.lein-failures +.lein-plugins +.lein-repl-history diff --git a/README.md b/README.md new file mode 100644 index 0000000..b90077c --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# hs-robotwar + +FIXME: description + +## Installation + +Download from http://example.com/FIXME. + +## Usage + +FIXME: explanation + + $ java -jar hs-robotwar-0.1.0-standalone.jar [args] + +## Options + +FIXME: listing of options this app accepts. + +## Examples + +... + +### Bugs + +... + +### Any Other Sections +### That You Think +### Might be Useful + +## License + +Copyright © 2013 FIXME + +Distributed under the Eclipse Public License, the same as Clojure. diff --git a/doc/intro.md b/doc/intro.md new file mode 100644 index 0000000..373c5d3 --- /dev/null +++ b/doc/intro.md @@ -0,0 +1,3 @@ +# Introduction to hs-robotwar + +TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/) diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..019ef1e --- /dev/null +++ b/project.clj @@ -0,0 +1,7 @@ +(defproject hs-robotwar "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.5.1"]] + :main hs-robotwar.core) diff --git a/src/hs_robotwar/core.clj b/src/hs_robotwar/core.clj new file mode 100644 index 0000000..e3e101c --- /dev/null +++ b/src/hs_robotwar/core.clj @@ -0,0 +1,62 @@ +(ns hs-robotwar.core + (:gen-class)) + +(defn -main + [] + ;; work around dangerous default behaviour in Clojure + (alter-var-root #'*read-eval* (constantly false))) + +(def error-type-map + {:parse-error "Parse Error" + :end-of-line-error "End of Line Error"}) + +(defn error + [error-type error-string] + (str (error-type-map error-type) ": " error-string)) + +(defn valid-number-string + [n] + (re-find #"^-?\d+\.?\d*$" n)) + +(defn number-or-string + [x] + (if (valid-number-string x) + (Float/parseFloat x) + x)) + +(defn parse + "parses a line, by returning a map with the expression, and meta- + information. Right now the value is just a number if it's supposed + to be a number, otherwise the original string." + [line] + (reduce (fn [ast ])) + (map (fn [word] + {:column-number } + (number-or-string word)) + (re-seq #"\S+" line))) + +(defn validate-expr + "right now just checks to see whether it's a number. + will do a lot more things in the future." + [expr] + (if (number? expr) + [expr nil] + [expr (error :parse-error "Not a number")])) + + +(defn evaluate + "evaluates an ast (right now just prints it). + Checks to see if it's a string because that's + the way errors are passed. We'll change that." + [ast] + (if (string? ast) + ast + (apply str (interpose " " ast)))) + + +(defn repl + "make it so" + [] + (loop [] + (println (evaluate (parse (lex (read-line))))) + (recur))) diff --git a/test/hs_robotwar/core_test.clj b/test/hs_robotwar/core_test.clj new file mode 100644 index 0000000..32f604e --- /dev/null +++ b/test/hs_robotwar/core_test.clj @@ -0,0 +1,7 @@ +(ns hs-robotwar.core-test + (:require [clojure.test :refer :all] + [hs-robotwar.core :refer :all])) + +(deftest a-test + (testing "FIXME, I fail." + (is (= 0 1))))