New work on the parser, based on instaparse.

This commit is contained in:
Simon Brooke 2015-02-10 22:26:53 +00:00
parent dddeea6041
commit bbac9a9c6e
2 changed files with 33 additions and 0 deletions

View file

@ -13,5 +13,6 @@
:plugins [[lein-marginalia "0.7.1"]]
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/tools.trace "0.7.8"]
[instaparse "1.3.5"]
[mw-engine "0.1.5-SNAPSHOT"]
])

32
src/mw_parser/insta.clj Normal file
View file

@ -0,0 +1,32 @@
(ns mw-parser.insta
(:use mw-engine.utils
[clojure.string :only [split trim triml]])
(:require [instaparse.core :as insta]))
(def grammar
"RULE := 'if' SPACE CONDITIONS SPACE 'then' SPACE ACTIONS;
CONDITIONS := CONDITION | CONDITION SPACE 'and' SPACE CONDITIONS;
CONDITION := DISJUNCT-CONDITION | PROPERTY-CONDITION;
DISJUNCT-CONDITION := CONDITION SPACE 'or' SPACE CONDITION;
PROPERTY-CONDITION := PROPERTY SPACE 'is' SPACE EXPRESSION;
EXPRESSION := VALUE QUALIFIER EXPRESSION | VALUE OPERATOR EXPRESSION | VALUE;
QUALIFIER := SPACE 'more' SPACE 'than' SPACE | SPACE 'less' SPACE 'than' SPACE | SPACE 'fewer' SPACE 'than' SPACE | SPACE 'equal' SPACE 'to' SPACE ;
OPERATOR := '+' | '-' | '*' | '/';
PROPERTY := SYMBOL;
VALUE := SYMBOL | NUMBER;
NUMBER := #'[0-9.]+';
SYMBOL := #'[a-z]+';
ACTIONS := ACTION | ACTION SPACE 'and' SPACE ACTIONS
ACTION := SYMBOL SPACE 'should' SPACE 'be' SPACE EXPRESSION
SPACE := #'[:blank:]*'"
)
(def rule-parser
(insta/parser grammar))
(def token-parser (insta/parser "TOKEN := #'[a-z]+'"))