-
Notifications
You must be signed in to change notification settings - Fork 10
/
split-vars.ometajs
37 lines (27 loc) · 1.53 KB
/
split-vars.ometajs
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
var K = require('../krasota'),
KrasotaJSIdentity = K.KrasotaJSIdentity;
ometa KrasotaJS <: KrasotaJSIdentity {
varItemInd = ([#varItemAsgn varItemInd:s t t t t] | [#varItemName t:s t t]) -> s,
varItemOutd = ([#varItemAsgn t t t t t:s] | [#varItemName t t t:s]) -> s,
splitVarItems :s1 :se :s2 = [t:v1_ splitVarItem1(s1, se, s2, v1_):v1 varItemInd(v1_):v1Ind
splitVarItem(s1, se, s2, v1Ind)*:vs] -> [v1].concat(vs),
splitVarItem1 :s1 :se :s2 = t:v varItemOutd(v):stmtOutd -> [#stmt, s1, [#varStmt, [v]], se, stmtOutd],
splitVarItem :s1 :se :s2 :v1Ind = t:v_
splitVarItem_(v1Ind, v_):v
varItemInd(v_):stmtInd_ splitVarItemInd(stmtInd_):stmtInd
varItemOutd(v_):stmtOutd -> [#stmt, stmtInd, [#varStmt, [v]], se, stmtOutd],
splitVarItem_ :v1Ind = [#varItemAsgn splitVarItem_(v1Ind):n t:s1 t:s2 t:e t:s3] -> [#varItemAsgn, n, s1, s2, e, s3]
| [#varItemName t t:n t:s2] -> [#varItemName, v1Ind, n, s2],
splitVarItemInd = [#spacesAndComments [splitVarItemIndSpaces*:sc]] -> [#spacesAndComments, sc],
splitVarItemIndSpaces = [#spaces :s] -> [#spaces, s.replace(/ {4}$/, '')]
| t,
splitVarStmtLast :s = [#stmt t:s1 t:v t:se t:s2] -> [#stmt, s1, v, se, s],
splitVarStmt = t:s1 [#varStmt :vs_ ?(vs_.length > 1)] t:se t:s2 splitVarItems(s1, se, s2, vs_):vs -> {
vs[vs.length - 1] = KrasotaJS.match(
vs[vs.length - 1],
'splitVarStmtLast',
[s2]);
[#stmts].concat(vs)
},
stmt = splitVarStmt | ^stmt
}