Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/spider/tdl/parser/SourceLocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define SPIDER_TDL_PARSER_SOURCELOCATION_HPP

#include <cstddef>
#include <string>

#include <fmt/format.h>

namespace spider::tdl::parser {
class SourceLocation {
Expand All @@ -14,6 +17,10 @@ class SourceLocation {

[[nodiscard]] auto get_column() const noexcept -> size_t { return m_column; }

[[nodiscard]] auto serialize_to_str() const -> std::string {
return fmt::format("({}:{})", m_line, m_column);
}

[[nodiscard]] auto operator==(SourceLocation const& other) const noexcept -> bool {
return m_line == other.m_line && m_column == other.m_column;
}
Expand Down
14 changes: 10 additions & 4 deletions src/spider/tdl/parser/ast/node_impl/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,27 @@ auto Function::serialize_to_str(size_t indentation_level) const

if (false == serialized_params.empty()) {
return fmt::format(
"{}[Function]:\n{}Name:{}\n{}Return:\n{}\n{}",
"{}[Function]{}:\n{}Name:\n{}\n{}Return:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
create_indentation(indentation_level + 1),
serialized_return_type,
fmt::join(serialized_params, "\n")
);
}

return fmt::format(
"{}[Function]:\n{}Name:{}\n{}Return:\n{}\n{}No Params",
"{}[Function]{}:\n{}Name:\n{}\n{}Return:\n{}\n{}No Params",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
create_indentation(indentation_level + 1),
serialized_return_type,
create_indentation(indentation_level + 1)
Expand Down
7 changes: 6 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
namespace spider::tdl::parser::ast::node_impl {
auto Identifier::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format("{}[Identifier]:{}", create_indentation(indentation_level), m_name);
return fmt::format(
"{}[Identifier]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
m_name
);
}
} // namespace spider::tdl::parser::ast::node_impl
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/NamedVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ auto NamedVar::create(
auto NamedVar::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[NamedVar]:\n{}Id:\n{}\n{}Type:\n{}",
"{}[NamedVar]{}:\n{}Id:\n{}\n{}Type:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_id()->serialize_to_str(indentation_level + 2)),
create_indentation(indentation_level + 1),
Expand Down
7 changes: 5 additions & 2 deletions src/spider/tdl/parser/ast/node_impl/Namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ auto Namespace::serialize_to_str(size_t indentation_level) const
);

return fmt::format(
"{}[Namespace]:\n{}Name:{}\n{}",
"{}[Namespace]{}:\n{}Name:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
fmt::join(serialized_funcs, "\n")
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/spider/tdl/parser/ast/node_impl/StructSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ auto StructSpec::serialize_to_str(size_t indentation_level) const
})
);
return fmt::format(
"{}[StructSpec]:\n{}Name:{}\n{}",
"{}[StructSpec]{}:\n{}Name:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
fmt::join(serialized_fields, "\n")
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/TranslationUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ auto TranslationUnit::serialize_to_str(size_t indentation_level) const
);

return fmt::format(
"{}[TranslationUnit]:\n{}StructSpecs:\n{}\n{}Namespaces:\n{}",
"{}[TranslationUnit]{}:\n{}StructSpecs:\n{}\n{}Namespaces:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
fmt::join(serialized_struct_specs, "\n"),
create_indentation(indentation_level + 1),
Expand Down
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ auto Struct::create(std::unique_ptr<Node> name, SourceLocation source_location)
auto Struct::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Struct]]:\n{}Name:\n{}",
"{}[Type[Struct]]{}:\n{}Name:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(
// The factory function ensures that the first child is of type `Identifier`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ auto List::create(std::unique_ptr<Node> element_type, SourceLocation source_loca
auto List::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Container[List]]]:\n{}ElementType:\n{}",
"{}[Type[Container[List]]]{}:\n{}ElementType:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_element_type()->serialize_to_str(indentation_level + 2))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ auto Map::create(
auto Map::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Container[Map]]]:\n{}KeyType:\n{}\n{}ValueType:\n{}",
"{}[Type[Container[Map]]]{}:\n{}KeyType:\n{}\n{}ValueType:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_key_type()->serialize_to_str(indentation_level + 2)),
create_indentation(indentation_level + 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ auto Tuple::serialize_to_str(size_t indentation_level) const
constexpr std::string_view cTypeTag{"[Type[Container[Tuple]]]"};

if (is_empty()) {
return fmt::format("{}{}:Empty", create_indentation(indentation_level), cTypeTag);
return fmt::format(
"{}{}{}:Empty",
create_indentation(indentation_level),
cTypeTag,
get_source_location().serialize_to_str()
);
}

std::vector<std::string> serialized_children;
Expand All @@ -55,9 +60,10 @@ auto Tuple::serialize_to_str(size_t indentation_level) const
})
);
return fmt::format(
"{}{}:\n{}",
"{}{}{}:\n{}",
create_indentation(indentation_level),
cTypeTag,
get_source_location().serialize_to_str(),
fmt::join(serialized_children, "\n")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Bool::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format("{}[Type[Primitive[Bool]]]", create_indentation(indentation_level));
return fmt::format(
"{}[Type[Primitive[Bool]]]{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str()
);
}
} // namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Float::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Primitive[Float]]]:{}",
"{}[Type[Primitive[Float]]]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
YSTDLIB_ERROR_HANDLING_TRYX(serialize_float_spec(m_spec))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Int::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Primitive[Int]]]:{}",
"{}[Type[Primitive[Int]]]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
YSTDLIB_ERROR_HANDLING_TRYX(serialize_int_spec(m_spec))
);
}
Expand Down
Loading