818
Du
dustymarkdown / files
dustymarkdown / node_modules / dust / src / dust.pegjs
2.5 KB
1{ 2 function wrap(node, ck) { 3 node['text'] = input.substring(ck.split('@')[1], pos); 4 return node; 5 } 6} 7 8start 9 = body 10 11body 12 = p:part* { return ["body"].concat(p) } 13 14part 15 = comment / section / partial / special / reference / buffer 16 17section "section" 18 = t:sec_tag_start rd b:body e:bodies n:end_tag 19 &{return result8[1].text === result12.text} 20 { e.push(["param", ["literal", "block"], b]); t.push(e); return t } 21 / t:sec_tag_start "/" rd 22 { t.push(["bodies"]); return t } 23 24sec_tag_start 25 = ld t:[#?^<+@%] n:identifier c:context p:params 26 { return [t, n, c, p] } 27 28end_tag "end tag" 29 = ld "/" n:identifier rd 30 { return n } 31 32context 33 = n:(":" n:identifier {return n})? 34 { return n ? ["context", n] : ["context"] } 35 36params "params" 37 = p:(ws k:key "=" v:(identifier / inline) {return ["param", ["literal", k], v]})* 38 { return ["params"].concat(p) } 39 40bodies "bodies" 41 = p:(ld ":" k:key rd v:body {return ["param", ["literal", k], v]})* 42 { return ["bodies"].concat(p) } 43 44reference "reference" 45 = ld n:identifier f:filters rd 46 { return ["reference", n, f] } 47 48partial "partial" 49 = ld ">" n:(k:key {return ["literal", k]} / inline) c:context "/" rd 50 { return ["partial", n, c] } 51 52filters "filters" 53 = f:("|" n:key {return n})* 54 { return ["filters"].concat(f) } 55 56special "special" 57 = ld "~" k:key rd 58 { return ["special", k] } 59 60identifier "identifier" 61 = p:path { return wrap(["path"].concat(p), cacheKey) } 62 / k:key { return wrap(["key", k], cacheKey) } 63 64path "path" 65 = k:key? d:("." k:key {return k})+ { 66 if (k) { d.unshift(k); return [false, d]; } 67 return [true, d]; 68 } 69 / "." { return [true, []] } 70 71key "key" 72 = h:[a-zA-Z_$] t:[0-9a-zA-Z_$]* 73 { return h + t.join('') } 74 75inline "inline" 76 = '"' '"' { return ["literal", ""] } 77 / '"' l:literal '"' { return ["literal", l] } 78 / '"' p:inline_part+ '"' { return ["body"].concat(p) } 79 80inline_part 81 = special / reference / l:literal { return ["buffer", l] } 82 83buffer "buffer" 84 = e:eol w:ws* 85 { return ["format", e, w.join('')] } 86 / b:(!tag !eol !comment c:. {return c})+ 87 { return ["buffer", b.join('')] } 88 89literal "literal" 90 = b:(!tag !eol c:(esc / [^"]) {return c})+ 91 { return b.join('') } 92 93esc 94 = '\\"' { return '"' } 95 96comment "comment" 97 = "{!" c:(!"!}" c:. {return c})* "!}" 98 { return ["comment", c.join('')] } 99 100tag 101 = ld [#?^><+%:@/~%] (!rd !eol .)+ rd 102 / reference 103 104ld 105 = "{" 106 107rd 108 = "}" 109 110eol 111 = "\n" 112 / "\r\n" 113 / "\r" 114 / "\u2028" 115 / "\u2029" 116 117ws 118 = [\t\v\f \u00A0\uFEFF]