Merge pull request #1799 from Kodiologist/kwp

Remove some exceptions in keyword parsing
This commit is contained in:
Kodi Arfer 2019-08-08 15:11:44 -04:00 committed by GitHub
commit d6ae646c66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 14 deletions

View File

@ -8,6 +8,8 @@ Removals
* Python 2 is no longer supported. * Python 2 is no longer supported.
* Support for attribute lists in `defclass` has been removed. Use `setv` * Support for attribute lists in `defclass` has been removed. Use `setv`
and `defn` instead. and `defn` instead.
* Literal keywords are no longer parsed differently in calls to functions
with certain names.
Bug Fixes Bug Fixes
------------------------------ ------------------------------

View File

@ -1664,11 +1664,7 @@ class HyASTCompiler(object):
if not func: if not func:
func = self.compile(root) func = self.compile(root)
# An exception for pulling together keyword args is if we're doing args, ret, keywords = self._compile_collect(args, with_kwargs=True)
# a typecheck, eg (type :foo)
with_kwargs = root not in (
"type", "HyKeyword", "keyword", "name", "keyword?", "identity")
args, ret, keywords = self._compile_collect(args, with_kwargs)
return func + ret + asty.Call( return func + ret + asty.Call(
expr, func=func.expr, args=args, keywords=keywords) expr, func=func.expr, args=args, keywords=keywords)

View File

@ -634,8 +634,8 @@ result['y in globals'] = 'y' in globals()")
"NATIVE: testing the keyword? function" "NATIVE: testing the keyword? function"
(assert (keyword? ':bar)) (assert (keyword? ':bar))
(assert (keyword? ':baz)) (assert (keyword? ':baz))
(assert (keyword? :bar)) (setv x :bar)
(assert (keyword? :baz)) (assert (keyword? x))
(assert (not (keyword? "foo"))) (assert (not (keyword? "foo")))
(assert (not (keyword? ":foo"))) (assert (not (keyword? ":foo")))
(assert (not (keyword? 1))) (assert (not (keyword? 1)))

View File

@ -1104,7 +1104,8 @@
(assert (= :foo :foo)) (assert (= :foo :foo))
(assert (= :foo ':foo)) (assert (= :foo ':foo))
(assert (is (type :foo) (type ':foo))) (setv x :foo)
(assert (is (type x) (type ':foo)))
(assert (= (get {:foo "bar"} :foo) "bar")) (assert (= (get {:foo "bar"} :foo) "bar"))
(assert (= (get {:bar "quux"} (get {:foo :bar} :foo)) "quux"))) (assert (= (get {:bar "quux"} (get {:foo :bar} :foo)) "quux")))
@ -1119,9 +1120,9 @@
(defn test-empty-keyword [] (defn test-empty-keyword []
"NATIVE: test that the empty keyword is recognized" "NATIVE: test that the empty keyword is recognized"
(assert (= : :)) (assert (= : :))
(assert (keyword? :)) (assert (keyword? ':))
(assert (!= : ":")) (assert (!= : ":"))
(assert (= (name :) ""))) (assert (= (name ':) "")))
(defn test-nested-if [] (defn test-nested-if []
@ -1198,12 +1199,15 @@
5j 5.1j 2+1j 1.2+3.4j 5j 5.1j 2+1j 1.2+3.4j
"" b"" "" b""
"apple bloom" b"apple bloom" "⚘" b"\x00" "apple bloom" b"apple bloom" "⚘" b"\x00"
:mykeyword
[] #{} {} [] #{} {}
[1 2 3] #{1 2 3} {"a" 1 "b" 2}]] [1 2 3] #{1 2 3} {"a" 1 "b" 2}]]
(assert (= (eval `(identity ~x)) x)) (assert (= (eval `(identity ~x)) x))
(assert (= (eval x) x))) (assert (= (eval x) x)))
(setv kw :mykeyword)
(assert (= (get (eval `[~kw]) 0) kw))
(assert (= (eval kw) kw))
; Tuples wrap to HyLists, not HyExpressions. ; Tuples wrap to HyLists, not HyExpressions.
(assert (= (eval (,)) [])) (assert (= (eval (,)) []))
(assert (= (eval (, 1 2 3)) [1 2 3])) (assert (= (eval (, 1 2 3)) [1 2 3]))
@ -1632,7 +1636,8 @@ macros()
(assert (= (keyword 'foo) :foo)) (assert (= (keyword 'foo) :foo))
(assert (= (keyword 'foo-bar) :foo-bar)) (assert (= (keyword 'foo-bar) :foo-bar))
(assert (= (keyword 1) :1)) (assert (= (keyword 1) :1))
(assert (= (keyword :foo_bar) :foo-bar))) (setv x :foo_bar)
(assert (= (keyword x) :foo-bar)))
(defn test-name-conversion [] (defn test-name-conversion []
"NATIVE: Test name conversion" "NATIVE: Test name conversion"
@ -1644,8 +1649,8 @@ macros()
(assert (= (name 'foo_bar) "foo-bar")) (assert (= (name 'foo_bar) "foo-bar"))
(assert (= (name 1) "1")) (assert (= (name 1) "1"))
(assert (= (name 1.0) "1.0")) (assert (= (name 1.0) "1.0"))
(assert (= (name :foo) "foo")) (assert (= (name ':foo) "foo"))
(assert (= (name :foo_bar) "foo-bar")) (assert (= (name ':foo_bar) "foo-bar"))
(assert (= (name test-name-conversion) "test-name-conversion"))) (assert (= (name test-name-conversion) "test-name-conversion")))
(defn test-keywords [] (defn test-keywords []