From 9ccc8ea44ebe4f9a3d40c8e94b55f77c0d815099 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 20 Aug 2018 23:23:02 -0400 Subject: Some refactoring. --- luxc/src/lux/lexer.clj | 7 ++++--- luxc/src/lux/reader.clj | 15 +++++++++------ stdlib/source/lux.lux | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/luxc/src/lux/lexer.clj b/luxc/src/lux/lexer.clj index f74e14dfd..0a09c0619 100644 --- a/luxc/src/lux/lexer.clj +++ b/luxc/src/lux/lexer.clj @@ -26,8 +26,9 @@ ) ;; [Utils] -(defn ^:private clean-line [^String raw-line] +(defn- clean-line "(-> Text Text)" + [^String raw-line] (let [line-length (.length raw-line) buffer (new StringBuffer line-length)] (loop [idx 0] @@ -61,7 +62,7 @@ (recur (+ 1 idx))))) (.toString buffer))))) -(defn ^:private lex-text-body [multi-line? offset] +(defn- lex-text-body [multi-line? offset] (|do [[_ eol? ^String pre-quotes**] (&reader/read-regex #"^([^\"]*)") ^String pre-quotes* (if multi-line? (|do [:let [empty-line? (and eol? (= "" pre-quotes**))] @@ -110,7 +111,7 @@ [meta _ comment] (&reader/read-regex #"^(.*)$")] (return (&/T [meta ($Comment comment)])))) -(defn ^:private lex-multi-line-comment [_] +(defn- lex-multi-line-comment [_] (|do [_ (&reader/read-text "#(") [meta comment] (&/try-all% (&/|list (|do [[meta comment] (&reader/read-regex+ #"(?is)^(?!#\()((?!\)#).)*")] (return (&/T [meta comment]))) diff --git a/luxc/src/lux/reader.clj b/luxc/src/lux/reader.clj index 5f4aa8afe..14914cc2e 100644 --- a/luxc/src/lux/reader.clj +++ b/luxc/src/lux/reader.clj @@ -11,7 +11,7 @@ ("Yes" 2)) ;; [Utils] -(defn ^:private with-line [body] +(defn- with-line [body] (fn [state] (|case (&/get$ &/$source state) (&/$Nil) @@ -32,7 +32,7 @@ output)) ))) -(defn ^:private with-lines [body] +(defn- with-lines [body] (fn [state] (|case (body (&/get$ &/$source state)) (&/$Right reader* match) @@ -43,7 +43,7 @@ ((&/fail-with-loc msg) state) ))) -(defn ^:private re-find! [^java.util.regex.Pattern regex column ^String line] +(defn- re-find! [^java.util.regex.Pattern regex column ^String line] (let [matcher (doto (.matcher regex line) (.region column (.length line)) (.useAnchoringBounds true))] @@ -63,8 +63,9 @@ (&/T [(&/T [file-name line-num column-num*]) line])))) ($No (str "[Reader Error] Pattern failed: " regex)))))) -(defn read-regex? [regex] +(defn read-regex? "(-> Regex (Reader (Maybe Text)))" + [regex] (with-line (fn [file-name line-num column-num ^String line] (if-let [^String match (re-find! regex column-num line)] @@ -101,8 +102,9 @@ (&/T [(&/T [file-name line-num column-num]) prefix*])])))) (&/$Left (str "[Reader Error] Pattern failed: " regex)))))))) -(defn read-text [^String text] +(defn read-text "(-> Text (Reader Text))" + [^String text] (with-line (fn [file-name line-num column-num ^String line] (if (.startsWith line text column-num) @@ -114,8 +116,9 @@ (&/T [(&/T [file-name line-num column-num*]) line])))) ($No (str "[Reader Error] Text failed: " text)))))) -(defn read-text? [^String text] +(defn read-text? "(-> Text (Reader (Maybe Text)))" + [^String text] (with-line (fn [file-name line-num column-num ^String line] (if (.startsWith line text column-num) diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index bf92eb4db..d64b83bd3 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -19,7 +19,7 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type does not matter. + [dummy-cursor (5 "The type of things whose type is irrelevant. It can be used to write functions or data-structures that can take, or return, anything.")]] (0)))))]) @@ -35,7 +35,7 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type is unknown or undefined. + [dummy-cursor (5 "The type of things whose type is undefined. Useful for expressions that cause errors or other \"extraordinary\" conditions.")]] (0)))))]) -- cgit v1.2.3