From f0ab13ebc3a91391007f24a21ff56b7dc5aff376 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 20 Jan 2021 22:56:31 +0100 Subject: [PATCH] Added "dollar operator" to get the current offset --- plugins/libimhex/include/hex/lang/token.hpp | 4 +++- plugins/libimhex/source/lang/lexer.cpp | 3 +++ plugins/libimhex/source/lang/parser.cpp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/libimhex/include/hex/lang/token.hpp b/plugins/libimhex/include/hex/lang/token.hpp index f0c693e24..a01edbcc0 100644 --- a/plugins/libimhex/include/hex/lang/token.hpp +++ b/plugins/libimhex/include/hex/lang/token.hpp @@ -59,7 +59,8 @@ namespace hex::lang { BoolOr, BoolXor, BoolNot, - TernaryConditional + TernaryConditional, + Dollar }; enum class ValueType { @@ -225,6 +226,7 @@ namespace hex::lang { #define OPERATOR_BOOLXOR COMPONENT(Operator, BoolXor) #define OPERATOR_BOOLNOT COMPONENT(Operator, BoolNot) #define OPERATOR_TERNARYCONDITIONAL COMPONENT(Operator, TernaryConditional) +#define OPERATOR_DOLLAR COMPONENT(Operator, Dollar) #define VALUETYPE_CUSTOMTYPE COMPONENT(ValueType, CustomType) #define VALUETYPE_PADDING COMPONENT(ValueType, Padding) diff --git a/plugins/libimhex/source/lang/lexer.cpp b/plugins/libimhex/source/lang/lexer.cpp index d24be2ad7..7a4f2366f 100644 --- a/plugins/libimhex/source/lang/lexer.cpp +++ b/plugins/libimhex/source/lang/lexer.cpp @@ -362,6 +362,9 @@ namespace hex::lang { } else if (c == '?') { tokens.emplace_back(TOKEN(Operator, TernaryConditional)); offset += 1; + } else if (c == '$') { + tokens.emplace_back(TOKEN(Operator, Dollar)); + offset += 1; } else if (c == '\'') { auto character = getCharacterLiteral(code.substr(offset)); diff --git a/plugins/libimhex/source/lang/parser.cpp b/plugins/libimhex/source/lang/parser.cpp index 7caf1792c..e32154d6b 100644 --- a/plugins/libimhex/source/lang/parser.cpp +++ b/plugins/libimhex/source/lang/parser.cpp @@ -97,6 +97,8 @@ namespace hex::lang { } else if (MATCHES(sequence(IDENTIFIER))) { std::vector path; return this->parseRValue(path); + } else if (MATCHES(sequence(OPERATOR_DOLLAR))) { + return new ASTNodeRValue({ "$" }); } else throwParseError("expected integer or parenthesis"); }