@@ -106,12 +106,14 @@ Parser.prototype.read = function (input, n) {
106
106
const type = typeValue [ 1 ]
107
107
if ( ! / ^ [ a - z A - Z 0 - 9 ] + $ / . test ( name ) ) {
108
108
throw new ParseError ( 'InvalidVariable' , {
109
- variable : name
109
+ variable : name ,
110
+ line : this . getLineNumber ( )
110
111
} )
111
112
}
112
113
if ( ! type ) {
113
114
throw new ParseError ( 'MissingType' , {
114
- variable : name
115
+ variable : name ,
116
+ line : this . getLineNumber ( )
115
117
} )
116
118
}
117
119
const nType = new Node ( type , n )
@@ -125,12 +127,14 @@ Parser.prototype.read = function (input, n) {
125
127
} else if ( type === 'word' || type === 'string' ) {
126
128
throw new ParseError ( 'MissingLength' , {
127
129
variable : name ,
128
- type : type
130
+ type : type ,
131
+ line : this . getLineNumber ( )
129
132
} )
130
133
} else if ( this . allowType . indexOf ( type ) < 0 ) {
131
134
throw new ParseError ( 'InvalidType' , {
132
135
variable : name ,
133
- type : type
136
+ type : type ,
137
+ line : this . getLineNumber ( )
134
138
} )
135
139
}
136
140
@@ -155,7 +159,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
155
159
156
160
if ( typeof param !== 'undefined' ) {
157
161
throw new ParseError ( 'InvalidKeyword' , {
158
- param : cmd + ':' + param
162
+ param : cmd + ':' + param ,
163
+ line : this . getLineNumber ( )
159
164
} )
160
165
}
161
166
@@ -300,7 +305,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
300
305
}
301
306
default :
302
307
throw new ParseError ( 'InvalidKeyword' , {
303
- param : cmd
308
+ param : cmd ,
309
+ line : this . getLineNumber ( )
304
310
} )
305
311
}
306
312
}
@@ -336,5 +342,8 @@ Parser.prototype.extractParam = function (type) {
336
342
const iclose = type . indexOf ( ')' )
337
343
return type . substring ( iopen + 1 , iclose )
338
344
}
345
+ Parser . prototype . getLineNumber = function ( ) {
346
+ return this . code . substring ( 0 , this . cursor - 1 ) . split ( '' ) . filter ( r => r === '\n' ) . length + 1
347
+ }
339
348
340
349
export default Parser
0 commit comments