forked from karimomaya/OTCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammer.pegjs
50 lines (35 loc) · 1.53 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
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/OTVariable
OTVariable = "$" [a-zA-Z]+ {return text().replace("$", "") }
/ [a-zA-Z0-9]+ {return text()}
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 "_OTCommands.auth('"+uname.join('')+"', '"+password.join('')+"')" }
JSCode
= [^%]* { return text();}
_ "whitespace"
= [ \t]* {return "";}
NLine
= [\r\n]+ {return "\n";}
Comment
= "//" [^\n]* { return text();}