Upversioning whole system to 0.2.0, for flow feature
This is definitely a point version change!
This commit is contained in:
parent
bbaca4710b
commit
ca3861b505
|
@ -1,4 +1,4 @@
|
||||||
(defproject mw-parser "0.1.6-SNAPSHOT"
|
(defproject mw-parser "0.2.0-SNAPSHOT"
|
||||||
:description "Parser for production rules for MicroWorld engine"
|
:description "Parser for production rules for MicroWorld engine"
|
||||||
:url "http://www.journeyman.cc/microworld"
|
:url "http://www.journeyman.cc/microworld"
|
||||||
:manifest {
|
:manifest {
|
||||||
|
@ -14,5 +14,5 @@
|
||||||
:dependencies [[org.clojure/clojure "1.11.1"]
|
:dependencies [[org.clojure/clojure "1.11.1"]
|
||||||
[org.clojure/tools.trace "0.7.11"]
|
[org.clojure/tools.trace "0.7.11"]
|
||||||
[instaparse "1.4.12"]
|
[instaparse "1.4.12"]
|
||||||
[mw-engine "0.1.6-SNAPSHOT"]
|
[mw-engine "0.2.0-SNAPSHOT"]
|
||||||
[trptr/java-wrapper "0.2.3"]])
|
[trptr/java-wrapper "0.2.3"]])
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
"CHANCE-IN := 'chance in';"
|
"CHANCE-IN := 'chance in';"
|
||||||
"EACH := 'each' | 'every' | 'all';"
|
"EACH := 'each' | 'every' | 'all';"
|
||||||
"EQUAL := 'equal to';"
|
"EQUAL := 'equal to';"
|
||||||
|
"FIRST := 'first';"
|
||||||
"FLOW := 'flow' | 'move';"
|
"FLOW := 'flow' | 'move';"
|
||||||
"FROM := 'from';"
|
"FROM := 'from';"
|
||||||
"IF := 'if';"
|
"IF := 'if';"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"Grammar for flow rules"
|
"Grammar for flow rules"
|
||||||
(join "\n" ["FLOW-RULE := FLOW SPACE QUANTITY SPACE PROPERTY SPACE FROM SPACE SOURCE SPACE TO-HOW SPACE DESTINATION;"
|
(join "\n" ["FLOW-RULE := FLOW SPACE QUANTITY SPACE PROPERTY SPACE FROM SPACE SOURCE SPACE TO-HOW SPACE DESTINATION;"
|
||||||
"PERCENTAGE := NUMBER #'%';"
|
"PERCENTAGE := NUMBER #'%';"
|
||||||
"QUANTITY := PERCENTAGE | NUMBER;"
|
"QUANTITY := PERCENTAGE | NUMBER | SOME;"
|
||||||
"SOURCE := STATE | STATE SPACE WITH SPACE CONDITIONS;"
|
"SOURCE := STATE | STATE SPACE WITH SPACE CONDITIONS;"
|
||||||
"DESTINATION := STATE | STATE SPACE WITH SPACE FLOW-CONDITIONS;"
|
"DESTINATION := STATE | STATE SPACE WITH SPACE FLOW-CONDITIONS;"
|
||||||
"DETERMINER := MOST | LEAST;"
|
"DETERMINER := MOST | LEAST;"
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
"STATE := SYMBOL;"
|
"STATE := SYMBOL;"
|
||||||
"TO-HOW := TO | TO-EACH | TO-FIRST;"
|
"TO-HOW := TO | TO-EACH | TO-FIRST;"
|
||||||
"TO-EACH := TO SPACE EACH | TO SPACE ALL;"
|
"TO-EACH := TO SPACE EACH | TO SPACE ALL;"
|
||||||
"TO-FIRST := TO SPACE EACH"
|
"TO-FIRST := TO SPACE FIRST"
|
||||||
]))
|
]))
|
||||||
|
|
||||||
(def parse-flow
|
(def parse-flow
|
||||||
|
|
|
@ -53,9 +53,9 @@
|
||||||
|
|
||||||
|
|
||||||
(defn generate-conjunct-condition
|
(defn generate-conjunct-condition
|
||||||
[tree]
|
|
||||||
"From this `tree`, assumed to be a syntactically conjunct correct condition clause,
|
"From this `tree`, assumed to be a syntactically conjunct correct condition clause,
|
||||||
generate and return the appropriate clojure fragment."
|
generate and return the appropriate clojure fragment."
|
||||||
|
[tree]
|
||||||
(assert-type tree :CONJUNCT-CONDITION)
|
(assert-type tree :CONJUNCT-CONDITION)
|
||||||
(cons 'and (map generate (rest tree))))
|
(cons 'and (map generate (rest tree))))
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@
|
||||||
qualifier (generate (nth tree 2))
|
qualifier (generate (nth tree 2))
|
||||||
expression (generate (nth tree 3))]
|
expression (generate (nth tree 3))]
|
||||||
(generate-disjunct-property-condition tree property qualifier expression)))
|
(generate-disjunct-property-condition tree property qualifier expression)))
|
||||||
([tree property qualifier expression]
|
([_tree property qualifier expression]
|
||||||
(let [e (list 'some (list 'fn ['i] '(= i value)) (list 'quote expression))]
|
(let [e (list 'some (list 'fn ['i] '(= i value)) (list 'quote expression))]
|
||||||
(list 'let ['value (list property 'cell)]
|
(list 'let ['value (list property 'cell)]
|
||||||
(if (= qualifier '=) e
|
(if (= qualifier '=) e
|
||||||
|
@ -314,3 +314,11 @@
|
||||||
:WITHIN-CONDITION (generate-within-condition tree)
|
:WITHIN-CONDITION (generate-within-condition tree)
|
||||||
(map generate tree))
|
(map generate tree))
|
||||||
tree))
|
tree))
|
||||||
|
|
||||||
|
;;; Flow rules. A flow rule DOES NOT return a modified world; instead, it
|
||||||
|
;;; returns a PLAN to modify the world, in the form of a sequence of `flows`.
|
||||||
|
;;; It is only when the plan is executed that the world is modified.
|
||||||
|
;;;
|
||||||
|
;;; so we're looking at something like
|
||||||
|
;;; (fn [cell world])
|
||||||
|
;;; (if (= (:state cell) (or (:house cell) :house))
|
|
@ -1,7 +1,8 @@
|
||||||
(ns ^{:doc "Simplify a parse tree."
|
(ns ^{:doc "Simplify a parse tree."
|
||||||
:author "Simon Brooke"}
|
:author "Simon Brooke"}
|
||||||
mw-parser.simplify
|
mw-parser.simplify
|
||||||
(:require [mw-engine.utils :refer [member?]]))
|
(:require [clojure.pprint :refer [pprint]]
|
||||||
|
[mw-engine.utils :refer [member?]]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;
|
;;;;
|
||||||
|
@ -26,20 +27,20 @@
|
||||||
;;;;
|
;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(declare simplify-rule)
|
(declare simplify-flow simplify-rule)
|
||||||
|
|
||||||
(defn simplify-qualifier
|
;; (defn simplify-qualifier
|
||||||
"Given that this `tree` fragment represents a qualifier, what
|
;; "Given that this `tree` fragment represents a qualifier, what
|
||||||
qualifier is that?"
|
;; qualifier is that?"
|
||||||
[tree]
|
;; [tree]
|
||||||
(cond
|
;; (cond
|
||||||
(empty? tree) nil
|
;; (empty? tree) nil
|
||||||
(and (coll? tree)
|
;; (and (coll? tree)
|
||||||
(member? (first tree) '(:EQUIVALENCE :COMPARATIVE))) tree
|
;; (#{:EQUIVALENCE :COMPARATIVE} (first tree))) tree
|
||||||
(coll? (first tree)) (or (simplify-qualifier (first tree))
|
;; (coll? (first tree)) (or (simplify-qualifier (first tree))
|
||||||
(simplify-qualifier (rest tree)))
|
;; (simplify-qualifier (rest tree)))
|
||||||
(coll? tree) (simplify-qualifier (rest tree))
|
;; (coll? tree) (simplify-qualifier (rest tree))
|
||||||
:else tree))
|
;; :else tree))
|
||||||
|
|
||||||
(defn simplify-second-of-two
|
(defn simplify-second-of-two
|
||||||
"There are a number of possible simplifications such that if the `tree` has
|
"There are a number of possible simplifications such that if the `tree` has
|
||||||
|
@ -47,11 +48,11 @@
|
||||||
[tree]
|
[tree]
|
||||||
(if (= (count tree) 2) (simplify-rule (nth tree 1)) tree))
|
(if (= (count tree) 2) (simplify-rule (nth tree 1)) tree))
|
||||||
|
|
||||||
(defn simplify-quantifier
|
;; (defn simplify-quantifier
|
||||||
"If this quantifier is a number, 'simplifiy' it into a comparative whose operator is '='
|
;; "If this quantifier is a number, 'simplifiy' it into a comparative whose operator is '='
|
||||||
and whose quantity is that number. This is actually more complicated but makes generation easier."
|
;; and whose quantity is that number. This is actually more complicated but makes generation easier."
|
||||||
[tree]
|
;; [tree]
|
||||||
(if (number? (second tree)) [:COMPARATIVE '= (second tree)] (simplify-rule (second tree))))
|
;; (if (number? (second tree)) [:COMPARATIVE '= (second tree)] (simplify-rule (second tree))))
|
||||||
|
|
||||||
(defn simplify-rule
|
(defn simplify-rule
|
||||||
"Simplify/canonicalise this `tree`. Opportunistically replace complex fragments with
|
"Simplify/canonicalise this `tree`. Opportunistically replace complex fragments with
|
||||||
|
@ -76,12 +77,18 @@
|
||||||
(remove nil? (map simplify-rule tree)))
|
(remove nil? (map simplify-rule tree)))
|
||||||
tree))
|
tree))
|
||||||
|
|
||||||
|
(defn simplify-determiner-condition
|
||||||
|
[tree])
|
||||||
|
|
||||||
(defn simplify-flow
|
(defn simplify-flow
|
||||||
[tree]
|
[tree]
|
||||||
(if (coll? tree)
|
(if (coll? tree)
|
||||||
(case (first tree)
|
(case (first tree)
|
||||||
|
:FLOW nil
|
||||||
:DETERMINER (simplify-second-of-two tree)
|
:DETERMINER (simplify-second-of-two tree)
|
||||||
|
:DETERMINER-CONDITION (simplify-determiner-condition tree)
|
||||||
:SPACE nil
|
:SPACE nil
|
||||||
|
:QUANTITY (simplify-second-of-two tree)
|
||||||
:STATE [:PROPERTY-CONDITION
|
:STATE [:PROPERTY-CONDITION
|
||||||
[:SYMBOL "state"]
|
[:SYMBOL "state"]
|
||||||
[:QUALIFIER
|
[:QUALIFIER
|
||||||
|
|
Loading…
Reference in a new issue