From 5e13ae0ad68947249a98dc69ab513bdbeca1697e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 22 Aug 2018 22:50:33 -0400 Subject: No more escaping of horizontal-tab. --- luxc/src/lux/lexer.clj | 2 - stdlib/source/lux.lux | 12 +----- .../compiler/default/phase/analysis/expression.lux | 4 +- .../lux/compiler/default/phase/extension.lux | 6 ++- .../default/phase/extension/analysis/host.jvm.lux | 2 +- stdlib/source/lux/compiler/default/syntax.lux | 4 +- stdlib/source/lux/data/collection/list.lux | 12 +++--- stdlib/source/lux/data/format/json.lux | 21 ++++++---- stdlib/source/lux/data/text.lux | 47 +++++++++++++--------- stdlib/source/lux/data/text/regex.lux | 20 ++++----- stdlib/source/lux/host.jvm.lux | 2 +- stdlib/test/test/lux/compiler/default/syntax.lux | 2 +- stdlib/test/test/lux/data/text/regex.lux | 6 +-- 13 files changed, 71 insertions(+), 69 deletions(-) diff --git a/luxc/src/lux/lexer.clj b/luxc/src/lux/lexer.clj index e81599957..37f5fdbed 100644 --- a/luxc/src/lux/lexer.clj +++ b/luxc/src/lux/lexer.clj @@ -37,8 +37,6 @@ (if (= \\ current-char) (do (assert (< (+ 1 idx) line-length) (str "[Lexer Error] Text is too short for escaping: " raw-line " " idx)) (case (.charAt raw-line (+ 1 idx)) - \t (do (.append buffer "\t") - (recur (+ 2 idx))) \v (do (.append buffer "\u000B") (recur (+ 2 idx))) \b (do (.append buffer "\b") diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 1b64aa22b..5ffe8d939 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5154,17 +5154,7 @@ (def: (text/encode original) (-> Text Text) - (let [escaped (|> original - (replace-all "\t" "\\t") - (replace-all "\v" "\\v") - (replace-all "\b" "\\b") - (replace-all "\n" "\\n") - (replace-all "\r" "\\r") - (replace-all "\f" "\\f") - (replace-all "\"" "\\\"") - (replace-all "\\" "\\\\") - )] - ($_ text/compose "\"" escaped "\""))) + ($_ text/compose "\"" original "\"")) (do-template [ ] [(def: #export ( value) diff --git a/stdlib/source/lux/compiler/default/phase/analysis/expression.lux b/stdlib/source/lux/compiler/default/phase/analysis/expression.lux index ed2f81735..073cc9950 100644 --- a/stdlib/source/lux/compiler/default/phase/analysis/expression.lux +++ b/stdlib/source/lux/compiler/default/phase/analysis/expression.lux @@ -26,14 +26,14 @@ (exception: #export (macro-expansion-failed {macro Name} {inputs (List Code)} {error Text}) (ex.report ["Macro" (%name macro)] ["Inputs" (|> inputs - (list/map (|>> %code (format "\n\t"))) + (list/map (|>> %code (format "\n" text.tab))) (text.join-with ""))] ["Error" error])) (exception: #export (macro-call-must-have-single-expansion {macro Name} {inputs (List Code)}) (ex.report ["Macro" (%name macro)] ["Inputs" (|> inputs - (list/map (|>> %code (format "\n\t"))) + (list/map (|>> %code (format "\n" text.tab))) (text.join-with ""))])) (exception: #export (unrecognized-syntax {code Code}) diff --git a/stdlib/source/lux/compiler/default/phase/extension.lux b/stdlib/source/lux/compiler/default/phase/extension.lux index 38ca02700..c7a2048a8 100644 --- a/stdlib/source/lux/compiler/default/phase/extension.lux +++ b/stdlib/source/lux/compiler/default/phase/extension.lux @@ -49,7 +49,7 @@ ["Available" (|> bundle dictionary.keys (list.sort text/<) - (list/map (|>> %t (format "\n\t"))) + (list/map (|>> %t (format "\n" text.tab))) (text.join-with ""))])) (exception: #export (incorrect-arity {name Text} {arity Nat} {args Nat}) @@ -75,7 +75,9 @@ (ex.throw unknown [where name bundle]) (#.Some handler) - ((handler name phase) parameters stateE)))) + ((<| (//.timed (name-of ..apply) (%t name)) + ((handler name phase) parameters)) + stateE)))) (def: #export (localized get set transform) (All [s s' i o v] diff --git a/stdlib/source/lux/compiler/default/phase/extension/analysis/host.jvm.lux b/stdlib/source/lux/compiler/default/phase/extension/analysis/host.jvm.lux index 5406ac20a..31f4b33ff 100644 --- a/stdlib/source/lux/compiler/default/phase/extension/analysis/host.jvm.lux +++ b/stdlib/source/lux/compiler/default/phase/extension/analysis/host.jvm.lux @@ -95,7 +95,7 @@ (ex.report ["Class" class] ["Method" method] ["Hints" (|> hints - (list/map (|>> product.left %type (format "\n\t"))) + (list/map (|>> product.left %type (format "\n" text.tab))) (text.join-with ""))]))] [no-candidates] diff --git a/stdlib/source/lux/compiler/default/syntax.lux b/stdlib/source/lux/compiler/default/syntax.lux index f333917d8..2aaa46992 100644 --- a/stdlib/source/lux/compiler/default/syntax.lux +++ b/stdlib/source/lux/compiler/default/syntax.lux @@ -140,7 +140,6 @@ [code l.any] (case code ## Handle special cases. - "t" (wrap [2 "\t"]) "v" (wrap [2 "\v"]) "b" (wrap [2 "\b"]) "n" (wrap [2 ..new-line]) @@ -624,8 +623,7 @@ (^template [ ] (^ (char )) (!find-next-escape 2 next-escape end source-code total )) - (["t" "\t"] - ["v" "\v"] + (["v" "\v"] ["b" "\b"] ["n" (static ..new-line)] ["r" "\r"] diff --git a/stdlib/source/lux/data/collection/list.lux b/stdlib/source/lux/data/collection/list.lux index ef1ebf5ac..c49a7ba9f 100644 --- a/stdlib/source/lux/data/collection/list.lux +++ b/stdlib/source/lux/data/collection/list.lux @@ -435,8 +435,8 @@ (identifier$ ("lux text concat" base "'"))])))) pattern (` [(~+ (map (function (_ [v vs]) (` (#.Cons (~ v) (~ vs)))) vars+lists))]) - g!step (identifier$ "\tstep\t") - g!blank (identifier$ "\t_\t") + g!step (identifier$ "0step0") + g!blank (identifier$ "0_0") list-vars (map product.right vars+lists) code (` (: (~ zip-type) (function ((~ g!step) (~+ list-vars)) @@ -466,8 +466,8 @@ (if (n/> 0 num-lists) (let [(^open ".") Functor indices (..indices num-lists) - g!return-type (identifier$ "\treturn-type\t") - g!func (identifier$ "\tfunc\t") + g!return-type (identifier$ "0return-type0") + g!func (identifier$ "0func0") type-vars (: (List Code) (map (|>> nat/encode identifier$) indices)) zip-type (` (All [(~+ type-vars) (~ g!return-type)] (-> (-> (~+ type-vars) (~ g!return-type)) @@ -482,8 +482,8 @@ (identifier$ ("lux text concat" base "'"))])))) pattern (` [(~+ (map (function (_ [v vs]) (` (#.Cons (~ v) (~ vs)))) vars+lists))]) - g!step (identifier$ "\tstep\t") - g!blank (identifier$ "\t_\t") + g!step (identifier$ "0step0") + g!blank (identifier$ "0_0") list-vars (map product.right vars+lists) code (` (: (~ zip-type) (function ((~ g!step) (~ g!func) (~+ list-vars)) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index c26df1893..1d0837b90 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -452,13 +452,20 @@ (def: escaped~ (l.Lexer Text) ($_ p.either - (p.after (l.this "\\t") (parser/wrap "\t")) - (p.after (l.this "\\b") (parser/wrap "\b")) - (p.after (l.this "\\n") (parser/wrap "\n")) - (p.after (l.this "\\r") (parser/wrap "\r")) - (p.after (l.this "\\f") (parser/wrap "\f")) - (p.after (l.this "\\\"") (parser/wrap "\"")) - (p.after (l.this "\\\\") (parser/wrap "\\")))) + (p.after (l.this "\\t") + (parser/wrap text.tab)) + (p.after (l.this "\\b") + (parser/wrap text.back-space)) + (p.after (l.this "\\n") + (parser/wrap text.new-line)) + (p.after (l.this "\\r") + (parser/wrap text.carriage-return)) + (p.after (l.this "\\f") + (parser/wrap text.form-feed)) + (p.after (l.this (text/compose "\\" text.double-quote)) + (parser/wrap text.double-quote)) + (p.after (l.this "\\\\") + (parser/wrap "\\")))) (def: string~ (l.Lexer String) diff --git a/stdlib/source/lux/data/text.lux b/stdlib/source/lux/data/text.lux index 48f35febe..0c6a5ea45 100644 --- a/stdlib/source/lux/data/text.lux +++ b/stdlib/source/lux/data/text.lux @@ -216,30 +216,37 @@ (-> Text Text Text) (enclose [boundary boundary] content)) -(def: #export encode - (-> Text Text) - (|>> (replace-all "\\" "\\\\") - (replace-all "\t" "\\t") - (replace-all "\v" "\\v") - (replace-all "\b" "\\b") - (replace-all "\n" "\\n") - (replace-all "\r" "\\r") - (replace-all "\f" "\\f") - (replace-all "\"" "\\\"") - (..enclose' "\""))) - (def: #export from-code (-> Nat Text) (|>> (:coerce Int) "lux int char")) +(do-template [ ] + [(def: #export (from-code ))] + + [back-space 8] + [tab 9] + [new-line 10] + [vertical-tab 11] + [form-feed 12] + [carriage-return 13] + [double-quote 34] + ) + +(def: #export encode + (-> Text Text) + (..enclose' ..double-quote)) + (def: #export (space? char) {#.doc "Checks whether the character is white-space."} (-> Nat Bit) - (case char - (^or (^ (char "\t")) (^ (char "\v")) - (^ (char " ")) (^ (char "\n")) - (^ (char "\r")) (^ (char "\f"))) - #1 - - _ - #0)) + (`` (case char + (^or (^ (char (~~ (static ..tab)))) + (^ (char (~~ (static ..vertical-tab)))) + (^ (char " ")) + (^ (char (~~ (static ..new-line)))) + (^ (char (~~ (static ..carriage-return)))) + (^ (char (~~ (static ..form-feed))))) + #1 + + _ + #0))) diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index ffd937d8e..a5409438e 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -8,14 +8,14 @@ ["e" error] ["." maybe] ["." number ("int/." Codec)] - ["." text - ["l" lexer] - format] [collection ["." list ("list/." Fold Monad)]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]]]) + ["s" syntax (#+ syntax:)]]] + ["." // + ["l" lexer] + format]) ## [Utils] (def: regex-char^ @@ -50,7 +50,7 @@ (-> (l.Lexer (List Text)) (l.Lexer Text)) (do p.Monad [parts part^] - (wrap (text.join-with "" parts)))) + (wrap (//.join-with "" parts)))) (def: name-char^ (l.Lexer Text) @@ -81,9 +81,9 @@ (def: re-range^ (l.Lexer Code) (do p.Monad - [from (|> regex-char^ (:: @ map (|>> (text.nth 0) maybe.assume))) + [from (|> regex-char^ (:: @ map (|>> (//.nth 0) maybe.assume))) _ (l.this "-") - to (|> regex-char^ (:: @ map (|>> (text.nth 0) maybe.assume)))] + to (|> regex-char^ (:: @ map (|>> (//.nth 0) maybe.assume)))] (wrap (` (l.range (~ (code.nat from)) (~ (code.nat to))))))) (def: re-char^ @@ -122,7 +122,7 @@ (def: blank^ (l.Lexer Text) - (l.one-of " \t")) + (l.one-of (format " " //.tab))) (def: ascii^ (l.Lexer Text) @@ -278,7 +278,7 @@ [idx names (list& (list g!temp complex - (' #let) (` [(~ g!total) (:: (~! text.Monoid) (~' compose) (~ g!total) (~ g!temp))])) + (' #let) (` [(~ g!total) (:: (~! //.Monoid) (~' compose) (~ g!total) (~ g!temp))])) steps)] (#.Right [(#Capturing [?name num-captures]) scoped]) @@ -294,7 +294,7 @@ [idx! (list& name! names) (list& (list name! scoped - (' #let) (` [(~ g!total) (:: (~! text.Monoid) (~' compose) (~ g!total) (~ access))])) + (' #let) (` [(~ g!total) (:: (~! //.Monoid) (~' compose) (~ g!total) (~ access))])) steps)]) ))) [+0 diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index b7a55dfaa..9bb839aec 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -1088,7 +1088,7 @@ (def: (annotation$ [name params]) (-> Annotation JVM-Code) - (format "(" name " " "{" (text.join-with "\t" (list/map annotation-param$ params)) "}" ")")) + (format "(" name " " "{" (text.join-with text.tab (list/map annotation-param$ params)) "}" ")")) (def: (bound-kind$ kind) (-> BoundKind JVM-Code) diff --git a/stdlib/test/test/lux/compiler/default/syntax.lux b/stdlib/test/test/lux/compiler/default/syntax.lux index 1bcb9dad8..6a447e9c1 100644 --- a/stdlib/test/test/lux/compiler/default/syntax.lux +++ b/stdlib/test/test/lux/compiler/default/syntax.lux @@ -30,7 +30,7 @@ (do r.Monad [#let [digits "0123456789" delimiters "()[]{}#.\"" - space "\t\v \n\r\f" + space "\v \n\r\f" invalid-range (format digits delimiters space) char-gen (|> r.nat (:: @ map (|>> (n/% 256) (n/max 1))) diff --git a/stdlib/test/test/lux/data/text/regex.lux b/stdlib/test/test/lux/data/text/regex.lux index 96f56c3d9..7a6e88d33 100644 --- a/stdlib/test/test/lux/data/text/regex.lux +++ b/stdlib/test/test/lux/data/text/regex.lux @@ -5,7 +5,7 @@ pipe ["p" parser]] [data - [text ("text/." Equivalence) + ["." text ("text/." Equivalence) format ["." lexer (#+ Lexer)] ["&" regex]]] @@ -117,10 +117,10 @@ (and (should-pass (&.regex "\\p{OctDigit}") "6") (should-fail (&.regex "\\p{OctDigit}") ".")) - (and (should-pass (&.regex "\\p{Blank}") "\t") + (and (should-pass (&.regex "\\p{Blank}") text.tab) (should-fail (&.regex "\\p{Blank}") ".")) - (and (should-pass (&.regex "\\p{ASCII}") "\t") + (and (should-pass (&.regex "\\p{ASCII}") text.tab) (should-fail (&.regex "\\p{ASCII}") "\u1234")) (and (should-pass (&.regex "\\p{Contrl}") "\u0012") -- cgit v1.2.3