Created
May 12, 2018 05:58
-
-
Save Conaws/aea4d4413961fd2d3035ab52ed07e48b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns history.logicparser | |
(:require [instaparse.core :as insta] | |
[clojure.string :as str])) | |
(def desireparse | |
(insta/parser | |
"S = desire phrase '.' | |
desire = 'I want' | |
phrase = (<w> word)+ | |
w = #'\\s+' | |
word = #'[a-zA-Z]+' | |
cond = 'because'")) | |
(def desire-reason | |
(insta/parser | |
"S = (desire/ reason / and/ phrase)+ <'.'?> | |
reason = (<w>? <#'[Bb]ecause'> phrase) | |
<br> = and | reason | desire | |
<phrase> = br / (<w> !br word)+ | |
desire = (<w>? <'I want'> phrase) | |
w = #'\\s+' | |
<word> = #'[a-zA-Z]+' | |
and = (<w>? <'and'> phrase)")) | |
(insta/visualize (insta/parse desire-reason "I want to go to dinner because I am hungry and I want to see my friends.")) | |
(insta/visualize (desire-reason "I want to touch Conors butt because it is tight.")) | |
(insta/visualize (filter vector? (map desire-reason ["I want to eat chocholate" "Because oxygen exists and sodium combine I want to study chemistry"]))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment