Statement.js
2.64 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
Loader.require('Logger');
Parser.Statement = Ext.extend(Object, {
isInverted: false,
properties: {},
buffer: '',
parent: null,
constructor: function(properties, isInverted) {
if (properties === undefined) {
properties = {};
}
if (isInverted === undefined) {
isInverted = false;
}
this.properties = properties;
this.isInverted = isInverted;
},
setProperty: function(name, value) {
this.properties[name] = value;
},
getProperty: function(name) {
return this.properties.hasOwnProperty(name) ? this.properties[name] : null;
},
removeProperty: function(name) {
delete this.properties[name];
},
isEnd: function(line, stream) {
return Parser.isCloseOf(line, this);
},
pushBuffer: function(content, withNewLine) {
if (withNewLine === undefined) {
withNewLine = false;
}
this.buffer += content + ((withNewLine) ? "\n" : "");
},
resetBuffer: function() {
this.buffer = '';
},
parse: function(stream) {
var line, subStatementData, subStatement;
while (!stream.eof) {
line = stream.readLine();
if (this.isEnd(line, stream)) {
break;
}
if ((subStatementData = Parser.parseStatement(line)) && (subStatement = Parser.Statement.factory(subStatementData))) {
subStatement.parent = this;
this.onSubStatement(subStatement, stream);
} else {
this.pushBuffer(line, !stream.eof);
}
}
return this.buffer;
},
onSubStatement: function(statement, stream) {
this.pushBuffer(statement.parse(stream));
}
});
Ext.apply(Parser.Statement, {
factory: function(type, properties, isInverted) {
var capitalizedType, statementClass, statement;
if (Ext.isObject(type)) {
properties = type.properties;
isInverted = type.isInverted;
type = type.type;
}
type = type.toLowerCase();
capitalizedType = type.charAt(0).toUpperCase() + type.slice(1);
Loader.require('Parser.Statement.' + capitalizedType, false);
statementClass = Parser.Statement[capitalizedType];
if (!statementClass) {
// Not supported
Logger.log("[NOTICE][Parser.Statement.factory] Statement type '" + type + "' is currently not supported, ignored");
return false;
}
statement = new statementClass(properties, isInverted);
statement.type = type;
return statement;
}
});