-
Notifications
You must be signed in to change notification settings - Fork 0
/
TelegramSyntaxCheck.js
152 lines (119 loc) · 5.4 KB
/
TelegramSyntaxCheck.js
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var Telegram = require('./Telegram.js');
function TelegramSyntaxCheck(telegObj, telegramPath) {
this.telegObj = telegObj;
this.telegramPath = telegramPath;
this.telegDict;
this.bufferVarDict = {};
this.setTelegDict.call(this, this.telegObj);
this.fillBufferVarDict.call(this, '');
};
TelegramSyntaxCheck.prototype.setTelegDict = function(telegObj){
// borrow this method without using Telegrams constructor
this.telegDict = Telegram.prototype.createTelegramDict(telegObj);
}
TelegramSyntaxCheck.prototype.fillBufferVarDict = function(){
var that = this;
this.telegDict.forEach(function(telegLine, index) {
if ( telegLine.value.isTelegramVariable() ) {
plainVarName = telegLine.value.getPlainVariableName();
if ( plainVarName.isBufferVariable() ) {
that.bufferVarDict[plainVarName] = 1;
}
}
});
}
TelegramSyntaxCheck.prototype.checkBufferKeys = function(bufferKeyVal){
var plainVarName;
if ( this.hasBufferVars() ) {
if ( bufferKeyVal === null ) {
throw 'The telegram "' this.telegramPath
'" contains buffer variables. However, the global "bufferKey" parameter is not defined.\n';
}
if ( ! this.bufferVarDict[ bufferKeyVal.getPlainVariableName() ] ) {
throw 'The global buffer key "' bufferKeyVal '" can not be found in the buffer variables of telegram "' this.telegramPath '".\n';
}
}
}
TelegramSyntaxCheck.prototype.hasBufferVars = function (){
if ( ! isEmptyObject(this.bufferVarDict) ) {
return true;
}
return false;
}
/*
* See if teleg offset and length definition are matching
* @class Telegram
* @method checkDefinition
*/
TelegramSyntaxCheck.prototype.checkDefinition = function (){
var nextExpectedOffset,
telegLine,
index,
that = this;
this.telegDict.forEach(function(telegLine, index) {
if ( telegLine.offset !== 1 && telegLine.offset !== nextExpectedOffset ) {
throw "Error in the defintion of telegram \"" that.telegramPath
"\". The telegram offset and length definition is wrong. \ Error is around line '" index "'.";
}
else {
nextExpectedOffset = telegLine.offset telegLine.length;
}
})
}
//~ telegVariablesSizeDict : varName
//~ - length: 12
//~ - telegFound: telegname
TelegramSyntaxCheck.prototype.checkVariablesSizes = function (telegVariablesSizeDict){
var that = this,
currentVal,
plainVariableName;
this.telegDict.forEach(function(telegLine, index) {
currentVal = telegLine.value;
if ( currentVal.isTelegramVariable() ) {
plainVariableName = currentVal.getPlainVariableName();
if ( ! plainVariableName.isRipleyInternalVariable() ) {
if ( telegVariablesSizeDict[currentVal] &&
telegVariablesSizeDict[currentVal]["length"] !== telegLine.length ) {
throw 'Telegram "' that.telegramPath '" has variable "' currentVal '" defined with a length of ' telegLine.length '. '
'However, telegram "' telegVariablesSizeDict[currentVal]["telegFound"]
'" defines the same variable with a length of ' telegVariablesSizeDict[currentVal]["length"] '.\n';
}
else {
// init object
if ( ! telegVariablesSizeDict[currentVal] ) {
telegVariablesSizeDict[currentVal] = {};
}
telegVariablesSizeDict[currentVal]["length"] = telegLine.length;
telegVariablesSizeDict[currentVal]["telegFound"] = that.telegramPath;
}
}
}
});
}
TelegramSyntaxCheck.prototype.checkRipleyInternalVariablesSize = function (configObj){
var that = this,
ripleyInternalVarValue,
plainVariableName;
this.telegDict.forEach(function(telegLine, index) {
currentVal = telegLine.value;
if ( currentVal.isTelegramVariable() ) {
plainVariableName = currentVal.getPlainVariableName();
if ( plainVariableName.isRipleyInternalVariable() ) {
ripleyInternalVarValue = Telegram.prototype.getRipleyInternalVariableValue(plainVariableName, configObj);
if ( ripleyInternalVarValue === null ) {
throw 'The Ripley internal variable "' currentVal '" of telegram "' that.telegramPath '" is not supported.\n';
}
else if ( telegLine.length !== ripleyInternalVarValue.length ) {
throw 'The Ripley internal variable "' currentVal '" of telegram "' that.telegramPath
'" has a configured length of ' telegLine.length '. The actual content is "' ripleyInternalVarValue
'" with a length of ' ripleyInternalVarValue.length '. Please adjust this.\n';
}
}
}
});
}
TelegramSyntaxCheck.prototype.getTelegramPath = function (){
return this.telegramPath;
}
// node.js module export
module.exports = TelegramSyntaxCheck;