config.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. package jade
  2. //go:generate stringer -type=itemType,NodeType -trimprefix=item -output=config_string.go
  3. var TabSize = 4
  4. var (
  5. golang_mode = false
  6. tag__bgn = "<%s%s>"
  7. tag__end = "</%s>"
  8. tag__void = "<%s%s/>"
  9. tag__arg_esc = ` %s="{{ print %s }}"`
  10. tag__arg_une = ` %s="{{ print %s }}"`
  11. tag__arg_str = ` %s="%s"`
  12. tag__arg_add = `%s " " %s`
  13. tag__arg_bgn = ""
  14. tag__arg_end = ""
  15. cond__if = "{{ if %s }}"
  16. cond__unless = "{{ if not %s }}"
  17. cond__case = "{{/* switch %s */}}"
  18. cond__while = "{{ range %s }}"
  19. cond__for = "{{/* %s, %s */}}{{ range %s }}"
  20. cond__end = "{{ end }}"
  21. cond__for_if = "{{ if gt len %s 0 }}{{/* %s, %s */}}{{ range %s }}"
  22. code__for_else = "{{ end }}{{ else }}"
  23. code__longcode = "{{/* %s */}}"
  24. code__buffered = "{{ %s }}"
  25. code__unescaped = "{{ %s }}"
  26. code__else = "{{ else }}"
  27. code__else_if = "{{ else if %s }}"
  28. code__case_when = "{{/* case %s: */}}"
  29. code__case_def = "{{/* default: */}}"
  30. code__mix_block = "{{/* block */}}"
  31. text__str = "%s"
  32. text__comment = "<!--%s -->"
  33. mixin__bgn = "\n%s"
  34. mixin__end = ""
  35. mixin__var_bgn = ""
  36. mixin__var = "{{ $%s := %s }}"
  37. mixin__var_rest = "{{ $%s := %#v }}"
  38. mixin__var_end = "\n"
  39. mixin__var_block_bgn = ""
  40. mixin__var_block = ""
  41. mixin__var_block_end = ""
  42. )
  43. type Cfg struct {
  44. GolangMode bool
  45. TagBgn string
  46. TagEnd string
  47. TagVoid string
  48. TagArgEsc string
  49. TagArgUne string
  50. TagArgStr string
  51. TagArgAdd string
  52. TagArgBgn string
  53. TagArgEnd string
  54. CondIf string
  55. CondUnless string
  56. CondCase string
  57. CondWhile string
  58. CondFor string
  59. CondEnd string
  60. CondForIf string
  61. CodeForElse string
  62. CodeLongcode string
  63. CodeBuffered string
  64. CodeUnescaped string
  65. CodeElse string
  66. CodeElseIf string
  67. CodeCaseWhen string
  68. CodeCaseDef string
  69. CodeMixBlock string
  70. TextStr string
  71. TextComment string
  72. MixinBgn string
  73. MixinEnd string
  74. MixinVarBgn string
  75. MixinVar string
  76. MixinVarRest string
  77. MixinVarEnd string
  78. MixinVarBlockBgn string
  79. MixinVarBlock string
  80. MixinVarBlockEnd string
  81. }
  82. func Config(c Cfg) {
  83. golang_mode = c.GolangMode
  84. if c.TagBgn != "" {
  85. tag__bgn = c.TagBgn
  86. }
  87. if c.TagEnd != "" {
  88. tag__end = c.TagEnd
  89. }
  90. if c.TagVoid != "" {
  91. tag__void = c.TagVoid
  92. }
  93. if c.TagArgEsc != "" {
  94. tag__arg_esc = c.TagArgEsc
  95. }
  96. if c.TagArgUne != "" {
  97. tag__arg_une = c.TagArgUne
  98. }
  99. if c.TagArgStr != "" {
  100. tag__arg_str = c.TagArgStr
  101. }
  102. if c.TagArgAdd != "" {
  103. tag__arg_add = c.TagArgAdd
  104. }
  105. if c.TagArgBgn != "" {
  106. tag__arg_bgn = c.TagArgBgn
  107. }
  108. if c.TagArgEnd != "" {
  109. tag__arg_end = c.TagArgEnd
  110. }
  111. if c.CondIf != "" {
  112. cond__if = c.CondIf
  113. }
  114. if c.CondUnless != "" {
  115. cond__unless = c.CondUnless
  116. }
  117. if c.CondCase != "" {
  118. cond__case = c.CondCase
  119. }
  120. if c.CondWhile != "" {
  121. cond__while = c.CondWhile
  122. }
  123. if c.CondFor != "" {
  124. cond__for = c.CondFor
  125. }
  126. if c.CondEnd != "" {
  127. cond__end = c.CondEnd
  128. }
  129. if c.CondForIf != "" {
  130. cond__for_if = c.CondForIf
  131. }
  132. if c.CodeForElse != "" {
  133. code__for_else = c.CodeForElse
  134. }
  135. if c.CodeLongcode != "" {
  136. code__longcode = c.CodeLongcode
  137. }
  138. if c.CodeBuffered != "" {
  139. code__buffered = c.CodeBuffered
  140. }
  141. if c.CodeUnescaped != "" {
  142. code__unescaped = c.CodeUnescaped
  143. }
  144. if c.CodeElse != "" {
  145. code__else = c.CodeElse
  146. }
  147. if c.CodeElseIf != "" {
  148. code__else_if = c.CodeElseIf
  149. }
  150. if c.CodeCaseWhen != "" {
  151. code__case_when = c.CodeCaseWhen
  152. }
  153. if c.CodeCaseDef != "" {
  154. code__case_def = c.CodeCaseDef
  155. }
  156. if c.CodeMixBlock != "" {
  157. code__mix_block = c.CodeMixBlock
  158. }
  159. if c.TextStr != "" {
  160. text__str = c.TextStr
  161. }
  162. if c.TextComment != "" {
  163. text__comment = c.TextComment
  164. }
  165. if c.MixinBgn != "" {
  166. mixin__bgn = c.MixinBgn
  167. }
  168. if c.MixinEnd != "" {
  169. mixin__end = c.MixinEnd
  170. }
  171. if c.MixinVarBgn != "" {
  172. mixin__var_bgn = c.MixinVarBgn
  173. }
  174. if c.MixinVar != "" {
  175. mixin__var = c.MixinVar
  176. }
  177. if c.MixinVarRest != "" {
  178. mixin__var_rest = c.MixinVarRest
  179. }
  180. if c.MixinVarEnd != "" {
  181. mixin__var_end = c.MixinVarEnd
  182. }
  183. if c.MixinVarBlockBgn != "" {
  184. mixin__var_block_bgn = c.MixinVarBlockBgn
  185. }
  186. if c.MixinVarBlock != "" {
  187. mixin__var_block = c.MixinVarBlock
  188. }
  189. if c.MixinVarBlockEnd != "" {
  190. mixin__var_block_end = c.MixinVarBlockEnd
  191. }
  192. }
  193. type Out struct {
  194. Name, Args, Import string
  195. }
  196. var Go Out
  197. func ConfigOtputPHP() {}
  198. type itemType int8
  199. const (
  200. itemError itemType = iota // error occurred; value is text of error
  201. itemEOF
  202. itemEndL
  203. itemIdent
  204. itemEmptyLine // empty line
  205. itemText // plain text
  206. itemComment // html comment
  207. itemHTMLTag // html <tag>
  208. itemDoctype // Doctype tag
  209. itemDiv // html div for . or #
  210. itemTag // html tag
  211. itemTagInline // inline tags
  212. itemTagEnd // for <tag />
  213. itemTagVoid // self-closing tags
  214. itemTagVoidInline // inline + self-closing tags
  215. itemID // id attribute
  216. itemClass // class attribute
  217. itemAttrStart
  218. itemAttrEnd
  219. itemAttr
  220. itemAttrSpace
  221. itemAttrComma
  222. itemAttrEqual
  223. itemAttrEqualUn
  224. itemFilter
  225. itemFilterSubf
  226. itemFilterArgs
  227. itemFilterText
  228. // itemKeyword // used only to delimit the keywords
  229. itemInclude
  230. itemExtends
  231. itemBlock
  232. itemBlockAppend
  233. itemBlockPrepend
  234. itemMixin
  235. itemMixinCall
  236. itemMixinBlock
  237. itemCode
  238. itemCodeBuffered
  239. itemCodeUnescaped
  240. itemIf
  241. itemElse
  242. itemElseIf
  243. itemUnless
  244. itemEach
  245. itemWhile
  246. itemFor
  247. itemForIfNotContain
  248. itemForElse
  249. itemCase
  250. itemCaseWhen
  251. itemCaseDefault
  252. )
  253. var key = map[string]itemType{
  254. "include": itemInclude,
  255. "extends": itemExtends,
  256. "block": itemBlock,
  257. "append": itemBlockAppend,
  258. "prepend": itemBlockPrepend,
  259. "mixin": itemMixin,
  260. "if": itemIf,
  261. "else": itemElse,
  262. "unless": itemUnless,
  263. "for": itemFor,
  264. "each": itemEach,
  265. "while": itemWhile,
  266. "case": itemCase,
  267. "when": itemCaseWhen,
  268. "default": itemCaseDefault,
  269. "doctype": itemDoctype,
  270. "a": itemTagInline,
  271. "abbr": itemTagInline,
  272. "acronym": itemTagInline,
  273. "b": itemTagInline,
  274. "code": itemTagInline,
  275. "em": itemTagInline,
  276. "font": itemTagInline,
  277. "i": itemTagInline,
  278. "ins": itemTagInline,
  279. "kbd": itemTagInline,
  280. "map": itemTagInline,
  281. "samp": itemTagInline,
  282. "small": itemTagInline,
  283. "span": itemTagInline,
  284. "strong": itemTagInline,
  285. "sub": itemTagInline,
  286. "sup": itemTagInline,
  287. "area": itemTagVoid,
  288. "base": itemTagVoid,
  289. "col": itemTagVoid,
  290. "command": itemTagVoid,
  291. "embed": itemTagVoid,
  292. "hr": itemTagVoid,
  293. "input": itemTagVoid,
  294. "keygen": itemTagVoid,
  295. "link": itemTagVoid,
  296. "meta": itemTagVoid,
  297. "param": itemTagVoid,
  298. "source": itemTagVoid,
  299. "track": itemTagVoid,
  300. "wbr": itemTagVoid,
  301. "br": itemTagVoidInline,
  302. "img": itemTagVoidInline,
  303. }
  304. // NodeType identifies the type of a parse tree node.
  305. type NodeType int
  306. // Type returns itself and provides an easy default implementation
  307. // for embedding in a Node. Embedded in all non-trivial Nodes.
  308. func (t NodeType) Type() NodeType {
  309. return t
  310. }
  311. const (
  312. NodeText NodeType = iota
  313. NodeList
  314. NodeTag
  315. NodeCode
  316. NodeCond
  317. NodeString
  318. NodeDoctype
  319. NodeMixin
  320. NodeBlock
  321. )