mw-parser.core
A very simple parser which parses production rules.
compile-rule
(compile-rule rule-text return-tuple?)
(compile-rule rule-text)
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 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.
Throws an exception if parsing fails.
gen-token-value
(gen-token-value token expect-int)
Parse a single value from this single token and return just the generated code, not a pair.
parse-comparator-neighbours-condition
(parse-comparator-neighbours-condition [MORE THAN n NEIGHBOURS WITHIN distance have-or-are & rest])
Parse conditions of the form ‘…more than 6 neighbours are condition’
parse-disjunct-value
(parse-disjunct-value [OR token & tokens] expect-int)
Parse a list of values from among these tokens
. If expect-int
is true, return integers or things which will evaluate to integers.
parse-member-condition
(parse-member-condition [property IS IN & rest])
parse-neighbours-condition
(parse-neighbours-condition tokens)
Parse conditions referring to neighbours
parse-property-int
(parse-property-int [value & remainder])
Parse a token assumed to be the name of a property of the current cell, whose value is assumed to be an integer.
parse-property-value
(parse-property-value [value & remainder])
Parse a token assumed to be the name of a property of the current cell.
parse-rule
(parse-rule line)
Parse a complete rule from this line
, expected to be either a string or a sequence of string tokens. Return the rule in the form of an S-expression.
Throws an exception if parsing fails.
parse-simple-condition
(parse-simple-condition tokens)
Parse conditions of the form ‘property comparison value’.
parse-simple-neighbours-condition
(parse-simple-neighbours-condition [n NEIGHBOURS WITHIN distance have-or-are & rest])
Parse conditions of the form ‘…6 neighbours are condition’
parse-simple-value
(parse-simple-value tokens expect-int)
(parse-simple-value tokens)
Parse a value from the first of these tokens
. If expect-int
is true, return an integer or something which will evaluate to an integer.
parse-some-neighbours-condition
(parse-some-neighbours-condition [SOME NEIGHBOURS & rest])
TODO: write docs
parse-token-value
(parse-token-value [value & remainder])
Parse a token assumed to be a simple token value.
parse-value
(parse-value tokens expect-int)
(parse-value tokens)
Parse a value from among these tokens
. If expect-int
is true, return an integer or something which will evaluate to an integer.