Permalink
Browse files

Mirror LispReader when matching missing symbol names

LispReader is very liberal about what characters may appear in a symbol:

    static Pattern symbolPat
        = Pattern.compile("[:]?([\\D&&[^/]].*/)?(/|[\\D&&[^/]][^/]*)");

Therefore non-ASCII Unicode strings are also valid symbols:

    (def unicode-symbols
      '#{스람훈드 Σλαμηονδ ∧ ∨ ∩ ∪ ¬ ∀ ∅ ∴ ∫})

The new sym-pat now covers this set of characters as well.

Also from LispReader.java:

    static boolean isWhitespace(int ch){
        return Character.isWhitespace(ch) || ch == ',';
    }

Happily, the symbol names in error messages are only ever surrounded by
spaces and commas.
  • Loading branch information...
1 parent bedcadd commit e7ac623d967e38d638d3e1df90c5e3226a0ef6b0 @guns guns committed Jan 4, 2014
Showing with 8 additions and 3 deletions.
  1. +1 −1 src/slam/hound/regrow.clj
  2. +6 −1 test/slam/hound/regrow_test.clj
  3. +1 −1 todo.org
@@ -21,7 +21,7 @@
(Character/isUpperCase ^Character (first (name x))))
(def ^:private missing-sym-patterns
- (let [sym-pat #"([-\+_\w\$\?!\*\>\<=]+'*|/)"
+ (let [sym-pat #"(/|\D[^\p{javaWhitespace},/]*)"
prefixes [#"Unable to resolve \w+: "
"Can't resolve: "
"No such namespace: "
@@ -23,6 +23,9 @@
(def CapitalVar true)
(def Pattern "Not java.util.Pattern")
(def trim (constantly "Conflicts with clojure.string/trim"))
+(def τ (* Math/PI 2))
+(def:intersection)
+(def:star)
;; Explicitly require korma for tests below
(require 'korma.core)
@@ -159,7 +162,9 @@
((keyword? /))])
'{:old {:exclude {clojure.core #{/}}}
:exclude {clojure.core #{/}}
- :refer {slam.hound.regrow-test #{/}}})))
+ :refer {slam.hound.regrow-test #{/}}}))
+ (is (= (regrow '[{} ((def unicode-syms [τ ∩ ★]))])
+ '{:refer {slam.hound.regrow-test #{τ ∩ ★}}})))
(testing "finds consumed references within syntax-quotes"
(is (= (regrow '[{:name slam.hound.regrow-test}
((eval `(instance? Named :foo)))])
View
@@ -25,6 +25,6 @@
* Minor enhancements
- [X] Sort alias candidates by L̶e̶v̶e̶n̶s̶h̶t̶e̶i̶n̶ "alias" distance, with emphasis on initial letters
- [X] Satisfy all reflection warnings (there are only a handful)
+ - [X] Support Unicode characters in regrow/missing-sym-name
- [ ] Count dashes as word separators when calculating "alias" distance
- - [ ] Support Unicode characters in regrow/missing-sym-name
- [ ] Sort refer candidates by matching arity. e.g. (join []) should prefer clojure.string/join

0 comments on commit e7ac623

Please sign in to comment.