Upversioning whole system to 0.2.0, for flow feature

This is definitely a point version change!
This commit is contained in:
Simon Brooke 2023-07-10 13:44:47 +01:00
parent bbaca4710b
commit ca3861b505
5 changed files with 41 additions and 25 deletions

View file

@ -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"
:url "http://www.journeyman.cc/microworld"
:manifest {
@ -14,5 +14,5 @@
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.trace "0.7.11"]
[instaparse "1.4.12"]
[mw-engine "0.1.6-SNAPSHOT"]
[mw-engine "0.2.0-SNAPSHOT"]
[trptr/java-wrapper "0.2.3"]])

View file

@ -88,6 +88,7 @@
"CHANCE-IN := 'chance in';"
"EACH := 'each' | 'every' | 'all';"
"EQUAL := 'equal to';"
"FIRST := 'first';"
"FLOW := 'flow' | 'move';"
"FROM := 'from';"
"IF := 'if';"

View file

@ -9,7 +9,7 @@
"Grammar for flow rules"
(join "\n" ["FLOW-RULE := FLOW SPACE QUANTITY SPACE PROPERTY SPACE FROM SPACE SOURCE SPACE TO-HOW SPACE DESTINATION;"
"PERCENTAGE := NUMBER #'%';"
"QUANTITY := PERCENTAGE | NUMBER;"
"QUANTITY := PERCENTAGE | NUMBER | SOME;"
"SOURCE := STATE | STATE SPACE WITH SPACE CONDITIONS;"
"DESTINATION := STATE | STATE SPACE WITH SPACE FLOW-CONDITIONS;"
"DETERMINER := MOST | LEAST;"
@ -18,7 +18,7 @@
"STATE := SYMBOL;"
"TO-HOW := TO | TO-EACH | TO-FIRST;"
"TO-EACH := TO SPACE EACH | TO SPACE ALL;"
"TO-FIRST := TO SPACE EACH"
"TO-FIRST := TO SPACE FIRST"
]))
(def parse-flow

View file

@ -53,9 +53,9 @@
(defn generate-conjunct-condition
[tree]
"From this `tree`, assumed to be a syntactically conjunct correct condition clause,
generate and return the appropriate clojure fragment."
[tree]
(assert-type tree :CONJUNCT-CONDITION)
(cons 'and (map generate (rest tree))))
@ -93,7 +93,7 @@
qualifier (generate (nth tree 2))
expression (generate (nth tree 3))]
(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))]
(list 'let ['value (list property 'cell)]
(if (= qualifier '=) e
@ -314,3 +314,11 @@
:WITHIN-CONDITION (generate-within-condition tree)
(map generate 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))

View file

@ -1,7 +1,8 @@
(ns ^{:doc "Simplify a parse tree."
:author "Simon Brooke"}
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
"Given that this `tree` fragment represents a qualifier, what
qualifier is that?"
[tree]
(cond
(empty? tree) nil
(and (coll? tree)
(member? (first tree) '(:EQUIVALENCE :COMPARATIVE))) tree
(coll? (first tree)) (or (simplify-qualifier (first tree))
(simplify-qualifier (rest tree)))
(coll? tree) (simplify-qualifier (rest tree))
:else tree))
;; (defn simplify-qualifier
;; "Given that this `tree` fragment represents a qualifier, what
;; qualifier is that?"
;; [tree]
;; (cond
;; (empty? tree) nil
;; (and (coll? tree)
;; (#{:EQUIVALENCE :COMPARATIVE} (first tree))) tree
;; (coll? (first tree)) (or (simplify-qualifier (first tree))
;; (simplify-qualifier (rest tree)))
;; (coll? tree) (simplify-qualifier (rest tree))
;; :else tree))
(defn simplify-second-of-two
"There are a number of possible simplifications such that if the `tree` has
@ -47,11 +48,11 @@
[tree]
(if (= (count tree) 2) (simplify-rule (nth tree 1)) tree))
(defn simplify-quantifier
"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."
[tree]
(if (number? (second tree)) [:COMPARATIVE '= (second tree)] (simplify-rule (second tree))))
;; (defn simplify-quantifier
;; "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."
;; [tree]
;; (if (number? (second tree)) [:COMPARATIVE '= (second tree)] (simplify-rule (second tree))))
(defn simplify-rule
"Simplify/canonicalise this `tree`. Opportunistically replace complex fragments with
@ -76,12 +77,18 @@
(remove nil? (map simplify-rule tree)))
tree))
(defn simplify-determiner-condition
[tree])
(defn simplify-flow
[tree]
(if (coll? tree)
(case (first tree)
:FLOW nil
:DETERMINER (simplify-second-of-two tree)
:DETERMINER-CONDITION (simplify-determiner-condition tree)
:SPACE nil
:QUANTITY (simplify-second-of-two tree)
:STATE [:PROPERTY-CONDITION
[:SYMBOL "state"]
[:QUALIFIER