#143 Script engine: Renamed TokenType to STokenType yielding for some Windows API specific stuff.

master
Tomatix 2 years ago
parent bb09217d7d
commit b8c2fd7d1b
  1. 58
      Script/Script.cpp
  2. 120
      Script/Tokenizer.cpp
  3. 26
      Script/Tokens.cpp
  4. 14
      Script/Tokens.h

@ -516,7 +516,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Commands
*/
else if (expr[0].type() == TokenType::Command) {
else if (expr[0].type() == STokenType::Command) {
lastConditional = -1;
const Token& cmd = static_cast<Token&>(expr[0]);
std::string input = resolveCommandLine(cmd.token(), symbols);
@ -526,7 +526,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Assignment
*/
else if (expr.count() == 3 && expr[0].type() == TokenType::Keyword && expr[1].type() == TokenType::Operator) {
else if (expr.count() == 3 && expr[0].type() == STokenType::Keyword && expr[1].type() == STokenType::Operator) {
lastConditional = -1;
const Token& lv = static_cast<Token&>(expr[0]);
@ -535,7 +535,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
auto pto = ParserToken::strToOperator(operToken.token());
if (expr[2].type() == TokenType::Reference) {
if (expr[2].type() == STokenType::Reference) {
if (pto != ParserOperator::Assign)
throw ScriptException(operToken.lineCol(), EMSG::CannotAssign);
if (subex.count() != 1)
@ -551,7 +551,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
ValueRef valRef = referSym->get().getValue();
symbols.set(lv.token(), ValueHolder(valRef));
}
if (expr[2].type() == TokenType::MapKeyword) {
if (expr[2].type() == STokenType::MapKeyword) {
if (pto != ParserOperator::Assign)
throw ScriptException(operToken.lineCol(), EMSG::CannotAssign);
if (subex.count() != 1)
@ -573,7 +573,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Assignment, map entry
*/
else if (expr.count() == 3 && expr[0].type() == TokenType::MapKeyword && expr[1].type() == TokenType::Operator) {
else if (expr.count() == 3 && expr[0].type() == STokenType::MapKeyword && expr[1].type() == STokenType::Operator) {
lastConditional = -1;
const MapToken& lv = static_cast<MapToken&>(expr[0]);
const Token& operToken = static_cast<Token&>(expr[1]);
@ -604,7 +604,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Keywords
*/
else if (expr[0].type() == TokenType::Keyword) {
else if (expr[0].type() == STokenType::Keyword) {
lastConditional = -1;
const std::string& token = static_cast<Token&>(expr[0]).token();
if (token == "return") { // TODO own token type
@ -618,7 +618,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Conditional: 'if'
*/
else if (expr[0].type() == TokenType::CondIf) {
else if (expr[0].type() == STokenType::CondIf) {
ConditionalScopeToken& scopeTk = static_cast<ConditionalScopeToken&>(expr[0]);
const Expression& condition = scopeTk.scope().condition();
ValueHolder result = resolveExpression(condition, symbols);
@ -639,13 +639,13 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Conditional: 'else'
*/
else if (expr[0].type() == TokenType::CondElse && lastConditional != 1) {
else if (expr[0].type() == STokenType::CondElse && lastConditional != 1) {
if (lastConditional == -1)
throw ScriptException(expr[0].lineCol(), EMSG::ElseWithoutPrevIf);
ConditionalScopeToken& scopeTk = static_cast<ConditionalScopeToken&>(expr[0]);
if (scopeTk.scope().begin()->begin()->type() == TokenType::CondIf) {
if (scopeTk.scope().begin()->begin()->type() == STokenType::CondIf) {
ConditionalScopeToken& ifScopeTk = static_cast<ConditionalScopeToken&>( *(scopeTk.scope().begin()->begin()) );
const Expression& condition = ifScopeTk.scope().condition();
ValueHolder result = resolveExpression(condition, symbols);
@ -679,7 +679,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Conditional: 'while'
*/
else if (expr[0].type() == TokenType::CondWhile) {
else if (expr[0].type() == STokenType::CondWhile) {
ConditionalScopeToken& scopeTk = static_cast<ConditionalScopeToken&>(expr[0]);
const Expression& condition = scopeTk.scope().condition();
ValueHolder test = resolveExpression(condition, symbols);
@ -689,7 +689,7 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
if (scopeResult.index() == 1) {
auto& control = std::get<TokenBaseRef>(scopeResult).get();
if (control.type() == TokenType::Continue)
if (control.type() == STokenType::Continue)
continue;
else
break;
@ -708,21 +708,21 @@ std::variant<std::optional<ValueHolder>, TokenBaseRef> Script::runScope(const Sc
/*
* Control: 'continue', 'break'
*/
else if (expr[0].type() == TokenType::Continue || expr[0].type() == TokenType::Break) {
else if (expr[0].type() == STokenType::Continue || expr[0].type() == STokenType::Break) {
return expr[0];
}
/*
* Function call where the result is discarded
*/
else if (expr[0].type() == TokenType::Function) {
else if (expr[0].type() == STokenType::Function) {
resolveExpression(expr, symbols);
}
/*
* Event dispatching
*/
else if (expr[0].type() == TokenType::Dispatch) {
else if (expr[0].type() == STokenType::Dispatch) {
auto& disptk = static_cast<DispatchToken&>(expr[0]);
std::vector<ValueHolder> params = resolveParameters(disptk.parameters(), symbols);
dispatchHandler(disptk.token(), params);
@ -743,7 +743,7 @@ ValueHolder Script::resolveParamsRunScope(const Scope& scope, std::vector<ValueH
else if (paramValues.size() > 0) {
// TODO implement default parameters here.
auto& tokenbase = *(paramExpr.begin());
if (tokenbase.type() == TokenType::Keyword) {
if (tokenbase.type() == STokenType::Keyword) {
const Token& token = static_cast<Token&>(tokenbase);
symbols.set(token.token(), paramValues[paramidx]);
++paramidx;
@ -754,9 +754,9 @@ ValueHolder Script::resolveParamsRunScope(const Scope& scope, std::vector<ValueH
auto scopeResult = runScope(scope, symbols);
if (scopeResult.index() == 1) {
auto& errTok = std::get<TokenBaseRef>(scopeResult).get();
if (errTok.type() == TokenType::Continue)
if (errTok.type() == STokenType::Continue)
throw ScriptException(errTok.lineCol(), EMSG::ContinueOutsideWhile);
else if (errTok.type() == TokenType::Break)
else if (errTok.type() == STokenType::Break)
throw ScriptException(errTok.lineCol(), EMSG::BreakOutsideWhile);
else
throw ScriptException(errTok.lineCol(), EMSG::UndefinedError);
@ -778,14 +778,14 @@ ValueHolder Script::resolveExpression(const Expression& expr, SymbolScope& symbo
if (expr.begin() == expr.end())
return {}; // Nothing to solve, return 'void'
else {
if (expr.begin()->type() == TokenType::Operator)
if (expr.begin()->type() == STokenType::Operator)
throw ScriptException(expr.begin()->lineCol(), EMSG::ExprOperStart);
if ((expr.end()-1)->type() == TokenType::Operator)
if ((expr.end()-1)->type() == STokenType::Operator)
throw ScriptException((expr.end()-1)->lineCol(), EMSG::ExprOperEnd);
}
if (expr.begin()->type() == TokenType::Reference) {
if (expr.begin()->type() == STokenType::Reference) {
if (expr.count() > 1)
throw ScriptException((expr.end()-1)->lineCol(), EMSG::CannotMixReferences);
@ -813,7 +813,7 @@ ValueHolder Script::resolveExpression(const Expression& expr, SymbolScope& symbo
* This is done recursively when hitting a subexpression.
*/
for (TokenBase& tkbase : expr) {
if (tkbase.type() == TokenType::Keyword) {
if (tkbase.type() == STokenType::Keyword) {
const Token& tk = static_cast<const Token&>(tkbase);
auto optval = symbols.get(tk.token());
if (!optval)
@ -829,7 +829,7 @@ ValueHolder Script::resolveExpression(const Expression& expr, SymbolScope& symbo
}
}
else if (tkbase.type() == TokenType::MapKeyword) {
else if (tkbase.type() == STokenType::MapKeyword) {
const MapToken& tk = static_cast<const MapToken&>(tkbase);
auto optval = symbols.get(tk.token());
if (!optval)
@ -864,34 +864,34 @@ ValueHolder Script::resolveExpression(const Expression& expr, SymbolScope& symbo
}
}
else if (tkbase.type() == TokenType::NumberLiteral) {
else if (tkbase.type() == STokenType::NumberLiteral) {
const Token& tk = static_cast<const Token&>(tkbase);
parts.emplace_back(tkbase, ValueHolder{ std::stoi(tk.token()) });
}
else if (tkbase.type() == TokenType::RealLiteral) {
else if (tkbase.type() == STokenType::RealLiteral) {
const Token& tk = static_cast<const Token&>(tkbase);
parts.emplace_back(tkbase, ValueHolder{ std::stod(tk.token()) });
}
else if (tkbase.type() == TokenType::StringLiteral) {
else if (tkbase.type() == STokenType::StringLiteral) {
const Token& tk = static_cast<const Token&>(tkbase);
parts.emplace_back(tkbase, ValueHolder{ tk.token() });
}
else if (tkbase.type() == TokenType::BoolLiteral) {
else if (tkbase.type() == STokenType::BoolLiteral) {
const BoolToken& tk = static_cast<const BoolToken&>(tkbase);
parts.emplace_back(tkbase, ValueHolder{ tk.value() });
}
else if (tkbase.type() == TokenType::Operator) {
else if (tkbase.type() == STokenType::Operator) {
const Token& tk = static_cast<const Token&>(tkbase);
auto op = ParserToken::strToOperator(tk.token());
if (op == ParserOperator::Invalid)
throw ScriptException(tk.lineCol(), EMSG::NotAnOperator + tk.token());
parts.emplace_back(tkbase, op);
}
else if (tkbase.type() == TokenType::Expression) {
else if (tkbase.type() == STokenType::Expression) {
const Expression& subexpr = static_cast<const Expression&>(tkbase);
parts.push_back(ParserToken(tkbase, resolveExpression(subexpr, symbols)));
}
else if (tkbase.type() == TokenType::Function) {
else if (tkbase.type() == STokenType::Function) {
try {
const FunctionToken& funtk = dynamic_cast<const FunctionToken&>(tkbase);
std::vector<ValueHolder> params = resolveParameters(funtk.parameters(), symbols);

@ -103,7 +103,7 @@ struct TokenizerPriv
std::string errorMsg{ "" };
DataIndex idx{ data };
TokenType curType{ TokenType::Undefined };
STokenType curType{ STokenType::Undefined };
std::vector<std::unique_ptr<Scope>> scopes{};
std::vector<std::string> globals{};
@ -162,25 +162,25 @@ bool TokenizerPriv::determineType(bool blankExpressionRelated)
const char c = data[idx()];
if (c == '/' && blankExpressionRelated)
curType = TokenType::Command;
curType = STokenType::Command;
else if (c == '&' && blankExpressionRelated)
curType = TokenType::Reference;
curType = STokenType::Reference;
else if (keywordChar(c, false))
curType = TokenType::Keyword;
curType = STokenType::Keyword;
else if (c >= '0' && c <= '9')
curType = TokenType::NumberLiteral; // RealLiteral will be detected during parsing of this type
curType = STokenType::NumberLiteral; // RealLiteral will be detected during parsing of this type
else if (c == '"')
curType = TokenType::StringLiteral;
curType = STokenType::StringLiteral;
else if (c == '{')
curType = TokenType::Scope;
curType = STokenType::Scope;
else if (c == '}')
curType = TokenType::EndScope;
curType = STokenType::EndScope;
else if (c == '(') {
if (idx > 0) {
@ -190,57 +190,57 @@ bool TokenizerPriv::determineType(bool blankExpressionRelated)
return false;
}
if (keywordChar(prev[0], false))
curType = TokenType::Function;
curType = STokenType::Function;
else
curType = TokenType::Expression;
curType = STokenType::Expression;
}
else
curType = TokenType::Expression;
curType = STokenType::Expression;
}
else if (c == ')' || c == ']')
curType = TokenType::EndExpression;
curType = STokenType::EndExpression;
else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '!'
|| c == '&' || c == '|' || c == '<' || c == '>' || c == '=')
curType = TokenType::Operator;
curType = STokenType::Operator;
else if (c == ',')
curType = TokenType::Comma;
curType = STokenType::Comma;
else if (c == ';')
curType = TokenType::SemiColon;
curType = STokenType::SemiColon;
else {
curType = TokenType::Undefined;
curType = STokenType::Undefined;
errorMsg = "Stray character: ";
errorMsg.push_back(c);
return false;
}
/* Peek next keyword for specials like 'if', 'else', etc. */
if (curType == TokenType::Keyword) {
if (curType == STokenType::Keyword) {
auto peek = peekNextKeyword(idx);
if (peek.first == TKN::If)
curType = TokenType::CondIf;
curType = STokenType::CondIf;
else if (peek.first == TKN::Else)
curType = TokenType::CondElse;
curType = STokenType::CondElse;
else if (peek.first == TKN::While)
curType = TokenType::CondWhile;
curType = STokenType::CondWhile;
else if (peek.first == TKN::Dispatch)
curType = TokenType::Dispatch;
curType = STokenType::Dispatch;
else if (peek.first == TKN::False || peek.first == TKN::True) {
curType = TokenType::BoolLiteral;
curType = STokenType::BoolLiteral;
buf = peek.first;
}
else if (data[peek.second()] == '[') {
curType = TokenType::MapKeyword;
curType = STokenType::MapKeyword;
buf = peek.first;
++peek.second;
}
if (curType != TokenType::Keyword)
if (curType != STokenType::Keyword)
idx = peek.second;
}
@ -324,7 +324,7 @@ bool TokenizerPriv::number()
buf += decimalSeparator();
decimalsep = true;
// Side effect:
curType = TokenType::RealLiteral;
curType = STokenType::RealLiteral;
}
else
break;
@ -343,13 +343,13 @@ void TokenizerPriv::comment()
bool TokenizerPriv::processExpression(Expression& root)
{
const TokenType& type = curType;
const STokenType& type = curType;
while (idx < data.length()) {
if (!determineType(root.count() == 0)) return false;
switch (type) {
case TokenType::Command:
case STokenType::Command:
{
if (!command()) return false;
if (buf.empty()) {
@ -362,7 +362,7 @@ bool TokenizerPriv::processExpression(Expression& root)
return true;
}
case TokenType::Keyword: // TODO return as own token type
case STokenType::Keyword: // TODO return as own token type
if (!keyword()) return false;
if (buf == "return") {
{
@ -379,7 +379,7 @@ bool TokenizerPriv::processExpression(Expression& root)
else if (buf == "continue") {
const auto lc = idx.lineCol();
root.addToken("", TokenType::Continue, lc.first, lc.second);
root.addToken("", STokenType::Continue, lc.first, lc.second);
buf.clear();
if (!whitespace()) return false;
if (data[idx()] != ';')
@ -389,7 +389,7 @@ bool TokenizerPriv::processExpression(Expression& root)
else if (buf == "break") {
const auto lc = idx.lineCol();
root.addToken("", TokenType::Break, lc.first, lc.second);
root.addToken("", STokenType::Break, lc.first, lc.second);
buf.clear();
if (!whitespace()) return false;
if (data[idx()] != ';')
@ -398,7 +398,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
break;
case TokenType::Reference:
case STokenType::Reference:
++idx;
buf.clear();
if (!keyword()) return false;
@ -413,7 +413,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
break;
case TokenType::MapKeyword:
case STokenType::MapKeyword:
{
const auto lc = idx.lineCol();
MapToken& token = root.addMapToken(buf, lc.first, lc.second);
@ -422,7 +422,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
continue;
case TokenType::Operator:
case STokenType::Operator:
if (!oper()) return false;
if (buf == "=") {
++idx;
@ -440,21 +440,21 @@ bool TokenizerPriv::processExpression(Expression& root)
/* Check if this is subtraction or unary minus */
if (buf == "-") {
if (root.count() == 0 || (root.back().type() == TokenType::Operator))
if (root.count() == 0 || (root.back().type() == STokenType::Operator))
continue;
}
break;
case TokenType::StringLiteral:
case STokenType::StringLiteral:
if (!string()) return false;
break;
case TokenType::NumberLiteral:
case STokenType::NumberLiteral:
// May turn the type into a FloatLiteral
if (!number()) return false;
break;
case TokenType::BoolLiteral:
case STokenType::BoolLiteral:
{
const auto lc = idx.lineCol();
// buf is peeked and stored via determineType().
@ -463,7 +463,7 @@ bool TokenizerPriv::processExpression(Expression& root)
continue;
}
case TokenType::Expression:
case STokenType::Expression:
{
++idx;
const auto lc = idx.lineCol();
@ -474,20 +474,20 @@ bool TokenizerPriv::processExpression(Expression& root)
continue;
}
case TokenType::EndScope: [[fallthrough]];
case TokenType::EndExpression: [[fallthrough]];
case TokenType::Comma:
case STokenType::EndScope: [[fallthrough]];
case STokenType::EndExpression: [[fallthrough]];
case STokenType::Comma:
++idx;
[[fallthrough]];
case TokenType::SemiColon:
case STokenType::SemiColon:
return true;
case TokenType::Comment:
case STokenType::Comment:
comment();
continue;
case TokenType::Function:
case STokenType::Function:
{
std::string fname;
{
@ -505,7 +505,7 @@ bool TokenizerPriv::processExpression(Expression& root)
continue;
}
case TokenType::CondIf:
case STokenType::CondIf:
{
if (!whitespace()) return false;
++idx;
@ -521,7 +521,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
return true;
case TokenType::CondWhile:
case STokenType::CondWhile:
{
if (!whitespace()) return false;
++idx;
@ -536,7 +536,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
return true;
case TokenType::CondElse:
case STokenType::CondElse:
{
const auto lc = idx.lineCol();
ConditionalScopeToken& scopeTk = root.addElseScope(lc.first, lc.second);
@ -545,7 +545,7 @@ bool TokenizerPriv::processExpression(Expression& root)
}
return true;
case TokenType::Dispatch:
case STokenType::Dispatch:
{
buf.clear();
if (!whitespace()) return false;
@ -568,7 +568,7 @@ bool TokenizerPriv::processExpression(Expression& root)
return false;
}
if (curType != TokenType::SemiColon) {
if (curType != STokenType::SemiColon) {
const auto lc = idx.lineCol();
root.addToken(buf, type, lc.first, lc.second);
buf.clear();
@ -600,10 +600,10 @@ bool TokenizerPriv::processStatementList(Scope& scope, bool parameterList)
if (expr.count() > 0)
scope.addStatement(std::move(expr));
if ((parameterList && curType == TokenType::EndExpression) || curType == TokenType::EndScope)
if ((parameterList && curType == STokenType::EndExpression) || curType == STokenType::EndScope)
return true;
if (curType == TokenType::SemiColon) {
if (curType == STokenType::SemiColon) {
++idx;
}
@ -690,7 +690,7 @@ bool TokenizerPriv::processDialog(Dialog& dialog)
buf.clear();
if (!determineType(false)) return false;
if (curType != TokenType::Keyword) {
if (curType != STokenType::Keyword) {
errorMsg = "Expected a keyword";
return false;
}
@ -711,7 +711,7 @@ bool TokenizerPriv::processDialog(Dialog& dialog)
else if (buf == "hook") {
buf.clear();
if (!determineType(false)) return false;
if (curType != TokenType::Keyword) {
if (curType != STokenType::Keyword) {
errorMsg = "Expected a keyword";
return false;
}
@ -755,22 +755,22 @@ bool TokenizerPriv::processDialogAttr(T& dialog_or_widget)
ValueHolder value;
switch (curType) {
case TokenType::StringLiteral:
case STokenType::StringLiteral:
buf.clear();
if (!string()) return false;
value = buf;
break;
case TokenType::NumberLiteral:
case STokenType::NumberLiteral:
buf.clear();
if (!number()) return false; // side-effect: may change current type to a real number.
if (curType == TokenType::RealLiteral)
if (curType == STokenType::RealLiteral)
value = std::stod(buf);
else
value = std::stoi(buf);
break;
case TokenType::BoolLiteral:
case STokenType::BoolLiteral:
value = buf == "true" ? true : false;
break;
@ -799,7 +799,7 @@ bool TokenizerPriv::processDialogWidget(Dialog& dialog, DialogWidget::Type wtype
if (!whitespace()) return false;
if (!determineType(false)) return false;
if (curType != TokenType::Keyword) {
if (curType != STokenType::Keyword) {
errorMsg = "Expected a keyword when declaring a widget in dialog '" + dialog.name() + "'";
return false;
}
@ -825,7 +825,7 @@ bool TokenizerPriv::processDialogWidget(Dialog& dialog, DialogWidget::Type wtype
buf.clear();
if (!determineType(false)) return false;
if (curType != TokenType::Keyword) {
if (curType != STokenType::Keyword) {
errorMsg = "Expected a keyword";
return false;
}
@ -834,7 +834,7 @@ bool TokenizerPriv::processDialogWidget(Dialog& dialog, DialogWidget::Type wtype
else if (buf == "hook") {
buf.clear();
if (!determineType(false)) return false;
if (curType != TokenType::Keyword) {
if (curType != STokenType::Keyword) {
errorMsg = "Expected a keyword";
return false;
}

@ -130,7 +130,7 @@ ConditionalScopeTokenPriv::ConditionalScopeTokenPriv(int line, int col, Expressi
* Various constructors
*/
TokenBase::TokenBase(TokenType type, int line, int col)
TokenBase::TokenBase(STokenType type, int line, int col)
: m_type(type)
, m_line(line)
, m_col(col)
@ -142,7 +142,7 @@ TokenBase::TokenBase(TokenBase&& other)
, m_col(other.m_col)
{}
Token::Token(const std::string& token, TokenType type, int line, int col)
Token::Token(const std::string& token, STokenType type, int line, int col)
: TokenBase(type, line, col)
, m_token(token)
{}
@ -153,7 +153,7 @@ Token::Token(Token&& other)
{}
BoolToken::BoolToken(bool val, int line, int col)
: TokenBase(TokenType::BoolLiteral, line, col)
: TokenBase(STokenType::BoolLiteral, line, col)
, m_val(val)
{}
@ -163,7 +163,7 @@ BoolToken::BoolToken(BoolToken&& other)
{}
MapToken::MapToken(const std::string& token, int line, int col, bool isRef)
: Token(token, isRef ? TokenType::Reference : TokenType::MapKeyword, line, col)
: Token(token, isRef ? STokenType::Reference : STokenType::MapKeyword, line, col)
, mp(new MapTokenPriv(line, col))
{}
@ -173,7 +173,7 @@ MapToken::MapToken(MapToken&& other)
{}
DispatchToken::DispatchToken(const std::string& token, int line, int col)
: Token(token, TokenType::Dispatch, line, col)
: Token(token, STokenType::Dispatch, line, col)
, mp(new DispatchTokenPriv(line, col))
{}
@ -183,7 +183,7 @@ DispatchToken::DispatchToken(DispatchToken&& other)
{}
FunctionToken::FunctionToken(const std::string& identifier, int line, int col)
: TokenBase(TokenType::Function, line, col)
: TokenBase(STokenType::Function, line, col)
, mp(new FunctionTokenPriv(identifier, line, col))
{}
@ -193,7 +193,7 @@ FunctionToken::FunctionToken(FunctionToken&& other)
{}
Expression::Expression(int line, int col)
: TokenBase(TokenType::Expression, line, col)
: TokenBase(STokenType::Expression, line, col)
, mp(new ExpressionPriv)
{}
@ -232,7 +232,7 @@ ConditionalScope::ConditionalScope(int line, int col, Expression&& condition)
, m_cond(std::move(condition))
{}
ConditionalScopeToken::ConditionalScopeToken(TokenType type, int line, int col, Expression&& condition)
ConditionalScopeToken::ConditionalScopeToken(STokenType type, int line, int col, Expression&& condition)
: TokenBase(type, line, col)
, mp(new ConditionalScopeTokenPriv(line, col, std::move(condition)))
{}
@ -248,7 +248,7 @@ std::pair<int, int> TokenBase::lineCol() const
return std::make_pair(m_line, m_col);
}
TokenType TokenBase::type() const
STokenType TokenBase::type() const
{
return m_type;
}
@ -352,7 +352,7 @@ ConditionalScope& ConditionalScopeToken::scope() const
* Expression
*/
void Expression::addToken(const std::string& token, TokenType type, int line, int col)
void Expression::addToken(const std::string& token, STokenType type, int line, int col)
{
mp->tokens.emplace_back(new Token(token, type, line, col));
}
@ -388,20 +388,20 @@ FunctionToken& Expression::addFunction(const std::string& identifier, int line,
ConditionalScopeToken& Expression::addIfScope(int line, int col, Expression&& condition)
{
mp->tokens.emplace_back(new ConditionalScopeToken(TokenType::CondIf, line, col, std::move(condition)));
mp->tokens.emplace_back(new ConditionalScopeToken(STokenType::CondIf, line, col, std::move(condition)));
return *(static_cast<ConditionalScopeToken*>(mp->tokens.back().get()));
}
ConditionalScopeToken& Expression::addElseScope(int line, int col)
{
Expression dummy(0, 0);
mp->tokens.emplace_back(new ConditionalScopeToken(TokenType::CondElse, line, col, std::move(dummy)));
mp->tokens.emplace_back(new ConditionalScopeToken(STokenType::CondElse, line, col, std::move(dummy)));
return *(static_cast<ConditionalScopeToken*>(mp->tokens.back().get()));
}
ConditionalScopeToken& Expression::addWhileScope(int line, int col, Expression&& condition)
{
mp->tokens.emplace_back(new ConditionalScopeToken(TokenType::CondWhile, line, col, std::move(condition)));
mp->tokens.emplace_back(new ConditionalScopeToken(STokenType::CondWhile, line, col, std::move(condition)));
return *(static_cast<ConditionalScopeToken*>(mp->tokens.back().get()));
}

@ -12,7 +12,7 @@
#include <vector>
#include <memory>
enum class TokenType {
enum class STokenType {
Undefined,
Command,
Function,
@ -134,15 +134,15 @@ class TokenBase
{
public:
virtual ~TokenBase() = default;
TokenType type() const;
STokenType type() const;
std::pair<int,int> lineCol() const;
protected:
TokenBase(TokenBase&& other);
explicit TokenBase(TokenType type, int line, int col);
explicit TokenBase(STokenType type, int line, int col);
private:
const TokenType m_type;
const STokenType m_type;
const int m_line;
const int m_col;
};
@ -163,7 +163,7 @@ public:
const std::string& token() const;
private:
Token(const std::string& token, TokenType type, int line, int col);
Token(const std::string& token, STokenType type, int line, int col);
Token(Token&& other);
const std::string m_token;
@ -276,7 +276,7 @@ public:
ConditionalScope& scope() const;
private:
ConditionalScopeToken(TokenType type, int line, int col, Expression&& condition);
ConditionalScopeToken(STokenType type, int line, int col, Expression&& condition);
std::unique_ptr<ConditionalScopeTokenPriv> mp;
};
@ -297,7 +297,7 @@ public:
Expression& operator=(Expression&) = delete;
Expression& operator=(Expression&&);
void addToken(const std::string& token, TokenType type, int line, int col);
void addToken(const std::string& token, STokenType type, int line, int col);
void addBool(bool val, int line, int col);
MapToken& addMapToken(const std::string& token, int line, int col, bool isRef = false);
DispatchToken& addDispatchToken(const std::string& token, int line, int col);

Loading…
Cancel
Save