bug fixed
This commit is contained in:
parent
1923fc74e4
commit
70a43c2f03
12
nasal_err.h
12
nasal_err.h
|
@ -48,11 +48,16 @@ public:
|
||||||
void err(const char* stage,const std::string& info)
|
void err(const char* stage,const std::string& info)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<"["<<stage<<"] "<<info<<'\n';
|
std::cout<<"["<<stage<<"] "<<file<<": "<<info<<'\n';
|
||||||
}
|
}
|
||||||
void err(const char* stage,uint32_t line,uint32_t column,const std::string& info)
|
void err(const char* stage,uint32_t line,uint32_t column,const std::string& info)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
|
if(!line)
|
||||||
|
{
|
||||||
|
err(stage,info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<":"<<column<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<":"<<column<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
||||||
for(int i=0;i<(int)column-1;++i)
|
for(int i=0;i<(int)column-1;++i)
|
||||||
std::cout<<char(" \t"[res[line-1][i]=='\t']);
|
std::cout<<char(" \t"[res[line-1][i]=='\t']);
|
||||||
|
@ -61,6 +66,11 @@ public:
|
||||||
void err(const char* stage,uint32_t line,const std::string& info)
|
void err(const char* stage,uint32_t line,const std::string& info)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
|
if(!line)
|
||||||
|
{
|
||||||
|
err(stage,info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
||||||
}
|
}
|
||||||
void chkerr(){if(error)std::exit(1);}
|
void chkerr(){if(error)std::exit(1);}
|
||||||
|
|
|
@ -294,9 +294,15 @@ void nasal_lexer::scan(const std::string& file)
|
||||||
tokens.push_back({line,column,type?type:tok_id,str});
|
tokens.push_back({line,column,type?type:tok_id,str});
|
||||||
}
|
}
|
||||||
else if(DIGIT(res[ptr]))
|
else if(DIGIT(res[ptr]))
|
||||||
tokens.push_back({line,column,tok_num,num_gen()});
|
{
|
||||||
|
str=num_gen(); // make sure column is correct
|
||||||
|
tokens.push_back({line,column,tok_num,str});
|
||||||
|
}
|
||||||
else if(STR(res[ptr]))
|
else if(STR(res[ptr]))
|
||||||
tokens.push_back({line,column,tok_str,str_gen()});
|
{
|
||||||
|
str=str_gen(); // make sure column is correct
|
||||||
|
tokens.push_back({line,column,tok_str,str});
|
||||||
|
}
|
||||||
else if(SINGLE_OPERATOR(res[ptr]))
|
else if(SINGLE_OPERATOR(res[ptr]))
|
||||||
{
|
{
|
||||||
str=res[ptr];
|
str=res[ptr];
|
||||||
|
|
|
@ -124,6 +124,8 @@ void nasal_parse::compile(const nasal_lexer& lexer)
|
||||||
void nasal_parse::die(uint32_t line,const std::string& info)
|
void nasal_parse::die(uint32_t line,const std::string& info)
|
||||||
{
|
{
|
||||||
int col=(int)tokens[ptr].column-(int)tokens[ptr].str.length();
|
int col=(int)tokens[ptr].column-(int)tokens[ptr].str.length();
|
||||||
|
if(tokens[ptr].type==tok_str)
|
||||||
|
col-=2; // tok_str's str has no \"
|
||||||
nerr.err("parse",line,col<0?0:col,info);
|
nerr.err("parse",line,col<0?0:col,info);
|
||||||
}
|
}
|
||||||
void nasal_parse::match(uint32_t type,const char* info)
|
void nasal_parse::match(uint32_t type,const char* info)
|
||||||
|
|
Loading…
Reference in New Issue