From 3ce06585ab5d606c0c03d37ab7f8be3145fd98e6 Mon Sep 17 00:00:00 2001 From: NBonaparte Date: Wed, 6 Sep 2017 20:06:13 -0700 Subject: [PATCH] fix(parser): Revert tag stacks --- include/components/parser.hpp | 13 ++----- src/components/parser.cpp | 65 +++++++++-------------------------- 2 files changed, 18 insertions(+), 60 deletions(-) diff --git a/include/components/parser.hpp b/include/components/parser.hpp index 5f113a69..8aeba5c0 100644 --- a/include/components/parser.hpp +++ b/include/components/parser.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include "common.hpp" #include "errors.hpp" @@ -30,9 +28,8 @@ class parser { void codeblock(string&& data, const bar_settings& bar); size_t text(string&& data); - unsigned int parse_color(std::stack& color_stack, string& value, unsigned int fallback); - unsigned int parse_color_string(const string& s, unsigned int fallback = 0); - int parse_fontindex(const string& value); + unsigned int parse_color(const string& s, unsigned int fallback = 0); + int parse_fontindex(const string& s); attribute parse_attr(const char attr); mousebtn parse_action_btn(const string& data); string parse_action_cmd(string&& data); @@ -41,12 +38,6 @@ class parser { signal_emitter& m_sig; vector m_actions; unique_ptr m_parser; - - std::stack m_fg; - std::stack m_bg; - std::stack m_ul; - std::stack m_ol; - std::stack m_fonts; }; POLYBAR_NS_END diff --git a/src/components/parser.cpp b/src/components/parser.cpp index 423127d4..a7e3cbf3 100644 --- a/src/components/parser.cpp +++ b/src/components/parser.cpp @@ -45,12 +45,6 @@ void parser::parse(const bar_settings& bar, string data) { } } - m_fg = std::stack(); - m_bg = std::stack(); - m_ul = std::stack(); - m_ol = std::stack(); - m_fonts = std::stack(); - if (!m_actions.empty()) { throw unclosed_actionblocks(to_string(m_actions.size()) + " unclosed action block(s)"); } @@ -82,31 +76,29 @@ void parser::codeblock(string&& data, const bar_settings& bar) { } switch (tag) { - case 'B': { - m_sig.emit(change_background{parse_color(m_bg, value, bar.background)}); + case 'B': + m_sig.emit(change_background{parse_color(value, bar.background)}); break; - } - case 'F': { - m_sig.emit(change_foreground{parse_color(m_fg, value, bar.foreground)}); + case 'F': + m_sig.emit(change_foreground{parse_color(value, bar.foreground)}); break; - } case 'T': m_sig.emit(change_font{parse_fontindex(value)}); break; case 'U': - m_sig.emit(change_underline{parse_color(m_ul, value, bar.underline.color)}); - m_sig.emit(change_overline{parse_color(m_ol, value, bar.overline.color)}); + m_sig.emit(change_underline{parse_color(value, bar.underline.color)}); + m_sig.emit(change_overline{parse_color(value, bar.overline.color)}); break; case 'u': - m_sig.emit(change_underline{parse_color(m_ul, value, bar.underline.color)}); + m_sig.emit(change_underline{parse_color(value, bar.underline.color)}); break; case 'o': - m_sig.emit(change_overline{parse_color(m_ol, value, bar.overline.color)}); + m_sig.emit(change_overline{parse_color(value, bar.overline.color)}); break; case 'R': @@ -184,24 +176,10 @@ size_t parser::text(string&& data) { return data.size(); } -/** - * Determine color using passed stack and input value - */ -unsigned int parser::parse_color(std::stack& color_stack, string& value, unsigned int fallback) { - if (!color_stack.empty() && !value.empty() && value[0] == '-') { - color_stack.pop(); - } - auto parsed_value = parse_color_string(value, !color_stack.empty() ? color_stack.top() : fallback); - if (!value.empty() && value[0] != '-' && (color_stack.empty() || (parsed_value != color_stack.top()))) { - color_stack.push(parsed_value); - } - return parsed_value; -} - /** * Process color hex string and convert it to the correct value */ -unsigned int parser::parse_color_string(const string& s, unsigned int fallback) { +unsigned int parser::parse_color(const string& s, unsigned int fallback) { if (!s.empty() && s[0] != '-') { return color_util::parse(s, fallback); } @@ -211,26 +189,15 @@ unsigned int parser::parse_color_string(const string& s, unsigned int fallback) /** * Process font index and convert it to the correct value */ -int parser::parse_fontindex(const string& value) { - auto font_index = 0; - auto reset = value.empty() || value[0] == '-'; - - if (reset && !m_fonts.empty()) { - m_fonts.pop(); - } else if (!reset) { - try { - font_index = std::stoul(value, nullptr, 10); - m_fonts.push(font_index); - return font_index; - } catch (const std::invalid_argument& err) { - return font_index; - } +int parser::parse_fontindex(const string& s) { + if (s.empty() || s[0] == '-') { + return 0; } - if (!m_fonts.empty()) { - return m_fonts.top(); - } else { - return font_index; + try { + return std::stoul(s, nullptr, 10); + } catch (const std::invalid_argument& err) { + return 0; } }