mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-10-31 20:09:53 +00:00
first commit
This commit is contained in:
commit
e9709abf39
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -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
|
35
README.md
Normal file
35
README.md
Normal file
@ -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.
|
3
doc/intro.md
Normal file
3
doc/intro.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Introduction to hs-robotwar
|
||||
|
||||
TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
|
7
project.clj
Normal file
7
project.clj
Normal file
@ -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)
|
62
src/hs_robotwar/core.clj
Normal file
62
src/hs_robotwar/core.clj
Normal file
@ -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)))
|
7
test/hs_robotwar/core_test.clj
Normal file
7
test/hs_robotwar/core_test.clj
Normal file
@ -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))))
|
Loading…
Reference in New Issue
Block a user