1
1
const OCCURENCE_TOKEN = '@>'
2
2
3
3
function ParseError ( name , params ) {
4
+ this . message = name + ': ' + JSON . stringify ( params )
4
5
this . name = name
5
6
this . params = params
6
7
}
@@ -106,12 +107,14 @@ Parser.prototype.read = function (input, n) {
106
107
const type = typeValue [ 1 ]
107
108
if ( ! / ^ [ a - z A - Z 0 - 9 ] + $ / . test ( name ) ) {
108
109
throw new ParseError ( 'InvalidVariable' , {
109
- variable : name
110
+ variable : name ,
111
+ line : this . getLineNumber ( )
110
112
} )
111
113
}
112
114
if ( ! type ) {
113
115
throw new ParseError ( 'MissingType' , {
114
- variable : name
116
+ variable : name ,
117
+ line : this . getLineNumber ( )
115
118
} )
116
119
}
117
120
const nType = new Node ( type , n )
@@ -125,12 +128,14 @@ Parser.prototype.read = function (input, n) {
125
128
} else if ( type === 'word' || type === 'string' ) {
126
129
throw new ParseError ( 'MissingLength' , {
127
130
variable : name ,
128
- type : type
131
+ type : type ,
132
+ line : this . getLineNumber ( )
129
133
} )
130
134
} else if ( this . allowType . indexOf ( type ) < 0 ) {
131
135
throw new ParseError ( 'InvalidType' , {
132
136
variable : name ,
133
- type : type
137
+ type : type ,
138
+ line : this . getLineNumber ( )
134
139
} )
135
140
}
136
141
@@ -155,7 +160,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
155
160
156
161
if ( typeof param !== 'undefined' ) {
157
162
throw new ParseError ( 'InvalidKeyword' , {
158
- param : cmd + ':' + param
163
+ param : cmd + ':' + param ,
164
+ line : this . getLineNumber ( )
159
165
} )
160
166
}
161
167
@@ -214,10 +220,10 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
214
220
const name = vari . trim ( )
215
221
match = name . match ( / " ( .* ) " / )
216
222
if ( match ) {
217
- return { type : 'CONST' , value : match [ 1 ] }
223
+ return { type : 'CONST' , value : match [ 1 ] }
218
224
} else {
219
225
const codeName = parser . getFirstCodeName ( input . vars , name )
220
- return { type : 'VAR' , node : input . getVar ( codeName ) }
226
+ return { type : 'VAR' , node : input . getVar ( codeName ) }
221
227
}
222
228
} )
223
229
write . param . separator = separator
@@ -300,7 +306,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
300
306
}
301
307
default :
302
308
throw new ParseError ( 'InvalidKeyword' , {
303
- param : cmd
309
+ param : cmd ,
310
+ line : this . getLineNumber ( )
304
311
} )
305
312
}
306
313
}
@@ -336,5 +343,8 @@ Parser.prototype.extractParam = function (type) {
336
343
const iclose = type . indexOf ( ')' )
337
344
return type . substring ( iopen + 1 , iclose )
338
345
}
346
+ Parser . prototype . getLineNumber = function ( ) {
347
+ return this . code . substring ( 0 , this . cursor - 1 ) . split ( '\n' ) . length
348
+ }
339
349
340
350
export default Parser
0 commit comments