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

antonvw / wex / 24938413517

25 Apr 2026 07:06PM UTC coverage: 64.281%. Remained the same
24938413517

push

github

antonvw
prevent the warning, solving not yet done

18754 of 32046 branches covered (58.52%)

Branch coverage included in aggregate %.

14955 of 20394 relevant lines covered (73.33%)

1458.02 hits per line

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

86.94
/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-2026 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,276✔
17
  ex*                ex,
18
  const std::string& text,
19
  parse_t            type)
2,276✔
20
  : command_parser_data(text)
21
  , m_ex(ex)
2,276✔
22
  , m_is_ok(m_text.empty() ? false : parse(type))
2,276✔
23
{
24
}
2,276✔
25

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

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

45
  try
46
  {
47
    switch (m_type)
2,270!
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:
450✔
60
        if (info_message_t im; !addressrange(m_ex, m_range).parse(*this, im))
450✔
61
        {
62
          return false;
12✔
63
        }
64
        else if (im != info_message_t::NONE)
438✔
65
        {
66
          m_ex->info_message(m_ex->register_text(), im);
107✔
67
        }
68
        break;
438✔
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
  // prevent warning about slicing
81
  // NOLINTNEXTLINE
82
  m_ex->m_command_parsed_data = *this;
438✔
83

84
  return true;
438✔
85
}
86

87
bool wex::command_parser::parse_other()
2,261✔
88
{
89
  ex_expansion(m_ex, m_text);
2,261✔
90

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

101
  const auto& cmds_1addr(address(m_ex).regex_commands());
2,261✔
102
  const auto& cmds_2addr(addressrange(m_ex).regex_commands());
2,261✔
103

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

150
  if (m_range.empty() && m_cmd != "!")
2,261✔
151
  {
152
    m_range =
153
      (m_cmd.starts_with("g") || m_cmd == "v" || m_cmd == "w" ? "%" : ".");
1,839✔
154
  }
155

156
  return true;
2,261✔
157
}
11,305!
158

159
bool wex::command_parser::parse_selection()
14✔
160
{
161
  if (m_ex->get_stc()->get_selected_text().empty())
14✔
162
  {
163
    return false;
1✔
164
  }
165

166
  const auto& cmds_2addr(addressrange(m_ex).regex_commands());
13✔
167

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

184
  return false;
1✔
185
}
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