• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antonvw / wex / 19191287701

08 Nov 2025 09:37AM UTC coverage: 64.338% (+0.07%) from 64.268%
19191287701

push

github

web-flow
1069 fix vi global move command (#1071)

* vi global move and copy fixes

* added separate files

* added more tests on move

* more updates

* minor updates

* all tests pass

* whitespace update

18424 of 31402 branches covered (58.67%)

Branch coverage included in aggregate %.

14656 of 20014 relevant lines covered (73.23%)

1529.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.76
/src/ex/command-parser.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
// Name:      command-parser.cpp
3
// Purpose:   Implementation of class wex::command_parser
4
// Author:    Anton van Wezenbeek
5
// Copyright: (c) 2021-2025 Anton van Wezenbeek
6
////////////////////////////////////////////////////////////////////////////////
7

8
#include <boost/algorithm/string.hpp>
9
#include <wex/core/log.h>
10
#include <wex/ex/addressrange.h>
11
#include <wex/ex/command-parser.h>
12
#include <wex/ex/ex.h>
13
#include <wex/factory/control.h>
14
#include <wex/syntax/stc.h>
15

16
wex::command_parser::command_parser(
2,270✔
17
  ex*                ex,
18
  const std::string& text,
19
  parse_t            type)
2,270✔
20
  : command_parser_data(text)
21
  , m_ex(ex)
2,270✔
22
{
23
  m_is_ok = m_text.empty() ? false : parse(type);
2,270✔
24
}
2,270✔
25

26
bool wex::command_parser::parse(parse_t type)
2,269✔
27
{
28
  if (m_text.starts_with(ex_command::selection_range()))
2,269✔
29
  {
30
    if (!parse_selection())
14✔
31
    {
32
      return false;
2✔
33
    }
34
  }
35
  else if (!parse_other())
2,255!
36
  {
37
    return false;
×
38
  }
39

40
  if (type == parse_t::CHECK)
2,267✔
41
  {
42
    return true;
3✔
43
  }
44

45
  try
46
  {
47
    switch (m_type)
2,264!
48
    {
49
      case address_t::NO_ADDR:
85✔
50
      {
51
        m_range.clear();
85✔
52
        const auto line(address(m_ex, m_text).get_line());
85✔
53
        return m_ex->get_stc()->inject(data::control().line(line));
85✔
54
      }
55

56
      case address_t::ONE_ADDR:
1,735✔
57
        return address(m_ex).parse(*this);
1,735✔
58

59
      case address_t::TWO_ADDR:
444✔
60
        if (info_message_t im; !addressrange(m_ex, m_range).parse(*this, im))
444✔
61
        {
62
          return false;
13✔
63
        }
64
        else if (im != info_message_t::NONE)
431✔
65
        {
66
          m_ex->info_message(m_ex->register_text(), im);
99✔
67
        }
68
        break;
431✔
69

70
      default:
×
71
        assert(0);
×
72
    }
73
  }
74
  catch (std::exception& e)
×
75
  {
76
    log(e) << m_cmd;
×
77
    return false;
×
78
  }
×
79

80
  m_ex->m_command_parsed_data = *this;
431✔
81

82
  return true;
431✔
83
}
84

85
bool wex::command_parser::parse_other()
2,255✔
86
{
87
  marker_and_register_expansion(m_ex, m_text);
2,255✔
88

89
  // Addressing in ex.
90
  // See also address::get_line
91
  const std::string addr(
92
    // (1) . (2) $ (3) decimal number, + or - (7)
93
    "[\\.\\$0-9\\+\\-]+|"
94
    // (4) marker
95
    "'[a-z]|"
96
    // (5) (6) regex find, non-greedy!
97
    "[-+]?[0-9]*[\\?/].*?[\\?/][-+]?[0-9]*");
2,255✔
98

99
  const auto& cmds_1addr(address(m_ex).regex_commands());
2,255✔
100
  const auto& cmds_2addr(addressrange(m_ex).regex_commands());
2,255✔
101

102
  if (regex v({// 2addr % range
2,255✔
103
               {"^%" + cmds_2addr,
×
104
                [&](const regex::match_t& m)
×
105
                {
106
                  m_type  = address_t::TWO_ADDR;
40✔
107
                  m_range = "%";
40✔
108
                  m_cmd   = m[0];
40✔
109
                  m_text  = m[1];
40✔
110
                }},
40✔
111
               // 1addr (or none)
112
               {"^(" + addr + ")?" + cmds_1addr,
4,510✔
113
                [&](const regex::match_t& m)
×
114
                {
115
                  m_type  = address_t::ONE_ADDR;
1,735✔
116
                  m_range = m[0];
1,735✔
117
                  m_cmd   = m[1];
1,735✔
118
                  m_text  = boost::algorithm::trim_left_copy(m[2]);
1,735✔
119
                  log::trace("ex 1addr") << m_range;
1,735✔
120
                }},
1,735✔
121
               // 2addr
122
               {"^(" + addr + "),(" + addr + ")" + cmds_2addr,
4,510✔
123
                [&](const regex::match_t& m)
×
124
                {
125
                  m_type  = address_t::TWO_ADDR;
122✔
126
                  m_range = m[0] + "," + m[1];
122✔
127
                  m_cmd   = m[2];
122✔
128
                  m_text  = m[3];
122✔
129
                  log::trace("ex 2addr") << m_range;
122✔
130
                }},
122✔
131
               // 2addr
132
               {"^(" + addr + ")?" + cmds_2addr,
4,510✔
133
                [&](const regex::match_t& m)
2,255✔
134
                {
135
                  m_type  = address_t::TWO_ADDR;
272✔
136
                  m_range = m[0];
272✔
137
                  m_cmd   = m[1];
272✔
138
                  m_text  = m[2];
272✔
139
                  log::trace("ex 2addr") << m_range;
272✔
140
                }}});
13,802!
141
      v.match(m_text) <= 1)
2,255✔
142
  {
143
    m_type = address_t::NO_ADDR;
86✔
144
  }
2,255✔
145

146
  if (m_range.empty() && m_cmd != "!")
2,255✔
147
  {
148
    m_range =
149
      (m_cmd.starts_with("g") || m_cmd == "v" || m_cmd == "w" ? "%" : ".");
1,840✔
150
  }
151

152
  return true;
2,255✔
153
}
11,275!
154

155
bool wex::command_parser::parse_selection()
14✔
156
{
157
  if (m_ex->get_stc()->get_selected_text().empty())
14✔
158
  {
159
    return false;
1✔
160
  }
161

162
  const auto& cmds_2addr(addressrange(m_ex).regex_commands());
13✔
163

164
  if (regex r(
13✔
165
        {{ex_command::selection_range() + cmds_2addr,
26✔
166
          [&](const regex::match_t& m)
13✔
167
          {
168
            m_type  = address_t::TWO_ADDR;
12✔
169
            m_range = ex_command::selection_range();
12✔
170
            m_cmd   = m[0];
12✔
171
            m_text  = m[1];
12✔
172
            log::trace("ex selection") << m_range;
12✔
173
          }}});
51!
174
      r.match(m_text) == 2)
13✔
175
  {
176
    return true;
12✔
177
  }
13✔
178

179
  return false;
1✔
180
}
39!
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc