Skip to content

Commit

Permalink
Merge pull request #1 from nyampass/feature/turn
Browse files Browse the repository at this point in the history
add turn
  • Loading branch information
tnoborio authored Feb 22, 2024
2 parents 01bd9c5 + 33f7cb0 commit 988587a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions resources/move2.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
move "right"
move "test"
move "left"
move "up"
move "down"
move "back"
6 changes: 6 additions & 0 deletions resources/turn.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
turn "left"
turn "right"
turn "forward"
turn "left"
turn "left"
turn "right"
5 changes: 3 additions & 2 deletions src/keystone/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
block ::= {stat}
<stat> ::= <space> ( define | op | loop | functioncall | label | if | for name '=' exp ',' exp [',' exp] do block end | for namelist in explist do block end | function funcname funcbody | local function name funcbody | local namelist ['=' explist] ) <'\n'*>
<space> ::= #\"\\s*\"
op ::= ( print | move ) <space> exp <space>
op ::= ( print | move | turn ) <space> exp <space>
print ::= 'print'
move ::= 'move'
turn ::= 'turn'
define ::= name <space> '=' <space> exp
loop ::= 'loop' <space> exp <space> <'\n'*> block <'\n'*> <end>
if ::= 'if' <space> exp <space> <'\n'*> block <'\n'*> <end>
Expand Down Expand Up @@ -169,7 +170,7 @@
(for [_ (range condition)]
(-eval args env))
(-eval rest env))
(if (contains? #{:print :move} op)
(if (contains? #{:print :move :turn} op)
(concat [{:op op :args (-eval-exps args @env)}] (-eval rest env))
(concat [code] (-eval rest env)))))))

Expand Down
10 changes: 9 additions & 1 deletion test/keystone/eval_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
(testing "hello"
(is (= (run (slurp "./resources/hello.ks")) [{:op :print :args '("hello")}])))

(testing "move2"
(is (= (run (slurp "./resources/move2.ks"))
[{:op :move :args '("right")} {:op :move :args '("test")} {:op :move :args '("left")} {:op :move :args '("up")} {:op :move :args '("down")} {:op :move :args '("back")}])))

(testing "move"
(is (= (run (slurp "./resources/move.ks"))
[{:op :move :args '("right")} {:op :move :args '("right")} {:op :move :args '("left")} {:op :move :args '("up")} {:op :move :args '("down")}])))
[{:op :move :args '("right")} {:op :move :args '("right")} {:op :move :args '("left")} {:op :move :args '("up")} {:op :move :args '("down")}])))

(testing "turn"
(is (= (run (slurp "./resources/turn.ks"))
[{:op :turn :args '("left")} {:op :turn :args '("right")} {:op :turn :args '("forward")} {:op :turn :args '("left")} {:op :turn :args '("left")} {:op :turn :args '("right")}])))

(testing "variable"
(is (= (run (slurp "./resources/variable.ks"))
Expand Down

0 comments on commit 988587a

Please sign in to comment.