-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproperties-parser.js
More file actions
126 lines (97 loc) · 4.77 KB
/
Copy pathproperties-parser.js
File metadata and controls
126 lines (97 loc) · 4.77 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
PropertiesParser = function(){
var sanitizer = require('./code-sanitizer');
var variablesParser = require('./variables-parser');
this.parse = function(data, entry){
// Strip out any GET/LET statements
var regEx = /(((?!'(?:\n))(?:\s*'.*?(?:\n))*)\n\s*((public|private)?\s*(?:default\s+)?property\s+(get|let|set)\s+(\w+)\s*(?:\((\w*)\)){0,1})([\s\S]*?)(?:end\s+(?:property)))/gi;
var remainingData = data;
var classProperties = {};
while (( match = regEx.exec(data) ) != null) {
var codeBlock = match[0];
remainingData = remainingData.replace(codeBlock, function(){
return '';
});
var visibility = match[4];
if (visibility === undefined)
visibility = "Public";
var property =
{
'comments' : ( match[2] != undefined ? match[2].replace(/\n\n/gi,'\n').replace(/^'/gm, '').split('\n') : undefined ),
'visibility' : visibility,
'type' : match[5].toLowerCase(), // get or let
'name' : match[6],
'code' : sanitizer.clean(match[8]),
'function' : { 'name' : match[6] }
};
property['function']['class'] = entry.class;
var result = variablesParser.parse( property.code, false, false, entry );
property['vars'] = result.vars;
if ( classProperties[property.name] === undefined )
classProperties[property.name] = {
'function' : { 'name' : property.name },
'var' : property.name,
'name' : property.name
};
if ( property.type === 'set' )
property.type == 'let';
// Lets try and find a variable which is assigned so we can match it up with a DIM in the class
if ( property.type === 'get' ){
var regEx2 = new RegExp('\\s*\\b' + property.name + '\\b\\s*=\\s*(?:\\w*\\()?\\s*(\\w+)\\s*\\)?\\s*', 'gi');
while (( match = regEx2.exec(property.code) ) != null) {
var theVar = match[1].trim();
if ( classProperties[property.name]['_Variable'] === undefined ){
remainingData = remainingData.replace( new RegExp('\\s*((private|public)(?:\\s*dim)?\\s+\\b' + theVar + '\\b)[\\t\\f]*(\'.*)?', 'gi' ), function( m, p1, p2, p3 ){
classProperties[property.name]['_Variable'] =
{
'name' : theVar,
'visibility' : p2,
'comment' : p3 !== undefined ? p3.replace(/^'/gm, '').split('\n') : undefined
};
return m;
});
}
}
}
if ( property.type === 'let' ){
var setParam = match[7];
property['setParam'] = setParam;
var regEx2 = new RegExp('\\s*(\\w+)\\b\\s*=\\s*(?:\\w*\\()?\\s*' + setParam + '\\s*\\)?\\s*', 'gi');
while (( match = regEx2.exec(property.code) ) != null) {
var theVar = match[1].trim();
if ( classProperties[property.name]['_Variable'] === undefined ){
remainingData = remainingData.replace( new RegExp('\\s*((private|public)(?:\\s*dim)?\\s+\\b' + theVar + '\\b)[\\t\\f]*(\'.*)?', 'gi' ), function( m, p1, p2, p3 ){
classProperties[property.name]['_Variable'] =
{
'name' : theVar,
'visibility' : p2,
'comment' : p3 !== undefined ? p3.replace(/^'/gm, '').split('\n') : undefined
};
return m;
});
}
}
}
classProperties[property.name][property.type] = property;
//codeBlock = codeBlock.trim();
//totalRemoved += codeBlock.length();
/*
remainingData = remainingData.substr( match.index.toExponential()
remainingData = remainingData.replace(codeBlock, function(m){
return '';
});
*/
}
classProperties.forEach = function (f){
for( var name in this ) {
if ( typeof this[name] === 'function' )
continue;
f( this[name], name );
}
};
return {
'properties' : classProperties,
'data' : remainingData.replace(/\n\n/gi, '\n').trim()
}
}
}
exports = module.exports = new PropertiesParser();