-
Notifications
You must be signed in to change notification settings - Fork 4
/
grammer.pegjs
58 lines (39 loc) · 2.02 KB
/
grammer.pegjs
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
File
= head:Expression tail:(Expression)* {
return tail.reduce(function(result, element){
return result + element;
}
,head);
}
Expression
= _ exp:(JSExpression / OTExpression / NLine / Comment) _ {return exp;}
JSExpression
= "<%" code:JSCode "%>" {return code;}
OTExpression
= left:OTLExpression _ "=" _ right:OTRExpression { return left + " = " + right + ";\n";}
/ right:OTRExpression {return right+";";}
OTLExpression
= "$" [a-zA-Z]+ {return "var " + text().replace("$", "")}
OTRExpression
= OTCreate/OTOpen/OTAuth/OTSet/OTGet/OTDelete/OTSubNodes/OTVariable
OTSubNodes = "subnodes" url:[ \t,+a-zA-Z0-9$\/:\.\\'_"]* {return "_OTCommands.get_sub_nodes("+url.join('').trim()+")";}
OTVariable = "$" [a-zA-Z]+ {return text().replace("$", "") }
/ [a-zA-Z0-9]+ {return text()}
OTDelete = "delete" url:[ \t,+a-zA-Z0-9$\/:\.\\'_"]* {return "_OTCommands.delete_by_id("+url.join('').trim()+")";}
OTGet = "get" url:[ \t,+a-zA-Z0-9$\/:\.\\'_"]* {return "_OTCommands.get_node_by_path("+url.join('')+")";}
OTSet = "set" _ obj:("category"/"permission") _ url:[ \t,+a-zA-Z0-9$\/:\.\\'"]+ {return "_OTCommands.set_"+obj+ "("+url.join('')+")";}
OTOpen
= "open" _ obj:("folder"/"file") _ url:[a-zA-Z0-9\/:\.]* {return "open_"+obj+"(__session, '"+url.join('')+"')";}
OTCreate
= "create" _ obj:("folder"/"document"/"category") _ url:[ \t,+a-zA-Z0-9$\/:\.\\'_"]* {return (obj == "document")?"_OTCommands.create_"+obj+"(" +url.join('').replace("$","")+")": (obj == "category")? "_OTCommands.create_"+obj+"(" +url.join('')+")": "_OTCommands.create"+"('"+obj +"'," +url.join('')+")";}
OTAuth
= "auth" _ uname:[^ \t]+ _ password:[^ \t\r\n]+ { return "__OTVARIABLES['token'] = _OTCommands.auth('"+uname.join('')+"', '"+password.join('')+"');"
+"\n__OTVARIABLES['xmltoken'] = _OTCommands.auth('"+uname.join('')+"', '"+password.join('')+"', 'xml')" }
JSCode
= [^%]* { return text();}
_ "whitespace"
= [ \t]* {return "";}
NLine
= [\r\n]+ {return "\n";}
Comment
= "//" [^\n]* { return text();}