Plasma Engine  2.0
Loading...
Searching...
No Matches
ExpressionParser_inl.h
1
2inline bool plExpressionParser::AcceptStatementTerminator()
3{
4 return plTokenParseUtils::Accept(m_TokenStream, m_uiCurrentToken, plTokenType::Newline) ||
5 plTokenParseUtils::Accept(m_TokenStream, m_uiCurrentToken, ";");
6}
7
8inline plResult plExpressionParser::Expect(plStringView sToken, const plToken** pExpectedToken)
9{
10 plUInt32 uiAcceptedToken = 0;
11 if (plTokenParseUtils::Accept(m_TokenStream, m_uiCurrentToken, sToken, &uiAcceptedToken) == false)
12 {
13 const plUInt32 uiErrorToken = plMath::Min(m_TokenStream.GetCount() - 1, m_uiCurrentToken);
14 auto pToken = m_TokenStream[uiErrorToken];
15 ReportError(pToken, plFmt("Syntax error, expected {} but got {}", sToken, pToken->m_DataView));
16 return PL_FAILURE;
17 }
18
19 if (pExpectedToken != nullptr)
20 {
21 *pExpectedToken = m_TokenStream[uiAcceptedToken];
22 }
23
24 return PL_SUCCESS;
25}
26
27inline plResult plExpressionParser::Expect(plTokenType::Enum Type, const plToken** pExpectedToken /*= nullptr*/)
28{
29 plUInt32 uiAcceptedToken = 0;
30 if (plTokenParseUtils::Accept(m_TokenStream, m_uiCurrentToken, Type, &uiAcceptedToken) == false)
31 {
32 const plUInt32 uiErrorToken = plMath::Min(m_TokenStream.GetCount() - 1, m_uiCurrentToken);
33 auto pToken = m_TokenStream[uiErrorToken];
34 ReportError(pToken, plFmt("Syntax error, expected token type {} but got {}", plTokenType::EnumNames[Type], plTokenType::EnumNames[pToken->m_iType]));
35 return PL_FAILURE;
36 }
37
38 if (pExpectedToken != nullptr)
39 {
40 *pExpectedToken = m_TokenStream[uiAcceptedToken];
41 }
42
43 return PL_SUCCESS;
44}
45
46inline void plExpressionParser::ReportError(const plToken* pToken, const plFormatString& message0)
47{
49 plStringView message = message0.GetText(tmp);
50 plLog::Error("{}({},{}): {}", pToken->m_File, pToken->m_uiLine, pToken->m_uiColumn, message);
51}
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
Implements formating of strings with placeholders and formatting options.
Definition FormatString.h:59
virtual plStringView GetText(plStringBuilder &) const
Generates the formatted text. Make sure to only call this function once and only when the formatted s...
Definition FormatString.h:76
static void Error(plLogInterface *pInterface, const plFormatString &string)
An error that needs to be fixed as soon as possible.
Definition Log.cpp:375
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Represents one piece of tokenized text in a document.
Definition Tokenizer.h:37
plUInt32 m_uiLine
The line in which the token appeared.
Definition Tokenizer.h:50
plUInt32 m_uiColumn
The column in the line, at which the token string started.
Definition Tokenizer.h:53
plHashedString m_File
The file in which the token appeared.
Definition Tokenizer.h:63
Enum
Definition Tokenizer.h:13
@ Newline
Either ' ' or '\r '.
Definition Tokenizer.h:18