Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is finally time to commit the entire syntax highlighting code and first is always the pattern language #115

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3831d31
feat: Last changes for syntax highlighting. Better parser support for…
paxcut May 20, 2024
9ff197c
Merge branch 'WerWolv:master' into preprocessor_improvements
paxcut May 22, 2024
ed41418
fix: the debugger uses locations to set the line of the text editor w…
paxcut May 25, 2024
e527553
Merge remote-tracking branch 'origin/preprocessor_improvements' into …
paxcut May 25, 2024
c85643c
Merge branch 'master' into preprocessor_improvements
WerWolv Jun 25, 2024
bdb8d6d
Merge remote-tracking branch 'origin/preprocessor_improvements' into …
paxcut Aug 2, 2024
44bac40
It is finally time to commit the entire syntax highlighting code and …
paxcut Aug 2, 2024
d5a0fb1
Merge branch 'WerWolv:master' into preprocessor_improvements
paxcut Aug 3, 2024
c92e341
fix: Function variables were being labeled as member variables. Views…
paxcut Aug 3, 2024
9085f1c
Fix: There were still cases of function variables identified as membe…
paxcut Aug 4, 2024
5137218
Fix: When a string ends prematurely with a newline, the newline wasn'…
paxcut Aug 6, 2024
92c24c3
Fix: fix for issue 1283. If a templated template struct had a non-typ…
paxcut Aug 8, 2024
b047664
Merge branch 'WerWolv:master' into preprocessor_improvements
paxcut Aug 10, 2024
1154aa3
Fix: If last statement is a directive or a comment then the end of pr…
paxcut Aug 10, 2024
2173dde
Fix: As originally coded the IMPORTED mechanic created to select out …
paxcut Aug 12, 2024
1a897e3
fix: if a windows style path delimiter was used in an include directi…
paxcut Aug 16, 2024
b3d13f3
fix: the previous fix to help highlight namespaces was not applied to…
paxcut Aug 16, 2024
805bd49
Merge branch 'WerWolv:master' into preprocessor_improvements
paxcut Aug 20, 2024
431d200
Merge branch 'WerWolv:master' into preprocessor_improvements
paxcut Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/include/pl/core/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace pl::core {
bool processToken(auto parserFunction, const std::string_view& identifier);
Location location() override;

std::optional<char> parseCharacter();
std::optional<char> parseCharacter(bool isWindowsPath=false);
std::optional<Token> parseOperator();
std::optional<Token> parseSeparator();
std::optional<Token> parseOneLineComment();
Expand All @@ -40,7 +40,7 @@ namespace pl::core {
std::optional<Token> parseConstant(const std::string_view &identifier);
std::optional<Token> parseStringLiteral();
std::optional<Token> parseDirectiveArgument();
std::optional<Token> parseDirectiveValue();
std::optional<Token> parseDirectiveValue(bool forInclude=false);
std::optional<Token::Literal> parseIntegerLiteral(std::string_view literal);

std::optional<double> parseFloatingPoint(std::string_view literal, char suffix);
Expand Down
8 changes: 4 additions & 4 deletions lib/include/pl/core/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ namespace pl::core {
hlp::safe_unique_ptr<ast::ASTNode> parseUnaryExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseMultiplicativeExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseAdditiveExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseShiftExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryAndExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryXorExpression();
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryOrExpression(bool inMatchRange);
hlp::safe_unique_ptr<ast::ASTNode> parseShiftExpression(bool inTemplate);
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryAndExpression(bool inTemplate);
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryXorExpression(bool inTemplate);
hlp::safe_unique_ptr<ast::ASTNode> parseBinaryOrExpression(bool inTemplate, bool inMatchRange);
hlp::safe_unique_ptr<ast::ASTNode> parseBooleanAnd(bool inTemplate, bool inMatchRange);
hlp::safe_unique_ptr<ast::ASTNode> parseBooleanXor(bool inTemplate, bool inMatchRange);
hlp::safe_unique_ptr<ast::ASTNode> parseBooleanOr(bool inTemplate, bool inMatchRange);
Expand Down
50 changes: 40 additions & 10 deletions lib/include/pl/core/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,59 @@ namespace pl::core {
hlp::CompileResult<std::vector<Token>> preprocess(PatternLanguage *runtime, api::Source* source, bool initialRun = true);

void addDefine(const std::string &name, const std::string &value = "");
void removeDefine(const std::string &name);
void addPragmaHandler(const std::string &pragmaType, const api::PragmaHandler &handler);
void addDirectiveHandler(const Token::Directive &directiveType, const api::DirectiveHandler &handler);
void removePragmaHandler(const std::string &pragmaType);
void removeDirectiveHandler(const Token::Directive &directiveType);
void validateExcludedLocations();
void appendExcludedLocation(const ExcludedLocation &location);

void validateOutput();

[[nodiscard]] auto getExcludedLocations() const {
[[nodiscard]] const std::vector<ExcludedLocation> &getExcludedLocations() const {
return m_excludedLocations;
}

[[nodiscard]] auto getResult() const {
return this->m_result;
[[nodiscard]] const std::vector<Token> &getResult() {
return m_result;
}

[[nodiscard]] auto getOutput() const {
return this->m_output;
}

void setOutput(std::vector<pl::core::Token> tokens) {
m_output = tokens;
void setOutput(const std::vector<pl::core::Token> &tokens) {
u32 j =0;
auto tokenCount = m_result.size();
for (auto token : tokens) {
if (auto identifier = std::get_if<Token::Identifier>(&token.value); identifier != nullptr) {
if (auto type = identifier->getType(); type > Token::Identifier::IdentifierType::ScopeResolutionUnknown) {
auto location = token.location;
if (location.source->source != "<Source Code>")
continue;
auto line = location.line;
auto column = location.column;
while (m_result[j].location.line < line) {
if (j >= tokenCount)
break;
j++;
}
while (m_result[j].location.column < column) {
if (j >= tokenCount)
break;
j++;
}
if (auto identifier2 = std::get_if<Token::Identifier>(&m_result[j].value); identifier2 != nullptr)
identifier2->setType(type);
}
}
}
}

[[nodiscard]] auto getErrors() const {
[[nodiscard]] const std::vector<err::CompileError> &getErrors() const {
return this->m_errors;
}

void setErrors(std::vector<err::CompileError> errors) {
void setErrors(const std::vector<err::CompileError> &errors) {
m_errors = errors;
}

Expand All @@ -70,11 +94,15 @@ namespace pl::core {
return m_initialized;
}

[[nodiscard]] const api::Resolver& getResolver() const {
return m_resolver;
}

void setResolver(const api::Resolver& resolvers) {
m_resolver = resolvers;
}

auto getNamespaces() const {
const std::vector<std::string> getNamespaces() const {
return m_namespaces;
}

Expand All @@ -85,6 +113,7 @@ namespace pl::core {
bool eof();
Location location() override;
void removeKey(const Token &token);
void nextLine(u32 line);
// directive handlers
void handleIfDef(u32 line);
void handleIfNDef(u32 line);
Expand All @@ -103,6 +132,7 @@ namespace pl::core {
std::unordered_map<Token::Directive, api::DirectiveHandler> m_directiveHandlers;

std::unordered_map<std::string, std::vector<Token>> m_defines;
std::map<std::string, std::string> m_addedDefines;
std::unordered_map<std::string, std::vector<std::pair<std::string, u32>>> m_pragmas;
std::vector<ExcludedLocation> m_excludedLocations;

Expand Down
5 changes: 3 additions & 2 deletions lib/include/pl/core/token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ namespace pl::core {
Typedef,
Function,
UDT,
View,
FunctionVariable,
FunctionParameter,
PatternLocalVariable,
PatternPlacedVariable,
LocalVariable,
CalculatedPointer,
TemplateArgument,
PatternVariable,
GlobalVariable,
Expand Down
4 changes: 0 additions & 4 deletions lib/include/pl/pattern_language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@ namespace pl {
return this->m_defines;
}

[[nodiscard]] const std::vector<std::shared_ptr<core::ast::ASTNode>> getAST() const {
return this->m_currAST;
}

[[nodiscard]] const std::map<std::string, api::PragmaHandler>& getPragmas() const {
return this->m_pragmas;
}
Expand Down
27 changes: 18 additions & 9 deletions lib/source/pl/core/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ namespace pl::core {
}


std::optional<char> Lexer::parseCharacter() {
std::optional<char> Lexer::parseCharacter(bool isWindowsPath) {
const char& c = m_sourceCode[m_cursor++];
if (c == '\\') {
if (c == '\\' && !isWindowsPath) {
switch (m_sourceCode[m_cursor++]) {
case 'a':
return '\a';
Expand Down Expand Up @@ -118,15 +118,15 @@ namespace pl::core {
return std::nullopt;
}

std::optional<Token> Lexer::parseDirectiveValue() {
std::optional<Token> Lexer::parseDirectiveValue(bool forInclude) {
std::string result;

m_cursor++; // Skip space
auto location = this->location();

while (!std::isblank(m_sourceCode[m_cursor]) && !std::isspace(m_sourceCode[m_cursor]) && m_sourceCode[m_cursor] != '\0' ) {

auto character = parseCharacter();
auto character = parseCharacter(forInclude);
if (!character.has_value()) {
return std::nullopt;
}
Expand Down Expand Up @@ -176,9 +176,17 @@ namespace pl::core {

while (m_sourceCode[m_cursor] != '\"') {
char c = peek();
if (c == '\n' || c == '\0') {
if (c == '\n') {
m_errorLength = 1;
error("Unexpected newline in string literal");
m_line++;
m_lineBegin = m_cursor;
return std::nullopt;
}

if (c == '\0') {
m_errorLength = 1;
error(c == '\n' ? "Unexpected newline in string literal" : "Unexpected end of file in string literal");
error("Unexpected end of file in string literal");
return std::nullopt;
}

Expand Down Expand Up @@ -599,15 +607,16 @@ namespace pl::core {
if (processToken(&Lexer::parseDirectiveName, directiveName)) {
Token::Directive directive = get<Token::Directive>(m_tokens.back().value);
if (m_line != line || directive == Token::Directive::Define || directive == Token::Directive::Undef ||
peek(0) == 0 || directive == Token::Directive::IfDef || directive == Token::Directive::IfNDef)
peek(0) == 0 || directive == Token::Directive::IfDef || directive == Token::Directive::IfNDef ||
directive == Token::Directive::EndIf)
continue;
if (peek(0) == '\n') {
m_line++;
m_lineBegin = m_cursor;
m_cursor++;
continue;
}
auto directiveValue = parseDirectiveValue();
auto directiveValue = parseDirectiveValue(directive == Token::Directive::Include);
if (directiveValue.has_value()) {
addToken(directiveValue.value());
if (m_line != line || peek(0) == 0)
Expand Down Expand Up @@ -661,7 +670,7 @@ namespace pl::core {
m_cursor++;
}

addToken(makeToken(Separator::EndOfProgram));
addToken(makeToken(Separator::EndOfProgram,0));

return { m_tokens, collectErrors() };
}
Expand Down
Loading
Loading