mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 17:19:39 +00:00
added skip parser for skipping faulty lines
This commit is contained in:
parent
bff0855af0
commit
21e0182ae2
4 changed files with 90 additions and 1 deletions
|
@ -68,7 +68,7 @@ source_group(misc FILES ${MISC} ${MISC_HEADER})
|
||||||
|
|
||||||
set(COMPILER components/compiler/errorhandler.cpp
|
set(COMPILER components/compiler/errorhandler.cpp
|
||||||
components/compiler/fileparser.cpp components/compiler/scriptparser.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/parser.cpp components/compiler/scanner.cpp
|
||||||
components/compiler/streamerrorhandler.cpp)
|
components/compiler/streamerrorhandler.cpp)
|
||||||
file(GLOB COMPILER_HEADER components/compiler/*.hpp)
|
file(GLOB COMPILER_HEADER components/compiler/*.hpp)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "scanner.hpp"
|
#include "scanner.hpp"
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
#include "errorhandler.hpp"
|
#include "errorhandler.hpp"
|
||||||
|
#include "skipparser.hpp"
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
|
@ -29,7 +30,12 @@ namespace Compiler
|
||||||
if (mState==ShortState || mState==LongState || mState==FloatState)
|
if (mState==ShortState || mState==LongState || mState==FloatState)
|
||||||
{
|
{
|
||||||
if (!getContext().canDeclareLocals())
|
if (!getContext().canDeclareLocals())
|
||||||
|
{
|
||||||
getErrorHandler().error ("local variables can't be declared in this context", loc);
|
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;
|
std::cout << "declaring local variable: " << name << std::endl;
|
||||||
mState = EndState;
|
mState = EndState;
|
||||||
|
|
41
components/compiler/skipparser.cpp
Normal file
41
components/compiler/skipparser.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
42
components/compiler/skipparser.hpp
Normal file
42
components/compiler/skipparser.hpp
Normal file
|
@ -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…
Reference in a new issue