Skip to content

Commit

Permalink
[Feature] Added single & multi-line comments (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Vedant <[email protected]>
  • Loading branch information
vrnimje authored Oct 16, 2023
1 parent 64e0b43 commit 375425d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 4 additions & 0 deletions examples/Button.qf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ LightBorder Vertical{
str y = "Test"
str z = "init"
str a
// This is a nested block
DashedBorder Horizontal {
Red Button {
"ls -l",
Expand All @@ -19,6 +20,9 @@ LightBorder Vertical{
}
}
Heavy separator
/*
Exits the UI
*/
Text("This button exits the TUI")
Button {
"Exit",
Expand Down
2 changes: 2 additions & 0 deletions examples/multiple_components.qf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ DoubleBorder Vertical{
}
}

// Separator here!!

Dashed separator

RedLight Button {
Expand Down
1 change: 1 addition & 0 deletions examples/text.qf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Vertical {
// Text demo
BlueLight bold Text("The given button opens chrome in Linux")
str a
Red Button {
Expand Down
31 changes: 20 additions & 11 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/recursive_variant.hpp>

#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/mouse.hpp" // for ftxui
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/component.hpp" // for Components
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for Options
#include "ftxui/component/mouse.hpp" // for ftxui
#include "ftxui/component/screen_interactive.hpp" // for screen
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
#include "ftxui/screen/screen.hpp"
#include "ftxui/util/ref.hpp" // for Ref
Expand Down Expand Up @@ -665,9 +665,6 @@ struct node_printer : boost::static_visitor<> {
}

void operator()(quick_ftxui_ast::dom_text const &text) const {
// tab(indent + tabsize);
// std::cout << "nil: \"" << text << '"' << std::endl;

switch (text.style) {
case quick_ftxui_ast::text_style::none:
data->components.push_back(ftxui::Renderer([&] {
Expand Down Expand Up @@ -742,8 +739,7 @@ struct node_printer : boost::static_visitor<> {
}

void operator()(quick_ftxui_ast::separator const &text) const {
// tab(indent + tabsize);
// std::cout << "nil: \"" << text << '"' << std::endl;

// clang-format off
switch (text.style) {
case quick_ftxui_ast::sep_style::Normal:
Expand Down Expand Up @@ -974,9 +970,17 @@ struct parser
para_comp %=
-(color_kw) >> qi::lit("Paragraph") >> '(' >> quoted_string >> ')';

single_line_comment =
qi::lit("//") >> *(char_ - qi::eol) >> (qi::eol | qi::eoi);

multi_line_comment =
qi::lit("/*") >> *(multi_line_comment | char_ - "*/") > qi::lit("*/");

skipper = single_line_comment | multi_line_comment;

node = button_comp | input_comp | slider_comp | menu_comp | toggle_comp |
drpdwn_comp | text_comp | int_var_decl | str_var_decl | sep_comp |
para_comp | expression;
para_comp | skipper | expression;

expression = -(border_kw) >> alignment_kw >> '{' >> *node >> '}';

Expand Down Expand Up @@ -1006,6 +1010,7 @@ struct parser
qi::rule<Iterator, quick_ftxui_ast::dom_text(), ascii::space_type> text_comp;
qi::rule<Iterator, quick_ftxui_ast::separator(), ascii::space_type> sep_comp;
qi::rule<Iterator, quick_ftxui_ast::paragraph(), ascii::space_type> para_comp;
qi::rule<Iterator> single_line_comment, multi_line_comment, skipper;
qi::symbols<char, quick_ftxui_ast::block_alignment> alignment_kw;
qi::symbols<char, quick_ftxui_ast::button_option> buttonopt_kw;
qi::symbols<char, quick_ftxui_ast::input_option> inputopt_kw;
Expand Down Expand Up @@ -1116,6 +1121,10 @@ void parse_qf(std::string source_code) {
}
}

///////////////////////////////////////////////////////////////////////////
// Variable interfacing
///////////////////////////////////////////////////////////////////////////

int get_int(std::string var_name) {
if (auto It = quick_ftxui_ast::numbers.find(std::string(var_name));
It != quick_ftxui_ast::numbers.end()) {
Expand Down

0 comments on commit 375425d

Please sign in to comment.