ide: Parser Lex now throws instead of ASSERTs

git-svn-id: svn://ultimatepp.org/upp/trunk@5353 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-09-13 11:47:59 +00:00
parent 737f747a57
commit c5974ca894
2 changed files with 24 additions and 6 deletions

View file

@ -104,8 +104,11 @@ class Lex {
void Next();
bool Prepare(int pos);
int GetCharacter();
void ThrowError(const char *e);
public:
Callback1<const String&> WhenError;
struct Grounding {};
int Code(int pos = 0);
@ -392,6 +395,10 @@ class Parser {
void Statement();
void Locals(const String& type);
String Tparam(int& q);
friend class Lex; // Fix to make Lex::ThrowError
typedef Parser CLASSNAME;
public:
struct FunctionStat
@ -432,7 +439,7 @@ public:
void Do(Stream& s, const Vector<String>& ignore, CppBase& base, const String& fn,
Callback2<int, const String&> err, const Vector<String>& typenames = Vector<String>());
Parser() : dobody(false) {}
Parser() : dobody(false) { lex.WhenError = THISBACK(ThrowError); }
};
String NoTemplatePars(const String& type);

View file

@ -361,9 +361,16 @@ bool Lex::IsId(int pos)
return Code(pos) >= endkey + 256;
}
void Lex::ThrowError(const char *e)
{
WhenError(e);
throw Parser::Error();
}
String Lex::Id(int pos)
{
ASSERT(IsId(pos));
if(!IsId(pos))
ThrowError("expected id");
return id[Code(pos) - 256];
}
@ -414,28 +421,32 @@ void Lex::SkipToGrounding()
int Lex::Int(int pos)
{
Prepare(pos);
ASSERT(term[pos].code == t_integer);
if(term[pos].code != t_integer)
ThrowError("expected integer literal");
return (int)term[pos].number;
}
double Lex::Double(int pos)
{
Prepare(pos);
ASSERT(term[pos].code == t_double);
if(term[pos].code != t_double)
ThrowError("expected floating point literal");
return term[pos].number;
}
String Lex::Text(int pos)
{
Prepare(pos);
ASSERT(term[pos].code == t_string);
if(term[pos].code != t_string)
ThrowError("expected string literal");
return term[pos].text;
}
int Lex::Chr(int pos)
{
Prepare(pos);
ASSERT(term[pos].code == t_character);
if(term[pos].code != t_character)
ThrowError("expected character literal");
return (byte)*term[pos].text;
}