bug fixed

This commit is contained in:
ValKmjolnir 2021-12-25 15:56:08 +08:00
parent 1923fc74e4
commit 70a43c2f03
3 changed files with 21 additions and 3 deletions

View File

@ -48,11 +48,16 @@ public:
void err(const char* stage,const std::string& info)
{
++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)
{
++error;
if(!line)
{
err(stage,info);
return;
}
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<":"<<column<<" "<<info<<"\n"<<res[line-1]<<'\n';
for(int i=0;i<(int)column-1;++i)
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)
{
++error;
if(!line)
{
err(stage,info);
return;
}
std::cout<<"["<<stage<<"] "<<file<<":"<<line<<" "<<info<<"\n"<<res[line-1]<<'\n';
}
void chkerr(){if(error)std::exit(1);}

View File

@ -294,9 +294,15 @@ void nasal_lexer::scan(const std::string& file)
tokens.push_back({line,column,type?type:tok_id,str});
}
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]))
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]))
{
str=res[ptr];

View File

@ -124,6 +124,8 @@ void nasal_parse::compile(const nasal_lexer& lexer)
void nasal_parse::die(uint32_t line,const std::string& info)
{
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);
}
void nasal_parse::match(uint32_t type,const char* info)