@@ -486,6 +486,14 @@ class Parser {
486
486
List <Token > tokens = Parser .lex (text);
487
487
Token token;
488
488
489
+ parserError (String s, [Token t]) {
490
+ if (t == null && ! tokens.isEmpty) t = tokens[0 ];
491
+ String location = t == null ?
492
+ 'the end of the expression' :
493
+ 'at column ${t .index + 1 } in' ;
494
+ return 'Parser Error: $s $location [$text ]' ;
495
+ }
496
+ evalError (String s) => 'Eval Error: $s while evaling [$text ]' ;
489
497
490
498
Token peekToken () {
491
499
if (tokens.length == 0 )
@@ -531,7 +539,7 @@ class Parser {
531
539
532
540
ParsedFn consume (e1){
533
541
if (expect (e1) == null ) {
534
- throw "not impl consume error" ;
542
+ throw parserError ( "Missing expected $ e1 " ) ;
535
543
//throwError("is unexpected, expecting [" + e1 + "]", peek());
536
544
}
537
545
}
@@ -553,8 +561,7 @@ class Parser {
553
561
Token token = expect ();
554
562
primary = token.primaryFn;
555
563
if (primary == null ) {
556
- throw "not impl error" ;
557
- //throwError("not a primary expression", token);
564
+ throw parserError ("Internal Angular Error: Unreachable code A." );
558
565
}
559
566
}
560
567
@@ -571,7 +578,7 @@ class Parser {
571
578
context = primary;
572
579
primary = fieldAccess (primary);
573
580
} else {
574
- throw "Impossible.. what?" ;
581
+ throw parserError ( "Internal Angular Error: Unreachable code B." ) ;
575
582
}
576
583
}
577
584
stopSavingTokens (ts);
@@ -662,14 +669,14 @@ class Parser {
662
669
// =========================
663
670
664
671
ParsedFn assignment () {
672
+ var ts = saveTokens ();
665
673
var left = logicalOR ();
674
+ stopSavingTokens (ts);
666
675
var right;
667
676
var token;
668
677
if ((token = expect ('=' )) != null ) {
669
678
if (! left.assignable) {
670
- throw "not impl bad assignment error" ;
671
- // throwError("implies assignment but [" +
672
- // text.substring(0, token.index) + "] can not be assigned to", token);
679
+ throw parserError ('Expression ${tokensText (ts )} is not assignable' , token);
673
680
}
674
681
right = logicalOR ();
675
682
return new ParsedFn ((scope, locals) =>
@@ -688,9 +695,9 @@ class Parser {
688
695
var left = expression ();
689
696
var token;
690
697
while (true ) {
691
- if ((token = expect ('|' ) != null ) ) {
698
+ if ((token = expect ('|' )) != null ) {
692
699
//left = binaryFn(left, token.fn, filter());
693
- throw "not impl filter" ;
700
+ throw parserError ( "Filters are not implemented" , token) ;
694
701
} else {
695
702
return left;
696
703
}
@@ -733,10 +740,10 @@ class Parser {
733
740
}
734
741
var userFn = fn (self, locals);
735
742
if (userFn == null ) {
736
- throw "Undefined function $fnName " ;
743
+ throw evalError ( "Undefined function $fnName " ) ;
737
744
}
738
745
if (userFn is ! Function ) {
739
- throw "$fnName is not a function" ;
746
+ throw evalError ( "$fnName is not a function" ) ;
740
747
}
741
748
return relaxFnApply (userFn, args);
742
749
});
@@ -768,7 +775,7 @@ class Parser {
768
775
} else if (o is Map ) {
769
776
return o[i.toString ()]; // toString dangerous?
770
777
}
771
- throw "not impl odd object access" ;
778
+ throw evalError ( "Attempted field access on a non-list, non-map" ) ;
772
779
}
773
780
774
781
setField (o, i, v) {
@@ -779,7 +786,7 @@ class Parser {
779
786
} else if (o is Map ) {
780
787
o[i.toString ()] = v; // toString dangerous?
781
788
} else {
782
- throw "not impl odd object access" ;
789
+ throw evalError ( "Attempting to set a field on a non-list, non-map" ) ;
783
790
}
784
791
return v;
785
792
}
@@ -791,7 +798,7 @@ class Parser {
791
798
var o = obj (self, locals),
792
799
v, p;
793
800
794
- if (o == null ) return throw "not impl null obj" ; // null
801
+ if (o == null ) return throw evalError ( 'Accessing null object' );
795
802
796
803
v = getField (o, i);
797
804
@@ -846,7 +853,7 @@ class Parser {
846
853
ParsedFn value = statements ();
847
854
848
855
if (tokens.length != 0 ) {
849
- throw "not impl, error msg $ tokens " ;
856
+ throw parserError ( "Unconsumed token ${ tokens [ 0 ]. text }" ) ;
850
857
}
851
858
return value;
852
859
}
0 commit comments