mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 14:31:11 +01:00
ircd: Add mutable_buffer ctor to parse::buffer; cleanup parse related.
This commit is contained in:
parent
9d4c2fb5c3
commit
fccfa03308
3 changed files with 13 additions and 64 deletions
|
@ -45,20 +45,6 @@ struct ircd::parse
|
|||
struct buffer;
|
||||
};
|
||||
|
||||
struct ircd::parse::grammar
|
||||
{
|
||||
static std::map<std::string_view, const grammar *> grammars;
|
||||
|
||||
const char *const name;
|
||||
|
||||
private:
|
||||
decltype(grammars)::const_iterator grammars_it;
|
||||
|
||||
public:
|
||||
grammar(const char *const &name);
|
||||
~grammar() noexcept;
|
||||
};
|
||||
|
||||
struct ircd::parse::buffer
|
||||
{
|
||||
char *base; // Lowest address of the buffer (const)
|
||||
|
@ -74,28 +60,24 @@ struct ircd::parse::buffer
|
|||
void discard();
|
||||
void remove();
|
||||
|
||||
buffer(const buffer &old, char *const &start, char *const &stop)
|
||||
:base{start}
|
||||
,parsed{start}
|
||||
,read{start + old.unparsed()}
|
||||
buffer(const buffer &old, const mutable_buffer &mb)
|
||||
:base{data(mb)}
|
||||
,parsed{data(mb)}
|
||||
,read{data(mb) + old.unparsed()}
|
||||
,stop{stop}
|
||||
{
|
||||
memmove(base, old.base, old.unparsed());
|
||||
}
|
||||
|
||||
buffer(char *const &start, char *const &stop)
|
||||
:base{start}
|
||||
,parsed{start}
|
||||
,read{start}
|
||||
,stop{stop}
|
||||
buffer(const mutable_buffer &mb)
|
||||
:base{data(mb)}
|
||||
,parsed{data(mb)}
|
||||
,read{data(mb)}
|
||||
,stop{data(mb) + ircd::size(mb)}
|
||||
{}
|
||||
|
||||
template<size_t N> buffer(const buffer &old, char (&buf)[N])
|
||||
:buffer{old, buf, buf + N}
|
||||
{}
|
||||
|
||||
template<size_t N> buffer(char (&buf)[N])
|
||||
:buffer{buf, buf + N}
|
||||
:buffer{old, buf}
|
||||
{}
|
||||
};
|
||||
|
||||
|
|
|
@ -130,7 +130,6 @@ template<class it,
|
|||
class top>
|
||||
struct ircd::http::grammar
|
||||
:qi::grammar<it, top>
|
||||
,parse::grammar
|
||||
{
|
||||
template<class R = unused_type, class... S> using rule = qi::rule<it, R, S...>;
|
||||
|
||||
|
@ -218,15 +217,11 @@ struct ircd::http::grammar
|
|||
,"response"
|
||||
};
|
||||
|
||||
grammar(const rule<top> &top_rule, const char *const &name)
|
||||
grammar(const rule<top> &top_rule)
|
||||
:grammar<it, top>::base_type
|
||||
{
|
||||
top_rule
|
||||
}
|
||||
,parse::grammar
|
||||
{
|
||||
name
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -236,7 +231,7 @@ struct ircd::http::parser
|
|||
static size_t content_length(const string_view &val);
|
||||
|
||||
using http::grammar<const char *, unused_type>::grammar;
|
||||
parser(): grammar { grammar::ws, "http.request" } {}
|
||||
parser(): grammar { grammar::ws } {}
|
||||
}
|
||||
const ircd::http::parser;
|
||||
|
||||
|
|
|
@ -19,37 +19,9 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//#include <boost/spirit/include/qi.hpp>
|
||||
//#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
namespace ircd {
|
||||
|
||||
// Registry of grammars. Grammars are usualy static data or modules.
|
||||
IRCD_INIT_PRIORITY(STD_CONTAINER)
|
||||
decltype(parse::grammar::grammars)
|
||||
parse::grammar::grammars
|
||||
namespace ircd
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace ircd
|
||||
|
||||
ircd::parse::grammar::grammar(const char *const &name)
|
||||
:name{name}
|
||||
,grammars_it{[this, &name]
|
||||
{
|
||||
const auto iit(grammars.emplace(name, this));
|
||||
if(!iit.second)
|
||||
throw grammar_error("Parsing grammar named \"%s\" already exists.", name);
|
||||
|
||||
return iit.first;
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::parse::grammar::~grammar()
|
||||
noexcept
|
||||
{
|
||||
grammars.erase(grammars_it);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue