forked from creationix/jack-old
/
test.jack
116 lines (103 loc) · 2.06 KB
/
test.jack
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"cool ${\"stuff $more\"}."
"content $var"
"$var content"
"content $var content"
"$var content $var"
"content"
"$var"
"${var}${var}"
""
SQL"content $var"
SQL"$var content"
SQL"content $var content"
SQL"$var content $var"
SQL"content"
SQL"$var"
SQL"${var}${var}"
SQL""
# Boolean Literals
# (Superset of JavaScript)
true
false
on
off
yes
no
# Number Literals
# (Same as JavaScript)
0xff0088
523
0XFFEE33
123.32
-0.32
0.234
6.02e23
6.02E23
# String Literals
# Single quote only, but with heredoc style added
# Heredoc contents don't include opening line and
# are left trimmed to match closing triplet.
'Hello \'World\''
'''
Hello "World"
In 'Multi' lines
'''
# Interpolated literals
# Double quotes and double heredoc
# Values are replaced last minute by a smart agent.
# (SQL escaper, HTML escape)
"Hello $planetoid"
SQL"""
SELECT * FROM users
WHERE name = $name
"""
HTML"<h$l>$title</h$l>"
# http://google-caja.googlecode.com/svn/changes/mikesamuel/string-interpolation-29-Jan-2008/trunk/src/js/com/google/caja/interp/index.html
# Interpolated use cases
"$noun $verb"
#-> (noun + " " + verb)
#=> "World Greets"
SQL"SELECT * FROM users WHERE name=$name"
#-> SQL.interpolate("SELECT * FROM users WHERE name=", name)
#=> "SELECT * FROM users WHERE name='O''Connor'"
JSON"{name: ${data.name}, age: ${data.age}"
#-> JSON.interpolate("{name: ", name, ", data.age: ", data.age}")
#=> "{name: "Tim", age: 27}"
# Regular Expression literals
/123/g
/^([^a-z]+)$/i
# List Literals
[ 1, 2, 3, 4 ]
[
1,0,0
0,1,0
0,0,1
]
# Object Literals
{name="Tim" age=27}
{
name="Tim"
age=27
}
# Delegated Objects
# Creates a new object that inherits from the given
# prototype, and then overrides some properties.
{Animal name="George" color="Brown"}
{Animal
name="George"
color="Brown"
}
# Delegated Lists
# Creates a clone of the passed in List-like object
# but replaces the contents with that given.
[HTMLColors 0x000000, 0xff8800, 0x0088ff, 0x887788]
[HTMLColors
0x000000
0xff8800
0x0088ff
0x887788
]
# Function literal
fun x -> x
# Curried function
fun a -> b -> x