-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.peg
36 lines (30 loc) · 927 Bytes
/
set.peg
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
{
var self = this;
function transformIdentifier(identifier, attribute) {
var param = self.name2param[identifier];
if(param) {
if(attribute) {
if(param.data.attributes.buffer && attribute == 'length') {
return 'node::Buffer::Length(args[' + param.nodeArgNum +'])';
}
}
return self.name2param[identifier].variable;
}
if(attribute)
return identifier + '.' + attribute;
return identifier;
}
}
start
= expression
expression = elements:(element:element _ {return element;})* {return elements.join(''); }
element = identifier_attribute / identifier:identifier {
return transformIdentifier(identifier);
} / [+-\\(\\)*/]
identifier_attribute = identifier:identifier _ '.' _ attribute:identifier {
return transformIdentifier(identifier, attribute);
}
identifier = char:[a-zA-Z_] chars:[a-zA-Z0-9_]* {
return char + chars.join('');
}
_ = [ \t\n]*