Advertisement
Guest User

Untitled

a guest
May 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def read-str
  2.   (let
  3.     [*all-chars (mapv char (range 0 128))
  4.      *negate (+seqf (constantly (symbol "negate")) (+char "n") (+char "e") (+char "g") (+char "a") (+char "t") (+char "e"))
  5.      *variable (+map symbol (+str (+plus (+char "xXyYzZ"))))
  6.      *digit (+char (apply str (filter #(Character/isDigit %) *all-chars)))
  7.      *space (+char (apply str (filter #(Character/isWhitespace %) *all-chars)))
  8.      *ws (+ignore (+star *space))
  9.      *number (+map read-string (+str (+plus (+or *digit (+char "-.")))))
  10.      *operations (+map symbol (+str (+plus (+char "+-/*"))))]
  11.     (letfn [(*seq [begin p end]
  12.               (+seqn 1 (+char begin) (+opt (+seqf cons *ws p (+star (+seqn 1 (+char " ") *ws p)))) *ws (+char end)))
  13.             (*array [] (*seq "(" (delay (*value)) ")"))
  14.             (*value [] (+or *negate *number *variable  (*array) *operations))]
  15.       (+parser (+seqn 0 *ws (*value) *ws)))))
  16.  
  17.  
  18. (defn parseSuffix [expression]
  19.   (cond
  20.     (number? expression) (Constant expression)
  21.     (symbol? expression) (Variable (str expression))
  22.     :else (apply (operationsMap (last expression)) (map parseSuffix (butlast expression)))
  23.     )
  24.   )
  25.  
  26. (defn parseObjectSuffix [expression] (parseSuffix (read-str expression)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement