-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigil.ex
61 lines (44 loc) · 1.21 KB
/
sigil.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# possibilities
# ~sigil_any/ /
# ~sigil_any| |
# ~sigil_any" "
# ~sigil_any' '
# ~sigil_any( )
# ~sigil_any[ ]
# ~sigil_any{ }
# ~sigil_any< >
~S"""
using template string
but without concatenation
"""
# output: "using template string\nbut without concatenation\n"
~S"""
#{this gonna be escaped} and
this `\n` not gonna break the line
"""
# output: "\#{this gonna be escaped} and \nthis `\\n` not gonna break the line\n"
~s(this gonna me escaped "" and this too '')
# output: "\#{this gonna be escaped} and \nthis `\\n` not gonna break the line\n"
~s/\#{this need to be escaped manually/
# output: "\#{this gonna be escaped} and \nthis `\\n` not gonna break the line\n"
~s{this too `\\n` needs to be escaped manually}
# output: "\#{this gonna be escaped} and \nthis `\\n` not gonna break the line\n"
~w<foo bar>a
# output: ["foo", "bar"]
~w<a b c>:a
# output: [:a, :b, :c]
# -*** *** ***-
defmodule MyCustomSigils do
def sigil_i(string, []), do: String.to_integer(string)
def sigil_i(string, [?n]), do: -String.to_integer(string)
end
# See more in module.ex
MyCustomSigils.sigil_i("13", [])
# output: 13
MyCustomSigils.sigil_i("14", [?n])
# output: -14
import MyCustomSigils
~i(13)
# output: 13
~i(42)n
# output: -42