forked from teamnwah/openmw-tes3coop
added line parser (doesn't parse anything yet)
This commit is contained in:
parent
fda7077cf2
commit
16f6f27a90
6 changed files with 106 additions and 6 deletions
|
@ -68,6 +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/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)
|
||||||
|
|
43
components/compiler/lineparser.cpp
Normal file
43
components/compiler/lineparser.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
#include "lineparser.hpp"
|
||||||
|
|
||||||
|
#include "scanner.hpp"
|
||||||
|
|
||||||
|
namespace Compiler
|
||||||
|
{
|
||||||
|
LineParser::LineParser (ErrorHandler& errorHandler, Context& context)
|
||||||
|
: Parser (errorHandler, context)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool LineParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
{
|
||||||
|
return Parser::parseInt (value, loc, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
{
|
||||||
|
return Parser::parseFloat (value, loc, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineParser::parseName (const std::string& name, const TokenLoc& loc,
|
||||||
|
Scanner& scanner)
|
||||||
|
{
|
||||||
|
return Parser::parseName (name, loc, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
{
|
||||||
|
return Parser::parseKeyword (keyword, loc, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
{
|
||||||
|
return Parser::parseSpecial (code, loc, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineParser::reset()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
42
components/compiler/lineparser.hpp
Normal file
42
components/compiler/lineparser.hpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef COMPILER_LINEPARSER_H_INCLUDED
|
||||||
|
#define COMPILER_LINEPARSER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "parser.hpp"
|
||||||
|
|
||||||
|
namespace Compiler
|
||||||
|
{
|
||||||
|
/// \brief Line parser, to be used in console scripts and as part of ScriptParser
|
||||||
|
|
||||||
|
class LineParser : public Parser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
LineParser (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?
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
///< Reset parser to clean state.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -56,7 +56,7 @@ namespace Compiler
|
||||||
/// - Default-implementation: Report an error.
|
/// - Default-implementation: Report an error.
|
||||||
|
|
||||||
virtual bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner);
|
virtual bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner);
|
||||||
///< Handle a double token.
|
///< Handle a float token.
|
||||||
/// \return fetch another token?
|
/// \return fetch another token?
|
||||||
///
|
///
|
||||||
/// - Default-implementation: Report an error.
|
/// - Default-implementation: Report an error.
|
||||||
|
|
|
@ -6,13 +6,17 @@
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
ScriptParser::ScriptParser (ErrorHandler& errorHandler, Context& context, bool end)
|
ScriptParser::ScriptParser (ErrorHandler& errorHandler, Context& context, bool end)
|
||||||
: Parser (errorHandler, context), mEnd (end)
|
: Parser (errorHandler, context), mLineParser (errorHandler, context), mEnd (end)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool ScriptParser::parseName (const std::string& name, const TokenLoc& loc,
|
bool ScriptParser::parseName (const std::string& name, const TokenLoc& loc,
|
||||||
Scanner& scanner)
|
Scanner& scanner)
|
||||||
{
|
{
|
||||||
return Parser::parseName (name, loc, scanner);
|
mLineParser.reset();
|
||||||
|
if (mLineParser.parseName (name, loc, scanner))
|
||||||
|
scanner.scan (mLineParser);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
bool ScriptParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
@ -22,7 +26,11 @@ namespace Compiler
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Parser::parseKeyword (keyword, loc, scanner);
|
mLineParser.reset();
|
||||||
|
if (mLineParser.parseKeyword (keyword, loc, scanner))
|
||||||
|
scanner.scan (mLineParser);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
bool ScriptParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
||||||
|
@ -30,7 +38,11 @@ namespace Compiler
|
||||||
if (code==Scanner::S_newline) // empty line
|
if (code==Scanner::S_newline) // empty line
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return Parser::parseSpecial (code, loc, scanner);
|
mLineParser.reset();
|
||||||
|
if (mLineParser.parseSpecial (code, loc, scanner))
|
||||||
|
scanner.scan (mLineParser);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptParser::parseEOF (Scanner& scanner)
|
void ScriptParser::parseEOF (Scanner& scanner)
|
||||||
|
@ -41,7 +53,7 @@ namespace Compiler
|
||||||
|
|
||||||
void ScriptParser::reset()
|
void ScriptParser::reset()
|
||||||
{
|
{
|
||||||
|
mLineParser.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define COMPILER_SCRIPTPARSER_H_INCLUDED
|
#define COMPILER_SCRIPTPARSER_H_INCLUDED
|
||||||
|
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
#include "lineparser.hpp"
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
|
@ -9,6 +10,7 @@ namespace Compiler
|
||||||
|
|
||||||
class ScriptParser : public Parser
|
class ScriptParser : public Parser
|
||||||
{
|
{
|
||||||
|
LineParser mLineParser;
|
||||||
bool mEnd;
|
bool mEnd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue