#pragma once

#include "katom.h"
#include "state.h"


std::string to_string(std::vector<Katom>::const_iterator begin, std::vector<Katom>::const_iterator end, bool trim_result=false);
std::string to_string(const std::vector<Katom>& katoms, bool trim_result=false);

// std::vector<Katom> process_katoms(
//     const std::string& s, State& state, const std::string& source,
//     bool nonascii=true, bool literal=true, bool ignore=true, bool whitespace=true,
//     bool klammers=true, bool eval=true, bool cond=true, bool read=true);

bool level_increase(const Katom& k);
bool level_decrease(const Katom& k);

const katom_list::iterator
find_katom_named(const katom_list::iterator begin, const katom_list::iterator end, std::string name);

const std::vector<Katom>::iterator
find_katom(const std::vector<Katom>::iterator begin, const std::vector<Katom>::iterator end, size_t index);

std::vector<std::pair<Katom, Katom>>
find_spans(std::vector<Katom>::iterator begin, std::vector<Katom>::iterator end,
           const std::function<bool(const Katom&)>& level_inc,
           const std::function<bool(const Katom&)>& level_dec,
           bool error_exit,
           const std::string& name);

std::vector<std::pair<Katom, Katom>>
find_spans(std::vector<Katom>& katoms,
           const std::function<bool(const Katom&)>& level_inc,
           const std::function<bool(const Katom&)>& level_dec,
           bool error_exit=true,
           const std::string& name="all");


void describe_spans(const std::vector<Katom>& katoms);

std::pair<std::vector<Katom>::iterator, std::vector<Katom>::iterator>
find_span_katoms(std::vector<Katom>& katoms, const Katom& begin, const Katom& end);

std::pair<std::vector<Katom>::iterator, std::vector<Katom>::iterator>
find_span_katoms(
    std::vector<Katom>::iterator kbegin, std::vector<Katom>::iterator kend, const Katom& begin, const Katom& end);

void encode_nonascii_characters(std::vector<Katom>& katoms);
void mark_literal_katoms(std::vector<Katom>& katoms);
void hide_special_katoms(std::vector<Katom>& katoms);
void mark_ignored_katoms(std::vector<Katom>& katoms);

void process_klammer_katoms(std::vector<Katom>& katoms);
