shell: exhaust parser after parsing error

This commit is contained in:
Lephenixnoir 2022-04-18 11:11:01 +01:00
parent 707c154f00
commit e0783c2348
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 20 additions and 10 deletions

View File

@ -35,8 +35,10 @@ static _e_args parse_e(Session &session, Parser &parser)
if(space)
while(!parser.at_end())
args.values.push_back(parser.expr(space));
else
else {
FxOS_log(ERR, "virtual space '%s' does not exist", args.space_name);
parser.exhaust();
}
// TODO: Error message when session specified in _e does not exist

View File

@ -12,7 +12,8 @@ static FxOS::Symbol parse_ms(Session &session, Parser &parser)
if(parser.lookahead().type == T::SYSCALL) {
s.type = FxOS::Symbol::Syscall;
s.value = parser.expect(T::SYSCALL).value.NUM;
} else {
}
else {
s.type = FxOS::Symbol::Address;
s.value = parser.expr(session.current_space);
}

View File

@ -2,6 +2,7 @@
#include "errors.h"
#include <stdexcept>
#include <fmt/core.h>
#include <fxos/util/log.h>
//---
// Lexing tools
@ -99,10 +100,6 @@ Token Parser::lookahead() const
bool Parser::at_end() const
{
/* When parsing to complete we try to go infinitely far, so we ignore
T::END. We supply T::SEPARATOR to complete the compound commands */
if(m_complete)
return (m_la.type == T::SEPARATOR);
return (m_la.type == T::SEPARATOR || m_la.type == T::END);
}
@ -113,6 +110,12 @@ void Parser::end()
throw SyntaxError("expected end of command");
}
void Parser::exhaust()
{
while(!at_end())
feed();
}
void Parser::skip_separators()
{
while(m_la.type == T::SEPARATOR)
@ -282,11 +285,13 @@ void Parser::accept_options()
std::string name = opt.substr(0, opt.find('='));
if(!m_options.count(name)) {
throw CommandError("unrecognized option {}", name);
if(!m_complete)
FxOS_log(ERR, "unrecognized option %s", name);
}
else {
std::string value = opt.substr(opt.find('=') + 1);
m_options[name](value);
}
std::string value = opt.substr(opt.find('=') + 1);
m_options[name](value);
}
}

View File

@ -115,6 +115,8 @@ public:
Token lookahead() const;
/* Require that command is finished */
void end();
/* Exhaust all input (usually after encountering an error) */
void exhaust();
/* Expect a token of this type, or of any of the listed types */
Token expect(T type, bool ignore_spaces=true);