diff --git a/hy/core/language.hy b/hy/core/language.hy index b17f041..d70e84b 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -28,6 +28,9 @@ (import collections) (import [fractions [Fraction :as fraction]]) (import sys) +(if-python2 + (import [StringIO [StringIO]]) + (import [io [StringIO]])) (import [hy._compat [long-type]]) ; long for python2, int for python3 (import [hy.models.cons [HyCons]] [hy.models.symbol [HySymbol]] @@ -382,6 +385,12 @@ (else (if parsed (break))))) parsed) + +(defn read-str [input] + "Reads and tokenizes first line of input" + (read :from-file (StringIO input))) + + (defun Botsbuildbots () (Botsbuildbots)) (defn zipwith [func &rest lists] @@ -423,6 +432,6 @@ identity inc input instance? integer integer? integer-char? interleave interpose iterable? iterate iterator? keyword keyword? last list* macroexpand macroexpand-1 map merge-with - name neg? nil? none? nth numeric? odd? pos? range read remove - repeat repeatedly rest reduce second some string string? + name neg? nil? none? nth numeric? odd? pos? range read read-str + remove repeat repeatedly rest reduce second some string string? symbol? take take-nth take-while zero? zip zip_longest zipwith]) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 08804c0..bd1a997 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -1170,6 +1170,11 @@ (catch [e Exception] (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 [] "NATIVE: Test keyword creation" (assert (= (keyword "foo") :foo))