Skip to content

Commit

Permalink
modify iter object to behave optionally
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze7111 committed Jul 3, 2024
1 parent 0a461a2 commit 5236f11
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 371 deletions.
7 changes: 7 additions & 0 deletions source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ int main() {
// print the preprocessed tokens
print_tokens(tokens);

for (auto &tok_ref : tokens) {
if (tok_ref->token_kind() == tokens::KEYWORD_FUNCTION) {
tok_ref.peek();
std::cout << tok_ref.peek()->get().value() << "\n";
}
}

// Print the time taken in nanoseconds and milliseconds
print("time taken: ", diff.count() * 1e+9, " ns");
print(" ", diff.count() * 1000, " ms");
Expand Down
3 changes: 3 additions & 0 deletions source/parser/ast/include/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#ifndef __CONTEXT_HH__
#define __CONTEXT_HH__

#include <map>
#include "parser/ast/include/nodes.hh"

namespace ast {
class ASTContext {

Expand Down
2 changes: 1 addition & 1 deletion source/parser/ast/include/nodes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct Variable : AstNode<Variable> { // a: int<8> | a: i32 = 5 | a: i32? = nul
AstNodePtr value; // 5 | null
bool is_nullable;
Token reference; // & | &&
Token pointer; // * | *
Token pointer; // *
explicit Variable(AstNodeRef<Identifier> name, AstNodeRef<GenericArgument> type,
AstNodePtr value, bool is_nullable = false, Token reference = Token(),
Token pointer = Token());
Expand Down
2 changes: 1 addition & 1 deletion source/parser/ast/include/parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Parser {
std::unique_ptr<ast::ProgramNode> parse() {
token::tokens current_token_type{};

for (auto it = tokens.begin(); it != tokens.end();) {
for (auto it = tokens.cbegin(); it != tokens.cend();) {
const token::Token &current_token = *it;
current_token_type = current_token.token_kind();

Expand Down
8 changes: 4 additions & 4 deletions source/parser/preprocessor/include/preprocessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ struct import_helix {
std::string get_module() {
std::string mod;

for (auto const &tok : module) {
mod += tok.value();
for (auto &tok : module) {
mod += tok->value();
}

return mod;
Expand All @@ -138,8 +138,8 @@ struct import_helix {
std::string get_namespace() {
std::string name_space;

for (auto const &tok : relative) {
name_space += tok.value();
for (auto &tok : relative) {
name_space += tok->value();
}

return name_space;
Expand Down
12 changes: 6 additions & 6 deletions source/parser/preprocessor/source/preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool is_circular_import(const std::shared_ptr<preprocessor::ImportNode> &node) {
std::shared_ptr<preprocessor::ImportNode> current = node;

while (current != nullptr) {
if (visited.find(current->module_name) != visited.end()) {
if (visited.find(current->module_name) != visited.cend()) {
return true; // Circular import detected
}
visited.insert(current->module_name);
Expand Down Expand Up @@ -222,16 +222,16 @@ Preprocessor::parse_import(std::unique_ptr<preprocessor::ImportTree> &import_tre

parsed_source = Preprocessor(parsed_source).parse(current_node);
parsed_source.pop_back();
parsed_source.insert(parsed_source.begin(),
parsed_source.insert(parsed_source.cbegin(),
Token(tokens::PUNCTUATION_OPEN_BRACE, string_import_path));

for (auto const &tok : std::ranges::reverse_view(namespace_name)) {
parsed_source.insert(parsed_source.begin(), tok);
for (auto it = namespace_name.rbegin(); it != namespace_name.rend(); ++it) {
parsed_source.insert(parsed_source.cbegin(), *it);
}

parsed_source.insert(parsed_source.begin(),
parsed_source.insert(parsed_source.cbegin(),
Token(tokens::KEYWORD_NAMESPACE, string_import_path));
parsed_source.insert(parsed_source.end(),
parsed_source.insert(parsed_source.cend(),
Token(tokens::PUNCTUATION_CLOSE_BRACE, string_import_path));

complete_import = {
Expand Down
Loading

0 comments on commit 5236f11

Please sign in to comment.