added skip parser for skipping faulty lines

actorid
Marc Zinnschlag 15 years ago
parent bff0855af0
commit 21e0182ae2

@ -68,7 +68,7 @@ source_group(misc FILES ${MISC} ${MISC_HEADER})
set(COMPILER components/compiler/errorhandler.cpp
components/compiler/fileparser.cpp components/compiler/scriptparser.cpp
components/compiler/lineparser.cpp
components/compiler/lineparser.cpp components/compiler/skipparser.cpp
components/compiler/parser.cpp components/compiler/scanner.cpp
components/compiler/streamerrorhandler.cpp)
file(GLOB COMPILER_HEADER components/compiler/*.hpp)

@ -6,6 +6,7 @@
#include "scanner.hpp"
#include "context.hpp"
#include "errorhandler.hpp"
#include "skipparser.hpp"
namespace Compiler
{
@ -29,7 +30,12 @@ namespace Compiler
if (mState==ShortState || mState==LongState || mState==FloatState)
{
if (!getContext().canDeclareLocals())
{
getErrorHandler().error ("local variables can't be declared in this context", loc);
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return false;
}
std::cout << "declaring local variable: " << name << std::endl;
mState = EndState;

@ -0,0 +1,41 @@
#include "skipparser.hpp"
#include "scanner.hpp"
namespace Compiler
{
SkipParser::SkipParser (ErrorHandler& errorHandler, Context& context)
: Parser (errorHandler, context)
{}
bool SkipParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
{
return true;
}
bool SkipParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
{
return true;
}
bool SkipParser::parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner)
{
return true;
}
bool SkipParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{
return true;
}
bool SkipParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{
if (code==Scanner::S_newline)
return false;
return true;
}
}

@ -0,0 +1,42 @@
#ifndef COMPILER_SKIPPARSER_H_INCLUDED
#define COMPILER_SKIPPARSER_H_INCLUDED
#include "parser.hpp"
namespace Compiler
{
// \brief Skip parser for skipping a line
//
// This parser is mainly intended for skipping the rest of a faulty line.
class SkipParser : public Parser
{
public:
SkipParser (ErrorHandler& errorHandler, Context& context);
virtual bool parseInt (int value, const TokenLoc& loc, Scanner& scanner);
///< Handle an int token.
/// \return fetch another token?
virtual bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner);
///< Handle a float token.
/// \return fetch another token?
virtual bool parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner);
///< Handle a name token.
/// \return fetch another token?
virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
///< Handle a keyword token.
/// \return fetch another token?
virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
///< Handle a special character token.
/// \return fetch another token?
};
}
#endif
Loading…
Cancel
Save