Skip to content

Commit

Permalink
preprocessor/lexer: improve lexer and preprocessor and add length to …
Browse files Browse the repository at this point in the history
…locations
  • Loading branch information
jumanji144 committed Nov 12, 2023
1 parent 867f039 commit 13c07e7
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 131 deletions.
3 changes: 2 additions & 1 deletion lib/include/pl/core/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace pl::core {
std::optional<double> parseFloatingPoint(std::string_view literal, char suffix);
std::optional<u128> parseInteger(std::string_view literal);

Token makeToken(const Token& token);
Token makeToken(const Token& token, size_t length = 1);
static Token makeTokenAt(const Token& token, Location& location, size_t length = 1);
void addToken(const Token& token);

std::string m_sourceCode;
Expand Down
3 changes: 2 additions & 1 deletion lib/include/pl/core/location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ namespace pl::core {

api::Source* source;
u32 line, column;
size_t length;

};

static constexpr api::Source* EmptySource = nullptr;
static constexpr Location EmptyLocation = { EmptySource, 0, 0 };
static constexpr Location EmptyLocation = { EmptySource, 0, 0, 0 };
static constexpr std::string DefaultSource = "<Source Code>";

}
2 changes: 1 addition & 1 deletion lib/include/pl/pattern_language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace pl {
* @brief Sets the console log callback
* @param callback Callback to call
*/
void setLogCallback(const core::LogConsole::Callback &callback);
void setLogCallback(const core::LogConsole::Callback &callback) const;

/**
* @brief Gets the error that occurred during the last execution
Expand Down
5 changes: 3 additions & 2 deletions lib/source/pl/core/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ namespace pl::core::err {
errorMessage += fmt::format("{}{}\n", lineNumberPrefix, errorLine);

{
const auto descriptionSpacing = std::string(lineNumberPrefix.length() + arrowPosition, ' ');
errorMessage += descriptionSpacing + "^\n";
const auto arrowSpacing = std::string(lineNumberPrefix.length() + arrowPosition, ' ');
// add arrow with length of the token
errorMessage += arrowSpacing + std::string(location.length, '^') + '\n';
}
}
}
Expand Down
Loading

0 comments on commit 13c07e7

Please sign in to comment.