summaryrefslogtreecommitdiffstats
path: root/src/document.sections.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/document.sections.hh')
-rw-r--r--src/document.sections.hh48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/document.sections.hh b/src/document.sections.hh
index 94cd01a..9129cf5 100644
--- a/src/document.sections.hh
+++ b/src/document.sections.hh
@@ -31,6 +31,7 @@
#define lnav_attr_line_breadcrumbs_hh
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -40,6 +41,7 @@
#include "intervaltree/IntervalTree.h"
#include "mapbox/variant.hpp"
#include "optional.hpp"
+#include "text_format.hh"
namespace lnav {
namespace document {
@@ -48,6 +50,16 @@ using section_key_t = mapbox::util::variant<std::string, size_t>;
using section_interval_t = interval_tree::Interval<file_off_t, section_key_t>;
using sections_tree_t = interval_tree::IntervalTree<file_off_t, section_key_t>;
+enum class section_types_t {
+ comment,
+ multiline_string,
+};
+
+using section_type_interval_t
+ = interval_tree::Interval<file_off_t, section_types_t>;
+using section_types_tree_t
+ = interval_tree::IntervalTree<file_off_t, section_types_t>;
+
struct hier_node {
hier_node* hn_parent{nullptr};
file_off_t hn_start{0};
@@ -57,6 +69,18 @@ struct hier_node {
nonstd::optional<hier_node*> lookup_child(section_key_t key) const;
+ nonstd::optional<size_t> child_index(const hier_node* hn) const;
+
+ struct child_neighbors_result {
+ nonstd::optional<const hier_node*> cnr_previous;
+ nonstd::optional<const hier_node*> cnr_next;
+ };
+
+ nonstd::optional<child_neighbors_result> child_neighbors(
+ const hier_node* hn, file_off_t offset) const;
+
+ nonstd::optional<child_neighbors_result> line_neighbors(size_t ln) const;
+
nonstd::optional<size_t> find_line_number(const std::string& str) const
{
auto iter = this->hn_named_children.find(str);
@@ -101,6 +125,11 @@ struct hier_node {
struct metadata {
sections_tree_t m_sections_tree;
std::unique_ptr<hier_node> m_sections_root;
+ section_types_tree_t m_section_types_tree;
+ std::set<size_t> m_indents;
+ text_format_t m_text_format{text_format_t::TF_UNKNOWN};
+
+ std::vector<section_key_t> path_for_range(size_t start, size_t stop);
std::vector<breadcrumb::possibility> possibility_provider(
const std::vector<section_key_t>& path);
@@ -108,9 +137,26 @@ struct metadata {
metadata discover_metadata(const attr_line_t& al);
-metadata discover_structure(attr_line_t& al, struct line_range lr);
+metadata discover_structure(attr_line_t& al,
+ struct line_range lr,
+ text_format_t tf = text_format_t::TF_UNKNOWN);
} // namespace document
} // namespace lnav
+namespace fmt {
+template<>
+struct formatter<lnav::document::section_key_t> : formatter<string_view> {
+ auto format(const lnav::document::section_key_t& p, format_context& ctx)
+ -> decltype(ctx.out()) const;
+};
+
+template<>
+struct formatter<std::vector<lnav::document::section_key_t>>
+ : formatter<string_view> {
+ auto format(const std::vector<lnav::document::section_key_t>& p,
+ format_context& ctx) -> decltype(ctx.out()) const;
+};
+} // namespace fmt
+
#endif