Skip to content

Commit 534df40

Browse files
author
Josh Kaplan
committed
Added sample.json and generateRules.py for developers
1 parent 36f6f55 commit 534df40

File tree

4 files changed

+309
-2
lines changed

4 files changed

+309
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.sublime-*
2-
samples
3-
tools
2+
samples/*
3+
tools/*
44
dependencies
55
packages.json

LICENSE-MIT

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,62 @@ furnished to do so, subject to the following conditions:
1212
The above copyright notice and this permission notice shall be included in
1313
all copies or substantial portions of the Software.
1414

15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
-------------------------------------------------------------------------------
24+
25+
This software has components that are based on other existing products.
26+
In compliance with their licenses, the following copyright notices are
27+
included below:
28+
29+
30+
Source: https://github.com/ColibriApps/MonokaiJsonPlus
31+
32+
The MIT License (MIT)
33+
34+
Copyright (c) 2014 ColibriApps. https://www.colibriapps.com
35+
36+
Permission is hereby granted, free of charge, to any person obtaining a copy
37+
of this software and associated documentation files (the "Software"), to deal
38+
in the Software without restriction, including without limitation the rights
39+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40+
copies of the Software, and to permit persons to whom the Software is
41+
furnished to do so, subject to the following conditions:
42+
43+
The above copyright notice and this permission notice shall be included in all
44+
copies or substantial portions of the Software.
45+
46+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52+
SOFTWARE.
53+
54+
55+
Source: https://github.com/jonschlinkert/sublime-monokai-extended
56+
57+
The MIT License (MIT)
58+
59+
Copyright (c) 2013-2016, Jon Schlinkert.
60+
61+
Permission is hereby granted, free of charge, to any person obtaining a copy
62+
of this software and associated documentation files (the "Software"), to deal
63+
in the Software without restriction, including without limitation the rights
64+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
65+
copies of the Software, and to permit persons to whom the Software is
66+
furnished to do so, subject to the following conditions:
67+
68+
The above copyright notice and this permission notice shall be included in
69+
all copies or substantial portions of the Software.
70+
1571
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1672
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1773
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

samples/sample.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"Level-1 Key" : "Level-1 Value",
3+
"Level-1 Key" : "Level-1 Value",
4+
"Level-1 Key" : "Level-1 Value",
5+
"Level-1 Key" : "Level-1 Value",
6+
"Level-1 Key" : "Level-1 Value",
7+
"Level-1 Key" : {
8+
"Level-2 Key" : "Level-2 Value",
9+
"Level-2 Key" : "Level-2 Value",
10+
"Level-2 Key" : "Level-2 Value",
11+
"Level-2 Key" : "Level-2 Value",
12+
"Level-2 Key" : "Level-2 Value",
13+
"Level-2 Key" : {
14+
"Level-3 Key" : "Level-3 Value",
15+
"Level-3 Key" : "Level-3 Value",
16+
"Level-3 Key" : "Level-3 Value",
17+
"Level-3 Key" : "Level-3 Value",
18+
"Level-3 Key" : "Level-3 Value",
19+
"Level-3 Key" : {
20+
"Level-4 Key" : "Level-4 Value",
21+
"Level-4 Key" : "Level-4 Value",
22+
"Level-4 Key" : "Level-4 Value",
23+
"Level-4 Key" : "Level-4 Value",
24+
"Level-4 Key" : "Level-4 Value",
25+
"Level-4 Key" : {
26+
"Level-5 Key" : "Level-5 Value",
27+
"Level-5 Key" : "Level-5 Value",
28+
"Level-5 Key" : "Level-5 Value",
29+
"Level-5 Key" : "Level-5 Value",
30+
"Level-5 Key" : "Level-5 Value",
31+
"Level-5 Key" : {
32+
"Level-6 Key" : "Level-6 Value",
33+
"Level-6 Key" : "Level-6 Value",
34+
"Level-6 Key" : "Level-6 Value",
35+
"Level-6 Key" : "Level-6 Value",
36+
"Level-6 Key" : "Level-6 Value",
37+
"Level-6 Key" : {
38+
"Level-7 Key" : "Level-7 Value",
39+
"Level-7 Key" : "Level-7 Value",
40+
"Level-7 Key" : "Level-7 Value",
41+
"Level-7 Key" : "Level-7 Value",
42+
"Level-7 Key" : "Level-7 Value",
43+
"Level-7 Key" : {
44+
"Level-7 Key" : "Level-7 Value",
45+
"Level-7 Key" : "Level-7 Value",
46+
"Level-7 Key" : "Level-7 Value",
47+
"Level-7 Key" : "Level-7 Value",
48+
"Level-7 Key" : "Level-7 Value",
49+
"Level-7 Key" : "Level-7 Value"
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}

tools/generateRules.py

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
##
2+
## https://github.com/ColibriApps/MonokaiJsonPlus
3+
##
4+
5+
import itertools
6+
import xml.dom.minidom
7+
from itertools import permutations
8+
9+
# Define Colors for the 10 Levels
10+
colors = [
11+
"#66D9EF", # Level 1 - Blue
12+
"#AE81FF", # Level 2 - Purple
13+
"#F92672", # Level 3 - Magenta
14+
"#A6E22E", # Level 4 - Green
15+
"#FD971F", # Level 5 - Orange
16+
"#E6DB74", # Level 6 - Yellow
17+
"#66D9EF", # Level 7 - Blue
18+
"#A6E22E", # Level 8 - Green
19+
"#E6DB74", # Level 9 - Yellow
20+
21+
"#66D9EF", # Level 1 - Blue
22+
"#AE81FF", # Level 2 - Purple
23+
"#F92672", # Level 3 - Magenta
24+
"#A6E22E", # Level 4 - Green
25+
"#FD971F", # Level 5 - Orange
26+
"#E6DB74", # Level 6 - Yellow
27+
"#66D9EF", # Level 7 - Blue
28+
"#A6E22E", # Level 8 - Green
29+
"#E6DB74" # Level 9 - Yellow
30+
31+
]
32+
33+
colors_val = [
34+
"#999999", # Level 1
35+
"#999999", # Level 2
36+
"#999999", # Level 3
37+
"#999999", # Level 4
38+
"#999999", # Level 5
39+
"#999999", # Level 6
40+
"#999999", # Level 7
41+
"#999999", # Level 8
42+
"#999999",
43+
"#999999",
44+
"#999999", # Level 1
45+
"#999999", # Level 2
46+
"#999999", # Level 3
47+
"#999999", # Level 4
48+
"#999999", # Level 5
49+
"#999999", # Level 6
50+
"#999999", # Level 7
51+
"#999999", # Level 8
52+
"#999999",
53+
"#999999"
54+
]
55+
56+
# defines the placeholder values
57+
prefix1 = "<dict><key>name</key><string>"
58+
prefix2 = "</string><key>scope</key><string>source.json "
59+
postfix1 = "string.quoted.double.json</string><key>settings</key><dict><key>foreground</key><string>"
60+
postfix2 = "</string></dict></dict>"
61+
d = "meta.structure.dictionary.json "
62+
v = "meta.structure.dictionary.value.json "
63+
a = "meta.structure.array.json "
64+
65+
# Logic to generate the required schema of dictionary key and values
66+
def getSequenceArray(items):
67+
result = []
68+
for item in items:
69+
tmp_item = item[:-1]
70+
s = 'dv' + tmp_item.replace('d', 'dv') + item[-1:]
71+
result.append(s)
72+
if item[-1:] == 'd':
73+
result.append(s + 'v')
74+
return result
75+
76+
# Generate Levels
77+
# Level 1 & 2
78+
levels = [
79+
[
80+
"d",
81+
"dv"
82+
],
83+
[
84+
"dvd",
85+
"dvdv",
86+
"dva"
87+
]
88+
]
89+
90+
# Level 3
91+
s = set()
92+
s.update([''.join(p) for p in permutations('dd')])
93+
s.update([''.join(p) for p in permutations('da')])
94+
s.update([''.join(p) for p in permutations('aa')])
95+
levels.append(getSequenceArray(s))
96+
97+
# Level 4
98+
s = set()
99+
s.update([''.join(p) for p in permutations('ddd')])
100+
s.update([''.join(p) for p in permutations('dda')])
101+
s.update([''.join(p) for p in permutations('daa')])
102+
s.update([''.join(p) for p in permutations('aaa')])
103+
levels.append(getSequenceArray(s))
104+
105+
# Level 5
106+
s = set()
107+
s.update([''.join(p) for p in permutations('dddd')])
108+
s.update([''.join(p) for p in permutations('ddda')])
109+
s.update([''.join(p) for p in permutations('ddaa')])
110+
s.update([''.join(p) for p in permutations('daaa')])
111+
s.update([''.join(p) for p in permutations('aaaa')])
112+
levels.append(getSequenceArray(s))
113+
114+
# Level 6
115+
s = set()
116+
s.update([''.join(p) for p in permutations('ddddd')])
117+
s.update([''.join(p) for p in permutations('dddda')])
118+
s.update([''.join(p) for p in permutations('dddaa')])
119+
s.update([''.join(p) for p in permutations('ddaaa')])
120+
s.update([''.join(p) for p in permutations('daaaa')])
121+
s.update([''.join(p) for p in permutations('aaaaa')])
122+
levels.append(getSequenceArray(s))
123+
124+
# Level 7
125+
s = set()
126+
s.update([''.join(p) for p in permutations('dddddd')])
127+
s.update([''.join(p) for p in permutations('ddddda')])
128+
s.update([''.join(p) for p in permutations('ddddaa')])
129+
s.update([''.join(p) for p in permutations('dddaaa')])
130+
s.update([''.join(p) for p in permutations('ddaaaa')])
131+
s.update([''.join(p) for p in permutations('daaaaa')])
132+
s.update([''.join(p) for p in permutations('aaaaaa')])
133+
levels.append(getSequenceArray(s))
134+
135+
# Level 8
136+
s = set()
137+
s.update([''.join(p) for p in permutations('ddddddd')])
138+
s.update([''.join(p) for p in permutations('dddddda')])
139+
s.update([''.join(p) for p in permutations('dddddaa')])
140+
s.update([''.join(p) for p in permutations('ddddaaa')])
141+
s.update([''.join(p) for p in permutations('dddaaaa')])
142+
s.update([''.join(p) for p in permutations('ddaaaaa')])
143+
s.update([''.join(p) for p in permutations('daaaaaa')])
144+
s.update([''.join(p) for p in permutations('aaaaaaa')])
145+
levels.append(getSequenceArray(s))
146+
147+
# Level 9
148+
s = set()
149+
s.update([''.join(p) for p in permutations('dddddddd')])
150+
s.update([''.join(p) for p in permutations('ddddddda')])
151+
s.update([''.join(p) for p in permutations('ddddddaa')])
152+
s.update([''.join(p) for p in permutations('dddddaaa')])
153+
s.update([''.join(p) for p in permutations('ddddaaaa')])
154+
s.update([''.join(p) for p in permutations('dddaaaaa')])
155+
s.update([''.join(p) for p in permutations('ddaaaaaa')])
156+
s.update([''.join(p) for p in permutations('daaaaaaa')])
157+
s.update([''.join(p) for p in permutations('aaaaaaaa')])
158+
levels.append(getSequenceArray(s))
159+
160+
# Level 10+
161+
s = set()
162+
s.update([''.join(p) for p in permutations('ddddddddd')])
163+
s.update([''.join(p) for p in permutations('dddddddda')])
164+
s.update([''.join(p) for p in permutations('dddddddaa')])
165+
s.update([''.join(p) for p in permutations('ddddddaaa')])
166+
s.update([''.join(p) for p in permutations('dddddaaaa')])
167+
s.update([''.join(p) for p in permutations('ddddaaaaa')])
168+
s.update([''.join(p) for p in permutations('dddaaaaaa')])
169+
s.update([''.join(p) for p in permutations('ddaaaaaaa')])
170+
s.update([''.join(p) for p in permutations('daaaaaaaa')])
171+
s.update([''.join(p) for p in permutations('aaaaaaaaa')])
172+
levels.append(getSequenceArray(s))
173+
174+
# Generate XML output
175+
output = ""
176+
for i in xrange(len(levels) - 1, -1, -1):
177+
level = levels[i]
178+
for items in level:
179+
result = prefix1 + "JSON - Level " + str(i + 1) + prefix2
180+
for item in list(items):
181+
if item == "d":
182+
result = result + d
183+
elif item == "v":
184+
result = result + v
185+
elif item == "a":
186+
result = result + a
187+
if item == "v" or item == "a":
188+
result = result + postfix1 + colors_val[i] + postfix2
189+
else:
190+
result = result + postfix1 + colors[i] + postfix2
191+
output = output + xml.dom.minidom.parseString(result).toprettyxml(
192+
indent="\t").replace("<?xml version=\"1.0\" ?>\n", "")
193+
194+
print output

0 commit comments

Comments
 (0)