@@ -45,9 +45,8 @@ function getEntryOrJunk(ps) {
4545 throw err ;
4646 }
4747
48- const annot = new AST . Annotation (
49- 'ParseError' , err . message , ps . getIndex ( )
50- ) ;
48+ const annot = new AST . Annotation ( err . code , err . message ) ;
49+ annot . addSpan ( ps . getIndex ( ) , ps . getIndex ( ) ) ;
5150
5251 ps . skipToNextEntryStart ( ) ;
5352 const nextEntryStart = ps . getIndex ( ) ;
@@ -79,7 +78,7 @@ function getEntry(ps) {
7978 if ( comment ) {
8079 return comment ;
8180 }
82- throw new ParseError ( 'Expected entry ' ) ;
81+ throw new ParseError ( 'E0002 ' ) ;
8382}
8483
8584function getComment ( ps ) {
@@ -151,13 +150,13 @@ function getMessage(ps, comment) {
151150
152151 if ( ps . isPeekNextLineTagStart ( ) ) {
153152 if ( attrs !== undefined ) {
154- throw new ParseError ( 'Tags cannot be added to messages with attributes ' ) ;
153+ throw new ParseError ( 'E0012 ' ) ;
155154 }
156155 tags = getTags ( ps ) ;
157156 }
158157
159158 if ( pattern === undefined && attrs === undefined && tags === undefined ) {
160- throw new ParseError ( 'Missing field' ) ;
159+ throw new ParseError ( 'E0005' , id , [ 'value' , 'attributes' , 'tags' ] ) ;
161160 }
162161
163162 return new AST . Message ( id , pattern , attrs , tags , comment ) ;
@@ -183,7 +182,7 @@ function getAttributes(ps) {
183182 const value = getPattern ( ps ) ;
184183
185184 if ( value === undefined ) {
186- throw new ParseError ( 'Expected field ' ) ;
185+ throw new ParseError ( 'E0006' , 'value ') ;
187186 }
188187
189188 attrs . push ( new AST . Attribute ( key , value ) ) ;
@@ -232,7 +231,7 @@ function getVariantKey(ps) {
232231 const ch = ps . current ( ) ;
233232
234233 if ( ! ch ) {
235- throw new ParseError ( 'Expected VariantKey ' ) ;
234+ throw new ParseError ( 'E0013 ' ) ;
236235 }
237236
238237 const cc = ch . charCodeAt ( 0 ) ;
@@ -271,7 +270,7 @@ function getVariants(ps) {
271270 const value = getPattern ( ps ) ;
272271
273272 if ( ! value ) {
274- throw new ParseError ( 'Expected field ' ) ;
273+ throw new ParseError ( 'E0006' , 'value ') ;
275274 }
276275
277276 variants . push ( new AST . Variant ( key , value , defaultIndex ) ) ;
@@ -282,7 +281,7 @@ function getVariants(ps) {
282281 }
283282
284283 if ( ! hasDefault ) {
285- throw new ParseError ( 'Missing default variant ' ) ;
284+ throw new ParseError ( 'E0010 ' ) ;
286285 }
287286
288287 return variants ;
@@ -314,7 +313,7 @@ function getDigits(ps) {
314313 }
315314
316315 if ( num . length === 0 ) {
317- throw new ParseError ( 'Expected char range ' ) ;
316+ throw new ParseError ( 'E0004' , '0-9 ') ;
318317 }
319318
320319 return num ;
@@ -432,7 +431,7 @@ function getExpression(ps) {
432431 const variants = getVariants ( ps ) ;
433432
434433 if ( variants . length === 0 ) {
435- throw new ParseError ( 'Missing variants ' ) ;
434+ throw new ParseError ( 'E0011 ' ) ;
436435 }
437436
438437 ps . expectChar ( '\n' ) ;
@@ -501,7 +500,7 @@ function getCallArgs(ps) {
501500
502501 if ( ps . current ( ) === ':' ) {
503502 if ( exp . type !== 'MessageReference' ) {
504- throw new ParseError ( 'Forbidden key ' ) ;
503+ throw new ParseError ( 'E0009 ' ) ;
505504 }
506505
507506 ps . next ( ) ;
@@ -533,7 +532,7 @@ function getArgVal(ps) {
533532 } else if ( ps . currentIs ( '"' ) ) {
534533 return getString ( ps ) ;
535534 }
536- throw new ParseError ( 'Expected field ' ) ;
535+ throw new ParseError ( 'E0006' , 'value ') ;
537536}
538537
539538function getString ( ps ) {
@@ -556,7 +555,7 @@ function getLiteral(ps) {
556555 const ch = ps . current ( ) ;
557556
558557 if ( ! ch ) {
559- throw new ParseError ( 'Expected literal ' ) ;
558+ throw new ParseError ( 'E0014 ' ) ;
560559 }
561560
562561 if ( ps . isNumberStart ( ) ) {
0 commit comments