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

antonvw / wex / 23087196341

14 Mar 2026 11:38AM UTC coverage: 64.125% (+0.003%) from 64.122%
23087196341

push

github

web-flow
1162 upgrade to llvm 22 (#1203)

* use llvm@22 instead of llvm@19

* added clang-tidy updates and code improvements

* fixes after review

18597 of 31860 branches covered (58.37%)

Branch coverage included in aggregate %.

14830 of 20268 relevant lines covered (73.17%)

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

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

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

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

56
      case address_t::ONE_ADDR:
1,734✔
57
        return address(m_ex).parse(*this);
1,734✔
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
  m_ex->m_command_parsed_data = *this;
438✔
81

82
  return true;
438✔
83
}
84

85
bool wex::command_parser::parse_other()
2,259✔
86
{
87
  marker_and_register_expansion(m_ex, m_text);
2,259✔
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,259✔
98

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

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

148
  if (m_range.empty() && m_cmd != "!")
2,259✔
149
  {
150
    m_range =
151
      (m_cmd.starts_with("g") || m_cmd == "v" || m_cmd == "w" ? "%" : ".");
1,837✔
152
  }
153

154
  return true;
2,259✔
155
}
11,295!
156

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

164
  const auto& cmds_2addr(addressrange(m_ex).regex_commands());
13✔
165

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

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

© 2026 Coveralls, Inc