diff --git a/project.clj b/project.clj index d48db45..9463073 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject mw-parser "0.1.5-SNAPSHOT" +(defproject mw-parser "3.0.0-SNAPSHOT" :description "Parser for production rules for MicroWorld engine" :url "http://www.journeyman.cc/microworld" :manifest { @@ -8,11 +8,12 @@ "build-signature-timestamp" "unset" "Implementation-Version" "unset" } + :source-paths ["src/clj" "src/cljc"] :license {:name "GNU General Public License v2" :url "http://www.gnu.org/licenses/gpl-2.0.html"} :plugins [[lein-marginalia "0.7.1"]] - :dependencies [[org.clojure/clojure "1.6.0"] + :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/tools.trace "0.7.9"] - [instaparse "1.4.1"] - [mw-engine "0.1.5-SNAPSHOT"] + [com.lucasbradstreet/instaparse-cljs "1.4.1.2"] + [mw-engine "3.0.0-SNAPSHOT"] ]) diff --git a/src/mw_parser/bulk.clj b/src/cljc/microworld/parser/bulk.cljc similarity index 93% rename from src/mw_parser/bulk.clj rename to src/cljc/microworld/parser/bulk.cljc index 45540e8..e9efd2e 100644 --- a/src/mw_parser/bulk.clj +++ b/src/cljc/microworld/parser/bulk.cljc @@ -1,15 +1,15 @@ (ns ^{:doc "parse multiple rules from a stream, possibly a file." :author "Simon Brooke"} - mw-parser.bulk - (:use mw-parser.declarative - mw-engine.utils + microworld.parser.bulk + (:use microworld.parser.declarative + microworld.engine.utils clojure.java.io [clojure.string :only [split trim]]) (:import (java.io BufferedReader StringReader))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; -;;;; mw-parser: a rule parser for MicroWorld. +;;;; microworld.parser: a rule parser for MicroWorld. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License diff --git a/src/mw_parser/core.clj b/src/cljc/microworld/parser/core.cljc similarity index 98% rename from src/mw_parser/core.clj rename to src/cljc/microworld/parser/core.cljc index 820f353..746a4f1 100644 --- a/src/mw_parser/core.clj +++ b/src/cljc/microworld/parser/core.cljc @@ -1,14 +1,14 @@ (ns ^{:doc "A very simple parser which parses production rules." :author "Simon Brooke"} - mw-parser.core - (:use mw-engine.utils + microworld.parser.core + (:use microworld.engine.utils [clojure.string :only [split trim triml]]) (:gen-class) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; -;;;; mw-parser: a rule parser for MicroWorld. +;;;; microworld.parser: a rule parser for MicroWorld. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License @@ -44,7 +44,7 @@ ;;;; * "if state is pasture and more than 3 neighbours have state equal to scrub then state should be scrub" ;;;; * ;;;; -;;;; it generates rules in the form expected by `mw-engine.core`, q.v. +;;;; it generates rules in the form expected by `microworld.engine.core`, q.v. ;;;; ;;;; It is, as I say, very simple; it generates a complete rule, or it fails completely, returning nil. ;;;; Very occasionally it generates a wrong rule - one which is not a correct translation of the rule @@ -434,7 +434,7 @@ (defn compile-rule "Parse this `rule-text`, a string conforming to the grammar of MicroWorld rules, into Clojure source, and then compile it into an anonymous - function object, getting round the problem of binding mw-engine.utils in + function object, getting round the problem of binding microworld.engine.utils in the compiling environment. If `return-tuple?` is present and true, return a list comprising the anonymous function compiled, and the function from which it was compiled. @@ -442,7 +442,7 @@ Throws an exception if parsing fails." ([rule-text return-tuple?] (do - (use 'mw-engine.utils) + (use 'microworld.engine.utils) (let [afn (eval (parse-rule rule-text))] (cond (and afn return-tuple?)(list afn (trim rule-text)) diff --git a/src/mw_parser/declarative.clj b/src/cljc/microworld/parser/declarative.cljc similarity index 90% rename from src/mw_parser/declarative.clj rename to src/cljc/microworld/parser/declarative.cljc index 62e1b03..f084716 100644 --- a/src/mw_parser/declarative.clj +++ b/src/cljc/microworld/parser/declarative.cljc @@ -1,16 +1,16 @@ (ns ^{:doc "A very simple parser which parses production rules." :author "Simon Brooke"} - mw-parser.declarative + microworld.parser.declarative (:require [instaparse.core :as insta] [clojure.string :refer [split trim triml]] - [mw-parser.errors :as pe] - [mw-parser.generate :as pg] - [mw-parser.simplify :as ps] - [mw-parser.utils :refer [rule?]])) + [microworld.parser.errors :as pe] + [microworld.parser.generate :as pg] + [microworld.parser.simplify :as ps] + [microworld.parser.utils :refer [rule?]])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; -;;;; mw-parser: a rule parser for MicroWorld. +;;;; microworld.parser: a rule parser for MicroWorld. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License @@ -96,7 +96,7 @@ (defn compile-rule "Parse this `rule-text`, a string conforming to the grammar of MicroWorld rules, into Clojure source, and then compile it into an anonymous - function object, getting round the problem of binding mw-engine.utils in + function object, getting round the problem of binding microworld.engine.utils in the compiling environment. If `return-tuple?` is present and true, return a list comprising the anonymous function compiled, and the function from which it was compiled. @@ -106,11 +106,12 @@ (assert (string? rule-text)) (let [rule (trim rule-text) tree (ps/simplify (parse-rule rule)) - afn (if (rule? tree) (eval (pg/generate tree)) + clj (pg/generate tree) + afn (if (rule? tree) (eval clj) ;; else (pe/throw-parse-exception tree))] (if return-tuple? - (list afn rule) + (list afn {:rule rule :clojure (print-str clj)}) ;; else afn))) ([rule-text] diff --git a/src/mw_parser/errors.clj b/src/cljc/microworld/parser/errors.cljc similarity index 99% rename from src/mw_parser/errors.clj rename to src/cljc/microworld/parser/errors.cljc index 6e5efbe..55bc354 100644 --- a/src/mw_parser/errors.clj +++ b/src/cljc/microworld/parser/errors.cljc @@ -1,7 +1,7 @@ (ns ^{:doc "Display parse errors in a format which makes it easy for the user to see where the error occurred." :author "Simon Brooke"} - mw-parser.errors) + microworld.parser.errors) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; diff --git a/src/mw_parser/generate.clj b/src/cljc/microworld/parser/generate.cljc similarity index 97% rename from src/mw_parser/generate.clj rename to src/cljc/microworld/parser/generate.cljc index 3c86b02..e7a9e5f 100644 --- a/src/mw_parser/generate.clj +++ b/src/cljc/microworld/parser/generate.cljc @@ -1,9 +1,9 @@ (ns ^{:doc "Generate Clojure source from simplified parse trees." :author "Simon Brooke"} - mw-parser.generate - (:require [mw-engine.utils :refer []] - [mw-parser.utils :refer [assert-type TODO]] - [mw-parser.errors :as pe])) + microworld.parser.generate + (:require [microworld.engine.utils :refer []] + [microworld.parser.utils :refer [assert-type TODO]] + [microworld.parser.errors :as pe])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -246,7 +246,7 @@ (list 'count (list 'remove 'false? (list 'map (list 'fn ['cell] property-condition) - (list 'mw-engine.utils/get-neighbours 'world 'cell distance)))) quantity)) + (list 'microworld.engine.utils/get-neighbours 'world 'cell distance)))) quantity)) ([comp1 quantity property-condition] (generate-neighbours-condition comp1 quantity property-condition 1))) diff --git a/src/mw_parser/simplify.clj b/src/cljc/microworld/parser/simplify.cljc similarity index 95% rename from src/mw_parser/simplify.clj rename to src/cljc/microworld/parser/simplify.cljc index 00529a8..1e32c61 100644 --- a/src/mw_parser/simplify.clj +++ b/src/cljc/microworld/parser/simplify.cljc @@ -1,11 +1,11 @@ (ns ^{:doc "Simplify a parse tree." :author "Simon Brooke"} - mw-parser.simplify - (:require [mw-engine.utils :refer [member?]])) + microworld.parser.simplify + (:require [microworld.engine.utils :refer [member?]])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; -;;;; mw-parser: a rule parser for MicroWorld. +;;;; microworld.parser: a rule parser for MicroWorld. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License diff --git a/src/mw_parser/utils.clj b/src/cljc/microworld/parser/utils.cljc similarity index 96% rename from src/mw_parser/utils.clj rename to src/cljc/microworld/parser/utils.cljc index e8bdca8..9390b18 100644 --- a/src/mw_parser/utils.clj +++ b/src/cljc/microworld/parser/utils.cljc @@ -1,10 +1,10 @@ (ns ^{:doc "Utilities used in more than one namespace within the parser." :author "Simon Brooke"} - mw-parser.utils) + microworld.parser.utils) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; -;;;; mw-parser: a rule parser for MicroWorld. +;;;; microworld.parser: a rule parser for MicroWorld. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License diff --git a/test/mw_parser/bulk_test.clj b/test/microworld/parser/bulk_test.clj similarity index 92% rename from test/mw_parser/bulk_test.clj rename to test/microworld/parser/bulk_test.clj index 1155361..6b74a61 100644 --- a/test/mw_parser/bulk_test.clj +++ b/test/microworld/parser/bulk_test.clj @@ -1,7 +1,7 @@ -(ns mw-parser.bulk-test +(ns microworld.parser.bulk-test (:use clojure.java.io) (:require [clojure.test :refer :all] - [mw-parser.bulk :refer :all])) + [microworld.parser.bulk :refer :all])) (deftest bulk-parsing-test (testing "Bulk (file) parsing and compilation" diff --git a/test/mw_parser/core_test.clj b/test/microworld/parser/core_test.clj similarity index 99% rename from test/mw_parser/core_test.clj rename to test/microworld/parser/core_test.clj index f0e152e..bd55717 100644 --- a/test/mw_parser/core_test.clj +++ b/test/microworld/parser/core_test.clj @@ -1,9 +1,9 @@ -(ns mw-parser.core-test +(ns microworld.parser.core-test (:use clojure.pprint - mw-engine.core - mw-engine.world) + microworld.engine.core + microworld.engine.world) (:require [clojure.test :refer :all] - [mw-parser.core :refer :all])) + [microworld.parser.core :refer :all])) (deftest primitives-tests (testing "Simple functions supporting the parser" diff --git a/test/mw_parser/declarative_test.clj b/test/microworld/parser/declarative_test.clj similarity index 98% rename from test/mw_parser/declarative_test.clj rename to test/microworld/parser/declarative_test.clj index bc7485f..953582d 100644 --- a/test/mw_parser/declarative_test.clj +++ b/test/microworld/parser/declarative_test.clj @@ -1,11 +1,11 @@ -(ns mw-parser.declarative-test +(ns microworld.parser.declarative-test (:use clojure.pprint - mw-engine.core - mw-engine.world - mw-engine.utils - mw-parser.utils) + microworld.engine.core + microworld.engine.world + microworld.engine.utils + microworld.parser.utils) (:require [clojure.test :refer :all] - [mw-parser.declarative :refer :all])) + [microworld.parser.declarative :refer :all])) (deftest rules-tests (testing "Rule parser - does not test whether generated functions actually work, just that something is generated!" @@ -485,3 +485,13 @@ (is (= (apply afn (list (get-cell world 2 1) world)) nil) "Middle cell of the strip is not scrub, so rule should not fire.")))) +(deftest regression-2-tests + (testing "Still getting fails althought tests for these fails fail." + (is + (= + (:state + (apply + (compile-rule "if state is scrub then 1 chance in 1 state should be forest") + (list {:state :scrub} {}))) + :forest)))) + diff --git a/test/mw_parser/generate_test.clj b/test/microworld/parser/generate_test.clj similarity index 93% rename from test/mw_parser/generate_test.clj rename to test/microworld/parser/generate_test.clj index eacd48c..a860424 100644 --- a/test/mw_parser/generate_test.clj +++ b/test/microworld/parser/generate_test.clj @@ -1,11 +1,11 @@ -(ns mw-parser.generate-test +(ns microworld.parser.generate-test (:use clojure.pprint - mw-engine.core - mw-engine.world - mw-engine.utils - mw-parser.utils) + microworld.engine.core + microworld.engine.world + microworld.engine.utils + microworld.parser.utils) (:require [clojure.test :refer :all] - [mw-parser.generate :refer :all])) + [microworld.parser.generate :refer :all])) (deftest expressions-tests