Permalink
Browse files

partial work on moving parser to new version of parsley

  • Loading branch information...
1 parent 35a9546 commit 7c7e78644e52250cc1f9b675323eca8b2f5ee954 @joodie joodie committed Oct 22, 2011
Showing with 33 additions and 43 deletions.
  1. +33 −43 src/clojure_refactoring/support/parser.clj
@@ -1,48 +1,38 @@
(ns clojure-refactoring.support.parser
- (:require [net.cgrand.parsley.glr :as glr])
- (:use net.cgrand.parsley
- [clojure.contrib.def :only [defonce-]]))
+ (:use net.cgrand.parsley ))
-(defonce- sexp
- (memoize
- (parser {:space [#{:whitespace :comment :discard}:*]
- :main :expr*}
- :expr- #{:atom :list :vector :set :map :string :regex
- :meta :deprecated-meta :quote
- :unquote :syntax-quote :unquote-splicing
- :deref :var :fn :char}
- :atom1st- #{{\a \z \A \Z \0 \9} (any-of "!$%&*+-./:<=>?_")}
- :atom (token :atom1st #{:atom1st \#}:* (?! #{:atom1st \#}))
- :string (token \" #{(none-of \\ \") [\\ any-char]}:* \")
- :char (token \\ #{any-char "newline" "space" "tab" "backspace"
- "formfeed" "return"
- (into [\u] (repeat 4 {\0 \9 \a \f \A \F}))
- [\u :hex :hex :hex :hex]
- [\o {\0 \7}]
- [\o {\0 \7} {\0 \7}]
- [\o {\0 \3} {\0 \7} {\0 \7}]}
- (?! #{:atom1st \#}))
- :regex (token \# \" #{(none-of \\ \") [\\ any-char]}:* \")
- :list ["(" :expr* ")"]
- :vector ["[" :expr* "]"]
- :set ["#{" :expr* "}"]
- :map ["{" :expr* "}"]
- :discard ["#_" :expr]
- :meta ["^" :expr :expr]
- :quote [\' :expr]
- :syntax-quote [\` :expr]
- :tilda- [\~ (?! \@)]
- :unquote [:tilda :expr]
- :unquote-splicing ["~@" :expr]
- :deprecated-meta ["#^" :expr :expr]
- :deref [\@ :expr]
- :var ["#'" :expr]
- :fn ["#(" :expr* ")"]
+(def sexp
+ (parser {:space [:whitespace :discard :*]
+ :main :expr*}
+ :expr- #{:atom :list :vector :set :regex :map :meta :quote :char
+ :syntax-quote :unquote :unquote-splicing :deprecated-meta
+ :deref :var :fn}
+ :atom #"[a-zA-Z0-9!$%&*+\-\./:<=>?_][a-zA-Z0-9!$%&*+\-\./:<=>?_#]+"
+ :comment (unspaced #{"#!" ";"} #"[^\n]" :*)
+ :whitespace [#"[ \t\n,]+"]
+ :list ["(" :expr* ")"]
+ :vector ["[" :expr* "]"]
+ :set ["#{" :expr* "}"]
+ :regex #"\"([^\"\\]|(\\.))+\""
+ :pair- [:expr :expr]
+ :map ["{" :pair* "}"]
+ :discard ["#_" :expr]
+ :meta ["^" :pair]
+ :quote ["'" :expr]
+ :char (unspaced "\\" #{#"." "newline" "space" "tab" "backspace"
+ "formfeed" "return"
+ #"u[0-9a-fA-F]{4}"
+ #"u[0-7]{1,2}"
+ #"u[0-3][0-7]{2}"})
+ :syntax-quote ["`" :expr]
+ :tilde- #"~(?!@)"
+ :unquote [:tilde :expr]
+ :unquote-splicing ["~@" :expr]
+ :deprecated-meta ["#^" :pair]
+ :deref ["@" :expr]
+ :var ["#'" :expr]
+ :fn ["#(" :expr* ")"]))
- :comment (token #{"#!" ";"} (none-of \newline):* (?! (none-of \newline)))
-
- :whitespace (token #{\space \tab \newline \,}:+ (?! #{\space \tab \newline \,})))))
-
-(def parse (comp second first sexp))
+(def parse sexp)
(def parse1 (comp first parse)) ;;parses one node

0 comments on commit 7c7e786

Please sign in to comment.