Add (read-str)

This commit is contained in:
Gregor Best 2015-07-28 16:51:35 +02:00
parent 557571cc71
commit 2d7134a1be
2 changed files with 16 additions and 2 deletions

View File

@ -28,6 +28,9 @@
(import collections) (import collections)
(import [fractions [Fraction :as fraction]]) (import [fractions [Fraction :as fraction]])
(import sys) (import sys)
(if-python2
(import [StringIO [StringIO]])
(import [io [StringIO]]))
(import [hy._compat [long-type]]) ; long for python2, int for python3 (import [hy._compat [long-type]]) ; long for python2, int for python3
(import [hy.models.cons [HyCons]] (import [hy.models.cons [HyCons]]
[hy.models.symbol [HySymbol]] [hy.models.symbol [HySymbol]]
@ -382,6 +385,12 @@
(else (if parsed (break))))) (else (if parsed (break)))))
parsed) parsed)
(defn read-str [input]
"Reads and tokenizes first line of input"
(read :from-file (StringIO input)))
(defun Botsbuildbots () (Botsbuildbots)) (defun Botsbuildbots () (Botsbuildbots))
(defn zipwith [func &rest lists] (defn zipwith [func &rest lists]
@ -423,6 +432,6 @@
identity inc input instance? integer integer? integer-char? identity inc input instance? integer integer? integer-char?
interleave interpose iterable? iterate iterator? keyword interleave interpose iterable? iterate iterator? keyword
keyword? last list* macroexpand macroexpand-1 map merge-with keyword? last list* macroexpand macroexpand-1 map merge-with
name neg? nil? none? nth numeric? odd? pos? range read remove name neg? nil? none? nth numeric? odd? pos? range read read-str
repeat repeatedly rest reduce second some string string? remove repeat repeatedly rest reduce second some string string?
symbol? take take-nth take-while zero? zip zip_longest zipwith]) symbol? take take-nth take-while zero? zip zip_longest zipwith])

View File

@ -1170,6 +1170,11 @@
(catch [e Exception] (catch [e Exception]
(assert (isinstance e EOFError))))) (assert (isinstance e EOFError)))))
(defn test-read-str []
"NATIVE: test read-str"
(assert (= (read-str "foo") "foo"))
(assert (= (read-str "(print 1)") '(print 1))))
(defn test-keyword-creation [] (defn test-keyword-creation []
"NATIVE: Test keyword creation" "NATIVE: Test keyword creation"
(assert (= (keyword "foo") :foo)) (assert (= (keyword "foo") :foo))