forked from Joker/jade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
362 lines (321 loc) · 6.96 KB
/
config.go
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package jade
//go:generate stringer -type=itemType,NodeType -trimprefix=item -output=config_string.go
var TabSize = 4
var (
golang_mode = false
tag__bgn = "<%s%s>"
tag__end = "</%s>"
tag__void = "<%s%s/>"
tag__arg_esc = ` %s="{{ print %s }}"`
tag__arg_une = ` %s="{{ print %s }}"`
tag__arg_str = ` %s="%s"`
tag__arg_add = `%s " " %s`
tag__arg_bgn = ""
tag__arg_end = ""
cond__if = "{{ if %s }}"
cond__unless = "{{ if not %s }}"
cond__case = "{{/* switch %s */}}"
cond__while = "{{ range %s }}"
cond__for = "{{/* %s, %s */}}{{ range %s }}"
cond__end = "{{ end }}"
cond__for_if = "{{ if gt len %s 0 }}{{/* %s, %s */}}{{ range %s }}"
code__for_else = "{{ end }}{{ else }}"
code__longcode = "{{/* %s */}}"
code__buffered = "{{ %s }}"
code__unescaped = "{{ %s }}"
code__else = "{{ else }}"
code__else_if = "{{ else if %s }}"
code__case_when = "{{/* case %s: */}}"
code__case_def = "{{/* default: */}}"
code__mix_block = "{{/* block */}}"
text__str = "%s"
text__comment = "<!--%s -->"
mixin__bgn = "\n%s"
mixin__end = ""
mixin__var_bgn = ""
mixin__var = "{{ $%s := %s }}"
mixin__var_rest = "{{ $%s := %#v }}"
mixin__var_end = "\n"
mixin__var_block_bgn = ""
mixin__var_block = ""
mixin__var_block_end = ""
)
type Cfg struct {
GolangMode bool
TagBgn string
TagEnd string
TagVoid string
TagArgEsc string
TagArgUne string
TagArgStr string
TagArgAdd string
TagArgBgn string
TagArgEnd string
CondIf string
CondUnless string
CondCase string
CondWhile string
CondFor string
CondEnd string
CondForIf string
CodeForElse string
CodeLongcode string
CodeBuffered string
CodeUnescaped string
CodeElse string
CodeElseIf string
CodeCaseWhen string
CodeCaseDef string
CodeMixBlock string
TextStr string
TextComment string
MixinBgn string
MixinEnd string
MixinVarBgn string
MixinVar string
MixinVarRest string
MixinVarEnd string
MixinVarBlockBgn string
MixinVarBlock string
MixinVarBlockEnd string
}
func Config(c Cfg) {
golang_mode = c.GolangMode
if c.TagBgn != "" {
tag__bgn = c.TagBgn
}
if c.TagEnd != "" {
tag__end = c.TagEnd
}
if c.TagVoid != "" {
tag__void = c.TagVoid
}
if c.TagArgEsc != "" {
tag__arg_esc = c.TagArgEsc
}
if c.TagArgUne != "" {
tag__arg_une = c.TagArgUne
}
if c.TagArgStr != "" {
tag__arg_str = c.TagArgStr
}
if c.TagArgAdd != "" {
tag__arg_add = c.TagArgAdd
}
if c.TagArgBgn != "" {
tag__arg_bgn = c.TagArgBgn
}
if c.TagArgEnd != "" {
tag__arg_end = c.TagArgEnd
}
if c.CondIf != "" {
cond__if = c.CondIf
}
if c.CondUnless != "" {
cond__unless = c.CondUnless
}
if c.CondCase != "" {
cond__case = c.CondCase
}
if c.CondWhile != "" {
cond__while = c.CondWhile
}
if c.CondFor != "" {
cond__for = c.CondFor
}
if c.CondEnd != "" {
cond__end = c.CondEnd
}
if c.CondForIf != "" {
cond__for_if = c.CondForIf
}
if c.CodeForElse != "" {
code__for_else = c.CodeForElse
}
if c.CodeLongcode != "" {
code__longcode = c.CodeLongcode
}
if c.CodeBuffered != "" {
code__buffered = c.CodeBuffered
}
if c.CodeUnescaped != "" {
code__unescaped = c.CodeUnescaped
}
if c.CodeElse != "" {
code__else = c.CodeElse
}
if c.CodeElseIf != "" {
code__else_if = c.CodeElseIf
}
if c.CodeCaseWhen != "" {
code__case_when = c.CodeCaseWhen
}
if c.CodeCaseDef != "" {
code__case_def = c.CodeCaseDef
}
if c.CodeMixBlock != "" {
code__mix_block = c.CodeMixBlock
}
if c.TextStr != "" {
text__str = c.TextStr
}
if c.TextComment != "" {
text__comment = c.TextComment
}
if c.MixinBgn != "" {
mixin__bgn = c.MixinBgn
}
if c.MixinEnd != "" {
mixin__end = c.MixinEnd
}
if c.MixinVarBgn != "" {
mixin__var_bgn = c.MixinVarBgn
}
if c.MixinVar != "" {
mixin__var = c.MixinVar
}
if c.MixinVarRest != "" {
mixin__var_rest = c.MixinVarRest
}
if c.MixinVarEnd != "" {
mixin__var_end = c.MixinVarEnd
}
if c.MixinVarBlockBgn != "" {
mixin__var_block_bgn = c.MixinVarBlockBgn
}
if c.MixinVarBlock != "" {
mixin__var_block = c.MixinVarBlock
}
if c.MixinVarBlockEnd != "" {
mixin__var_block_end = c.MixinVarBlockEnd
}
}
type Out struct {
Name, Args, Import string
}
var Go Out
func ConfigOtputPHP() {}
type itemType int8
const (
itemError itemType = iota // error occurred; value is text of error
itemEOF
itemEndL
itemIdent
itemEmptyLine // empty line
itemText // plain text
itemComment // html comment
itemHTMLTag // html <tag>
itemDoctype // Doctype tag
itemDiv // html div for . or #
itemTag // html tag
itemTagInline // inline tags
itemTagEnd // for <tag />
itemTagVoid // self-closing tags
itemTagVoidInline // inline + self-closing tags
itemID // id attribute
itemClass // class attribute
itemAttrStart
itemAttrEnd
itemAttr
itemAttrSpace
itemAttrComma
itemAttrEqual
itemAttrEqualUn
itemFilter
itemFilterSubf
itemFilterArgs
itemFilterText
// itemKeyword // used only to delimit the keywords
itemInclude
itemExtends
itemBlock
itemBlockAppend
itemBlockPrepend
itemMixin
itemMixinCall
itemMixinBlock
itemCode
itemCodeBuffered
itemCodeUnescaped
itemIf
itemElse
itemElseIf
itemUnless
itemEach
itemWhile
itemFor
itemForIfNotContain
itemForElse
itemCase
itemCaseWhen
itemCaseDefault
)
var key = map[string]itemType{
"include": itemInclude,
"extends": itemExtends,
"block": itemBlock,
"append": itemBlockAppend,
"prepend": itemBlockPrepend,
"mixin": itemMixin,
"if": itemIf,
"else": itemElse,
"unless": itemUnless,
"for": itemFor,
"each": itemEach,
"while": itemWhile,
"case": itemCase,
"when": itemCaseWhen,
"default": itemCaseDefault,
"doctype": itemDoctype,
"a": itemTagInline,
"abbr": itemTagInline,
"acronym": itemTagInline,
"b": itemTagInline,
"code": itemTagInline,
"em": itemTagInline,
"font": itemTagInline,
"i": itemTagInline,
"ins": itemTagInline,
"kbd": itemTagInline,
"map": itemTagInline,
"samp": itemTagInline,
"small": itemTagInline,
"span": itemTagInline,
"strong": itemTagInline,
"sub": itemTagInline,
"sup": itemTagInline,
"area": itemTagVoid,
"base": itemTagVoid,
"col": itemTagVoid,
"command": itemTagVoid,
"embed": itemTagVoid,
"hr": itemTagVoid,
"input": itemTagVoid,
"keygen": itemTagVoid,
"link": itemTagVoid,
"meta": itemTagVoid,
"param": itemTagVoid,
"source": itemTagVoid,
"track": itemTagVoid,
"wbr": itemTagVoid,
"br": itemTagVoidInline,
"img": itemTagVoidInline,
}
// NodeType identifies the type of a parse tree node.
type NodeType int
// Type returns itself and provides an easy default implementation
// for embedding in a Node. Embedded in all non-trivial Nodes.
func (t NodeType) Type() NodeType {
return t
}
const (
NodeText NodeType = iota
NodeList
NodeTag
NodeCode
NodeCond
NodeString
NodeDoctype
NodeMixin
NodeBlock
)