comparison parser/Parser.d @ 189:75d0544ddc45

Better error handling on unexpected EOF.
author Anders Johnsen <skabet@gmail.com>
date Fri, 25 Jul 2008 13:50:01 +0200
parents 7b274cfdc1dc
children 85e492318bb6
comparison
equal deleted inserted replaced
188:b3e0729c8524 189:75d0544ddc45
110 case Tok.OpenParentheses: 110 case Tok.OpenParentheses:
111 return parseFunc(type, iden, att); 111 return parseFunc(type, iden, att);
112 112
113 default: 113 default:
114 auto n1 = next(); 114 auto n1 = next();
115 messages.report(UnexpectedTok, n1.location).arg(n1.getType); 115 isEOF(type.tok);
116 return null; 116 messages.report(UnexpectedTok, n1.location).arg(n1.get(sm));
117 return action.actOnDeclarator(type, iden, null, att);
117 } 118 }
118 messages.report(InvalidDeclType, peek.location) 119 messages.report(InvalidDeclType, peek.location)
119 .arg(sm.getText(peek.asRange)); 120 .arg(sm.getText(peek.asRange));
120 121
121 default: 122 default:
126 .arg(sm.getText(peek.asRange)); 127 .arg(sm.getText(peek.asRange));
127 128
128 return null; 129 return null;
129 } 130 }
130 messages.report(UnexpectedTok, peek.location) 131 messages.report(UnexpectedTok, peek.location)
131 .arg(peek.getType) 132 .arg(peek.get(sm))
132 .arg(Tok.Identifier) 133 .arg(Tok.Identifier)
133 .fatal(ExitLevel.Parser); 134 .fatal(ExitLevel.Parser);
134 } 135 }
135 136
136 Extern parseLinkageType() 137 Extern parseLinkageType()
690 691
691 default: 692 default:
692 if (peek.isBasicType) 693 if (peek.isBasicType)
693 goto case Tok.Void; 694 goto case Tok.Void;
694 695
695 messages.report(UnexpectedBeginStmt, peek.location).arg(peek.getType); 696 messages.report(UnexpectedBeginStmt, peek.location).arg(peek.get(sm));
696 require(Tok.Seperator); 697 require(Tok.Seperator);
697 return null; 698 return null;
698 } 699 }
699 } 700 }
700 701
788 789
789 if (tok.type is Tok.Identifier) 790 if (tok.type is Tok.Identifier)
790 return Id(tok); 791 return Id(tok);
791 792
792 messages.report(UnexpectedTokSingle, tok.location) 793 messages.report(UnexpectedTokSingle, tok.location)
793 .arg(tok.getType) 794 .arg(tok.get(sm))
794 .arg(Tok.Identifier); 795 .arg(Tok.Identifier);
795 } 796 }
796 797
797 ModuleName parseModuleName() 798 ModuleName parseModuleName()
798 { 799 {
1126 1127
1127 private: 1128 private:
1128 1129
1129 Token require(Tok t) 1130 Token require(Tok t)
1130 { 1131 {
1131 if (peek().type != t) 1132 if (!isa(t))
1132 messages.report(UnexpectedTokSingle, peek.location) 1133 if(isa(Tok.EOF))
1133 .arg(peek.getType) 1134 messages.report(UnexpectedEOF,
1134 .arg(t); 1135 [lexer.last.asRange][], [])
1136 .arg(lexer.last.get(sm))
1137 .fatal(ExitLevel.Parser);
1138 else
1139 messages.report(UnexpectedTokSingle, peek.location)
1140 .arg(peek.get(sm))
1141 .arg(typeToString[t]);
1135 return next(); 1142 return next();
1136 } 1143 }
1137 1144
1138 bool skip(Tok t) 1145 bool skip(Tok t)
1139 { 1146 {
1146 bool isa(Tok t, int i = 0) 1153 bool isa(Tok t, int i = 0)
1147 { 1154 {
1148 return peek(i).type == t; 1155 return peek(i).type == t;
1149 } 1156 }
1150 1157
1158 bool isEOF(Token t)
1159 {
1160 if (isa(Tok.EOF))
1161 messages.report(UnexpectedEOF,
1162 [t.asRange][], [])
1163 .arg(t.get(sm))
1164 .fatal(ExitLevel.Parser);
1165 return false;
1166 }
1167
1151 Token next() 1168 Token next()
1152 { 1169 {
1153 return lexer.next; 1170 return lexer.next;
1154 } 1171 }
1155 1172