aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2018-08-23 01:24:29 -0400
committerEduardo Julian2018-08-23 01:24:29 -0400
commit7e312258b13c5fc9c80079fede0e41d479a8a327 (patch)
tree6d3158b42c007a3b481e24d31806b7d03cd7d2b0
parentbc251026c21590da76085bc0bc9abeaa5ec242b6 (diff)
No more escaping of back-slash.
-rw-r--r--lux-mode/lux-mode.el3
-rw-r--r--luxc/src/lux/lexer.clj21
-rw-r--r--stdlib/source/lux.lux2
-rw-r--r--stdlib/source/lux/compiler/default/name.lux2
-rw-r--r--stdlib/source/lux/compiler/default/syntax.lux2
-rw-r--r--stdlib/source/lux/data/format/json.lux20
-rw-r--r--stdlib/source/lux/data/text/regex.lux74
-rw-r--r--stdlib/test/test/lux/data/text/regex.lux102
8 files changed, 103 insertions, 123 deletions
diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el
index c48d41ae6..b3f5d2260 100644
--- a/lux-mode/lux-mode.el
+++ b/lux-mode/lux-mode.el
@@ -93,7 +93,6 @@ Otherwise check `define-lux-indent' and `put-lux-indent'."
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
(modify-syntax-entry ?\" "\"\"" table)
- (modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?# "w 124b" table)
(modify-syntax-entry ?\n "> b" table)
(modify-syntax-entry '(?a . ?z) "w" table)
@@ -122,7 +121,7 @@ Otherwise check `define-lux-indent' and `put-lux-indent'."
(modify-syntax-entry ?< "w" table)
(modify-syntax-entry ?> "w" table)
(modify-syntax-entry ?\; "w" table)
- ;; (modify-syntax-entry ?\\ "w" table)
+ (modify-syntax-entry ?\\ "w" table)
(modify-syntax-entry ?\s "-" table)
(modify-syntax-entry ?\t "-" table)
(modify-syntax-entry ?\r "-" table)
diff --git a/luxc/src/lux/lexer.clj b/luxc/src/lux/lexer.clj
index fc572790b..8ed75b940 100644
--- a/luxc/src/lux/lexer.clj
+++ b/luxc/src/lux/lexer.clj
@@ -26,31 +26,12 @@
)
;; [Utils]
-(defn- clean-line
- "(-> Text Text)"
- [^String raw-line]
- (let [line-length (.length raw-line)
- buffer (new StringBuffer line-length)]
- (loop [idx 0]
- (if (< idx line-length)
- (let [current-char (.charAt raw-line idx)]
- (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))
- \\ (do (.append buffer "\\")
- (recur (+ 2 idx)))
- ;; else
- (assert false (str "[Lexer Error] Invalid escaping syntax: " raw-line " " idx))))
- (do (.append buffer current-char)
- (recur (+ 1 idx)))))
- (.toString buffer)))))
-
(def lex-text
(|do [[meta _ _] (&reader/read-text "\"")
:let [[_ _ _column] meta]
[_ _ ^String content] (&reader/read-regex #"^([^\"]*)")
_ (&reader/read-text "\"")]
- (return (&/T [meta ($Text (clean-line content))]))))
+ (return (&/T [meta ($Text content)]))))
(def +ident-re+
#"^([^0-9\[\]\{\}\(\)\s\"#.][^\[\]\{\}\(\)\s\"#.]*)")
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index 0417c9a4d..bfbfe0678 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -5285,7 +5285,7 @@
"## Creates code documentation, embedding text as comments and properly formatting the forms it's being given."
__paragraph
"## For Example:" ..new-line
- "(doc ''Allows arbitrary looping, using the \\''recur\\'' form to re-start the loop.''" ..new-line
+ "(doc ''Allows arbitrary looping, using the 'recur' form to re-start the loop.''" ..new-line
" ''Can be used in monadic code to create monadic loops.''" ..new-line
" (loop [count +0" ..new-line
" x init]" ..new-line
diff --git a/stdlib/source/lux/compiler/default/name.lux b/stdlib/source/lux/compiler/default/name.lux
index ddbf9ee8f..925b0585d 100644
--- a/stdlib/source/lux/compiler/default/name.lux
+++ b/stdlib/source/lux/compiler/default/name.lux
@@ -12,7 +12,7 @@
(^ (char "+")) "_PLUS_"
(^ (char "-")) "_DASH_"
(^ (char "/")) "_SLASH_"
- (^ (char "\\")) "_BSLASH_"
+ (^ (char "\")) "_BSLASH_"
(^ (char "_")) "_UNDERS_"
(^ (char "%")) "_PERCENT_"
(^ (char "$")) "_DOLLAR_"
diff --git a/stdlib/source/lux/compiler/default/syntax.lux b/stdlib/source/lux/compiler/default/syntax.lux
index 92f223940..778588959 100644
--- a/stdlib/source/lux/compiler/default/syntax.lux
+++ b/stdlib/source/lux/compiler/default/syntax.lux
@@ -73,7 +73,7 @@
(def: #export open-record "{")
(def: #export close-record "}")
-(def: escape "\\")
+(def: escape "\")
(def: #export sigil "#")
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index 9189b375f..20f059503 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -452,29 +452,29 @@
(def: escaped~
(l.Lexer Text)
($_ p.either
- (p.after (l.this "\\t")
+ (p.after (l.this "\t")
(parser/wrap text.tab))
- (p.after (l.this "\\b")
+ (p.after (l.this "\b")
(parser/wrap text.back-space))
- (p.after (l.this "\\n")
+ (p.after (l.this "\n")
(parser/wrap text.new-line))
- (p.after (l.this "\\r")
+ (p.after (l.this "\r")
(parser/wrap text.carriage-return))
- (p.after (l.this "\\f")
+ (p.after (l.this "\f")
(parser/wrap text.form-feed))
- (p.after (l.this (text/compose "\\" text.double-quote))
+ (p.after (l.this (text/compose "\" text.double-quote))
(parser/wrap text.double-quote))
- (p.after (l.this "\\\\")
- (parser/wrap "\\"))))
+ (p.after (l.this "\\")
+ (parser/wrap "\"))))
(def: string~
(l.Lexer String)
(<| (l.enclosed [text.double-quote text.double-quote])
(loop [_ []])
(do p.Monad<Parser>
- [chars (l.some (l.none-of (text/compose "\\" text.double-quote)))
+ [chars (l.some (l.none-of (text/compose "\" text.double-quote)))
stop l.peek])
- (if (text/= "\\" stop)
+ (if (text/= "\" stop)
(do @
[escaped escaped~
next-chars (recur [])]
diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux
index ec11c9259..ba0128b7b 100644
--- a/stdlib/source/lux/data/text/regex.lux
+++ b/stdlib/source/lux/data/text/regex.lux
@@ -20,12 +20,12 @@
## [Utils]
(def: regex-char^
(l.Lexer Text)
- (l.none-of "\\.|&()[]{}"))
+ (l.none-of "\.|&()[]{}"))
(def: escaped-char^
(l.Lexer Text)
(do p.Monad<Parser>
- [? (l.this? "\\")]
+ [? (l.this? "\")]
(if ?
l.any
regex-char^)))
@@ -75,7 +75,7 @@
(def: (re-var^ current-module)
(-> Text (l.Lexer Code))
(do p.Monad<Parser>
- [name (l.enclosed ["\\@<" ">"] (name^ current-module))]
+ [name (l.enclosed ["\@<" ">"] (name^ current-module))]
(wrap (` (: (l.Lexer Text) (~ (code.identifier name)))))))
(def: re-range^
@@ -135,7 +135,7 @@
(def: punct^
(l.Lexer Text)
- (l.one-of (format "!#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
+ (l.one-of (format "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
//.double-quote)))
(def: graph^
@@ -153,27 +153,27 @@
[]
($_ p.either
(p.after (l.this ".") (wrap (` l.any)))
- (p.after (l.this "\\d") (wrap (` l.decimal)))
- (p.after (l.this "\\D") (wrap (` (l.not l.decimal))))
- (p.after (l.this "\\s") (wrap (` l.space)))
- (p.after (l.this "\\S") (wrap (` (l.not l.space))))
- (p.after (l.this "\\w") (wrap (` (~! word^))))
- (p.after (l.this "\\W") (wrap (` (l.not (~! word^)))))
-
- (p.after (l.this "\\p{Lower}") (wrap (` l.lower)))
- (p.after (l.this "\\p{Upper}") (wrap (` l.upper)))
- (p.after (l.this "\\p{Alpha}") (wrap (` l.alpha)))
- (p.after (l.this "\\p{Digit}") (wrap (` l.decimal)))
- (p.after (l.this "\\p{Alnum}") (wrap (` l.alpha-num)))
- (p.after (l.this "\\p{Space}") (wrap (` l.space)))
- (p.after (l.this "\\p{HexDigit}") (wrap (` l.hexadecimal)))
- (p.after (l.this "\\p{OctDigit}") (wrap (` l.octal)))
- (p.after (l.this "\\p{Blank}") (wrap (` (~! blank^))))
- (p.after (l.this "\\p{ASCII}") (wrap (` (~! ascii^))))
- (p.after (l.this "\\p{Contrl}") (wrap (` (~! control^))))
- (p.after (l.this "\\p{Punct}") (wrap (` (~! punct^))))
- (p.after (l.this "\\p{Graph}") (wrap (` (~! graph^))))
- (p.after (l.this "\\p{Print}") (wrap (` (~! print^))))
+ (p.after (l.this "\d") (wrap (` l.decimal)))
+ (p.after (l.this "\D") (wrap (` (l.not l.decimal))))
+ (p.after (l.this "\s") (wrap (` l.space)))
+ (p.after (l.this "\S") (wrap (` (l.not l.space))))
+ (p.after (l.this "\w") (wrap (` (~! word^))))
+ (p.after (l.this "\W") (wrap (` (l.not (~! word^)))))
+
+ (p.after (l.this "\p{Lower}") (wrap (` l.lower)))
+ (p.after (l.this "\p{Upper}") (wrap (` l.upper)))
+ (p.after (l.this "\p{Alpha}") (wrap (` l.alpha)))
+ (p.after (l.this "\p{Digit}") (wrap (` l.decimal)))
+ (p.after (l.this "\p{Alnum}") (wrap (` l.alpha-num)))
+ (p.after (l.this "\p{Space}") (wrap (` l.space)))
+ (p.after (l.this "\p{HexDigit}") (wrap (` l.hexadecimal)))
+ (p.after (l.this "\p{OctDigit}") (wrap (` l.octal)))
+ (p.after (l.this "\p{Blank}") (wrap (` (~! blank^))))
+ (p.after (l.this "\p{ASCII}") (wrap (` (~! ascii^))))
+ (p.after (l.this "\p{Contrl}") (wrap (` (~! control^))))
+ (p.after (l.this "\p{Punct}") (wrap (` (~! punct^))))
+ (p.after (l.this "\p{Graph}") (wrap (` (~! graph^))))
+ (p.after (l.this "\p{Print}") (wrap (` (~! print^))))
)))
(def: re-class^
@@ -189,11 +189,11 @@
(def: re-back-reference^
(l.Lexer Code)
(p.either (do p.Monad<Parser>
- [_ (l.this "\\")
+ [_ (l.this "\")
id number^]
(wrap (` ((~! ..copy) (~ (code.identifier ["" (int/encode (.int id))]))))))
(do p.Monad<Parser>
- [_ (l.this "\\k<")
+ [_ (l.this "\k<")
captured-name name-part^
_ (l.this ">")]
(wrap (` ((~! ..copy) (~ (code.identifier ["" captured-name]))))))))
@@ -411,11 +411,11 @@
(regex ".")
"Escaping"
- (regex "\\.")
+ (regex "\.")
"Character classes"
- (regex "\\d")
- (regex "\\p{Lower}")
+ (regex "\d")
+ (regex "\p{Lower}")
(regex "[abc]")
(regex "[a-z]")
(regex "[a-zA-Z]")
@@ -449,11 +449,11 @@
"Groups"
(regex "a(.)c")
(regex "a(b+)c")
- (regex "(\\d{3})-(\\d{3})-(\\d{4})")
- (regex "(\\d{3})-(?:\\d{3})-(\\d{4})")
- (regex "(?<code>\\d{3})-\\k<code>-(\\d{4})")
- (regex "(?<code>\\d{3})-\\k<code>-(\\d{4})-\\0")
- (regex "(\\d{3})-((\\d{3})-(\\d{4}))")
+ (regex "(\d{3})-(\d{3})-(\d{4})")
+ (regex "(\d{3})-(?:\d{3})-(\d{4})")
+ (regex "(?<code>\d{3})-\k<code>-(\d{4})")
+ (regex "(?<code>\d{3})-\k<code>-(\d{4})-\0")
+ (regex "(\d{3})-((\d{3})-(\d{4}))")
"Alternation"
(regex "a|b")
@@ -477,11 +477,11 @@
{branches (p.many s.any)})
{#.doc (doc "Allows you to test text against regular expressions."
(case some-text
- (^regex "(\\d{3})-(\\d{3})-(\\d{4})"
+ (^regex "(\d{3})-(\d{3})-(\d{4})"
[_ country-code area-code place-code])
do-some-thing-when-number
- (^regex "\\w+")
+ (^regex "\w+")
do-some-thing-when-word
_
diff --git a/stdlib/test/test/lux/data/text/regex.lux b/stdlib/test/test/lux/data/text/regex.lux
index 7c54d8385..3398f4685 100644
--- a/stdlib/test/test/lux/data/text/regex.lux
+++ b/stdlib/test/test/lux/data/text/regex.lux
@@ -53,8 +53,8 @@
(test "Can parse character literals."
(and (should-pass (&.regex "a") "a")
(should-fail (&.regex "a") ".")
- (should-pass (&.regex "\\.") ".")
- (should-fail (&.regex "\\.") "a"))))
+ (should-pass (&.regex "\.") ".")
+ (should-fail (&.regex "\.") "a"))))
(context: "Regular Expressions [System character classes]"
($_ seq
@@ -62,79 +62,79 @@
(should-pass (&.regex ".") "a"))
(test "Can parse digits."
- (and (should-pass (&.regex "\\d") "0")
- (should-fail (&.regex "\\d") "m")))
+ (and (should-pass (&.regex "\d") "0")
+ (should-fail (&.regex "\d") "m")))
(test "Can parse non digits."
- (and (should-pass (&.regex "\\D") "m")
- (should-fail (&.regex "\\D") "0")))
+ (and (should-pass (&.regex "\D") "m")
+ (should-fail (&.regex "\D") "0")))
(test "Can parse white-space."
- (and (should-pass (&.regex "\\s") " ")
- (should-fail (&.regex "\\s") "m")))
+ (and (should-pass (&.regex "\s") " ")
+ (should-fail (&.regex "\s") "m")))
(test "Can parse non white-space."
- (and (should-pass (&.regex "\\S") "m")
- (should-fail (&.regex "\\S") " ")))
+ (and (should-pass (&.regex "\S") "m")
+ (should-fail (&.regex "\S") " ")))
(test "Can parse word characters."
- (and (should-pass (&.regex "\\w") "_")
- (should-fail (&.regex "\\w") "^")))
+ (and (should-pass (&.regex "\w") "_")
+ (should-fail (&.regex "\w") "^")))
(test "Can parse non word characters."
- (and (should-pass (&.regex "\\W") ".")
- (should-fail (&.regex "\\W") "a")))
+ (and (should-pass (&.regex "\W") ".")
+ (should-fail (&.regex "\W") "a")))
))
(context: "Regular Expressions [Special system character classes : Part 1]"
($_ seq
(test "Can parse using special character classes."
- (and (and (should-pass (&.regex "\\p{Lower}") "m")
- (should-fail (&.regex "\\p{Lower}") "M"))
+ (and (and (should-pass (&.regex "\p{Lower}") "m")
+ (should-fail (&.regex "\p{Lower}") "M"))
- (and (should-pass (&.regex "\\p{Upper}") "M")
- (should-fail (&.regex "\\p{Upper}") "m"))
+ (and (should-pass (&.regex "\p{Upper}") "M")
+ (should-fail (&.regex "\p{Upper}") "m"))
- (and (should-pass (&.regex "\\p{Alpha}") "M")
- (should-fail (&.regex "\\p{Alpha}") "0"))
+ (and (should-pass (&.regex "\p{Alpha}") "M")
+ (should-fail (&.regex "\p{Alpha}") "0"))
- (and (should-pass (&.regex "\\p{Digit}") "1")
- (should-fail (&.regex "\\p{Digit}") "n"))
+ (and (should-pass (&.regex "\p{Digit}") "1")
+ (should-fail (&.regex "\p{Digit}") "n"))
- (and (should-pass (&.regex "\\p{Alnum}") "1")
- (should-fail (&.regex "\\p{Alnum}") "."))
+ (and (should-pass (&.regex "\p{Alnum}") "1")
+ (should-fail (&.regex "\p{Alnum}") "."))
- (and (should-pass (&.regex "\\p{Space}") " ")
- (should-fail (&.regex "\\p{Space}") "."))
+ (and (should-pass (&.regex "\p{Space}") " ")
+ (should-fail (&.regex "\p{Space}") "."))
))
))
(context: "Regular Expressions [Special system character classes : Part 2]"
($_ seq
(test "Can parse using special character classes."
- (and (and (should-pass (&.regex "\\p{HexDigit}") "a")
- (should-fail (&.regex "\\p{HexDigit}") "."))
+ (and (and (should-pass (&.regex "\p{HexDigit}") "a")
+ (should-fail (&.regex "\p{HexDigit}") "."))
- (and (should-pass (&.regex "\\p{OctDigit}") "6")
- (should-fail (&.regex "\\p{OctDigit}") "."))
+ (and (should-pass (&.regex "\p{OctDigit}") "6")
+ (should-fail (&.regex "\p{OctDigit}") "."))
- (and (should-pass (&.regex "\\p{Blank}") text.tab)
- (should-fail (&.regex "\\p{Blank}") "."))
+ (and (should-pass (&.regex "\p{Blank}") text.tab)
+ (should-fail (&.regex "\p{Blank}") "."))
- (and (should-pass (&.regex "\\p{ASCII}") text.tab)
- (should-fail (&.regex "\\p{ASCII}") (text.from-code (hex "1234"))))
+ (and (should-pass (&.regex "\p{ASCII}") text.tab)
+ (should-fail (&.regex "\p{ASCII}") (text.from-code (hex "1234"))))
- (and (should-pass (&.regex "\\p{Contrl}") (text.from-code (hex "12")))
- (should-fail (&.regex "\\p{Contrl}") "a"))
+ (and (should-pass (&.regex "\p{Contrl}") (text.from-code (hex "12")))
+ (should-fail (&.regex "\p{Contrl}") "a"))
- (and (should-pass (&.regex "\\p{Punct}") "@")
- (should-fail (&.regex "\\p{Punct}") "a"))
+ (and (should-pass (&.regex "\p{Punct}") "@")
+ (should-fail (&.regex "\p{Punct}") "a"))
- (and (should-pass (&.regex "\\p{Graph}") "@")
- (should-fail (&.regex "\\p{Graph}") " "))
+ (and (should-pass (&.regex "\p{Graph}") "@")
+ (should-fail (&.regex "\p{Graph}") " "))
- (and (should-pass (&.regex "\\p{Print}") (text.from-code (hex "20")))
- (should-fail (&.regex "\\p{Print}") (text.from-code (hex "1234"))))
+ (and (should-pass (&.regex "\p{Print}") (text.from-code (hex "20")))
+ (should-fail (&.regex "\p{Print}") (text.from-code (hex "1234"))))
))
))
@@ -191,9 +191,9 @@
))
(context: "Regular Expressions [Reference]"
- (let [number (&.regex "\\d+")]
+ (let [number (&.regex "\d+")]
(test "Can build complex regexs by combining simpler ones."
- (should-check ["809-345-6789" "809" "345" "6789"] (&.regex "(\\@<number>)-(\\@<number>)-(\\@<number>)") "809-345-6789"))))
+ (should-check ["809-345-6789" "809" "345" "6789"] (&.regex "(\@<number>)-(\@<number>)-(\@<number>)") "809-345-6789"))))
(context: "Regular Expressions [Fuzzy Quantifiers]"
($_ seq
@@ -240,14 +240,14 @@
(test "Can extract groups of sub-matches specified in a pattern."
(and (should-check ["abc" "b"] (&.regex "a(.)c") "abc")
(should-check ["abbbbbc" "bbbbb"] (&.regex "a(b+)c") "abbbbbc")
- (should-check ["809-345-6789" "809" "345" "6789"] (&.regex "(\\d{3})-(\\d{3})-(\\d{4})") "809-345-6789")
- (should-check ["809-345-6789" "809" "6789"] (&.regex "(\\d{3})-(?:\\d{3})-(\\d{4})") "809-345-6789")
- (should-check ["809-809-6789" "809" "6789"] (&.regex "(\\d{3})-\\0-(\\d{4})") "809-809-6789")
- (should-check ["809-809-6789" "809" "6789"] (&.regex "(?<code>\\d{3})-\\k<code>-(\\d{4})") "809-809-6789")
- (should-check ["809-809-6789-6789" "809" "6789"] (&.regex "(?<code>\\d{3})-\\k<code>-(\\d{4})-\\0") "809-809-6789-6789")))
+ (should-check ["809-345-6789" "809" "345" "6789"] (&.regex "(\d{3})-(\d{3})-(\d{4})") "809-345-6789")
+ (should-check ["809-345-6789" "809" "6789"] (&.regex "(\d{3})-(?:\d{3})-(\d{4})") "809-345-6789")
+ (should-check ["809-809-6789" "809" "6789"] (&.regex "(\d{3})-\0-(\d{4})") "809-809-6789")
+ (should-check ["809-809-6789" "809" "6789"] (&.regex "(?<code>\d{3})-\k<code>-(\d{4})") "809-809-6789")
+ (should-check ["809-809-6789-6789" "809" "6789"] (&.regex "(?<code>\d{3})-\k<code>-(\d{4})-\0") "809-809-6789-6789")))
(test "Can specify groups within groups."
- (should-check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (&.regex "(\\d{3})-((\\d{3})-(\\d{4}))") "809-345-6789"))
+ (should-check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (&.regex "(\d{3})-((\d{3})-(\d{4}))") "809-345-6789"))
))
(context: "Regular Expressions [Alternation]"
@@ -263,7 +263,7 @@
(should-fail (&.regex "a(.)(.)|b(.)(.)") "cde")
(should-check ["809-345-6789" (0 ["809" "345-6789" "345" "6789"])]
- (&.regex "(\\d{3})-((\\d{3})-(\\d{4}))|b(.)d")
+ (&.regex "(\d{3})-((\d{3})-(\d{4}))|b(.)d")
"809-345-6789")))
))