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 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
|
struct ircd::parse::buffer
|
||||||
{
|
{
|
||||||
char *base; // Lowest address of the buffer (const)
|
char *base; // Lowest address of the buffer (const)
|
||||||
|
@ -74,28 +60,24 @@ struct ircd::parse::buffer
|
||||||
void discard();
|
void discard();
|
||||||
void remove();
|
void remove();
|
||||||
|
|
||||||
buffer(const buffer &old, char *const &start, char *const &stop)
|
buffer(const buffer &old, const mutable_buffer &mb)
|
||||||
:base{start}
|
:base{data(mb)}
|
||||||
,parsed{start}
|
,parsed{data(mb)}
|
||||||
,read{start + old.unparsed()}
|
,read{data(mb) + old.unparsed()}
|
||||||
,stop{stop}
|
,stop{stop}
|
||||||
{
|
{
|
||||||
memmove(base, old.base, old.unparsed());
|
memmove(base, old.base, old.unparsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer(char *const &start, char *const &stop)
|
buffer(const mutable_buffer &mb)
|
||||||
:base{start}
|
:base{data(mb)}
|
||||||
,parsed{start}
|
,parsed{data(mb)}
|
||||||
,read{start}
|
,read{data(mb)}
|
||||||
,stop{stop}
|
,stop{data(mb) + ircd::size(mb)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<size_t N> buffer(const buffer &old, char (&buf)[N])
|
template<size_t N> buffer(const buffer &old, char (&buf)[N])
|
||||||
:buffer{old, buf, buf + N}
|
:buffer{old, buf}
|
||||||
{}
|
|
||||||
|
|
||||||
template<size_t N> buffer(char (&buf)[N])
|
|
||||||
:buffer{buf, buf + N}
|
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,6 @@ template<class it,
|
||||||
class top>
|
class top>
|
||||||
struct ircd::http::grammar
|
struct ircd::http::grammar
|
||||||
:qi::grammar<it, top>
|
:qi::grammar<it, top>
|
||||||
,parse::grammar
|
|
||||||
{
|
{
|
||||||
template<class R = unused_type, class... S> using rule = qi::rule<it, R, S...>;
|
template<class R = unused_type, class... S> using rule = qi::rule<it, R, S...>;
|
||||||
|
|
||||||
|
@ -218,15 +217,11 @@ struct ircd::http::grammar
|
||||||
,"response"
|
,"response"
|
||||||
};
|
};
|
||||||
|
|
||||||
grammar(const rule<top> &top_rule, const char *const &name)
|
grammar(const rule<top> &top_rule)
|
||||||
:grammar<it, top>::base_type
|
:grammar<it, top>::base_type
|
||||||
{
|
{
|
||||||
top_rule
|
top_rule
|
||||||
}
|
}
|
||||||
,parse::grammar
|
|
||||||
{
|
|
||||||
name
|
|
||||||
}
|
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -236,7 +231,7 @@ struct ircd::http::parser
|
||||||
static size_t content_length(const string_view &val);
|
static size_t content_length(const string_view &val);
|
||||||
|
|
||||||
using http::grammar<const char *, unused_type>::grammar;
|
using http::grammar<const char *, unused_type>::grammar;
|
||||||
parser(): grammar { grammar::ws, "http.request" } {}
|
parser(): grammar { grammar::ws } {}
|
||||||
}
|
}
|
||||||
const ircd::http::parser;
|
const ircd::http::parser;
|
||||||
|
|
||||||
|
|
|
@ -19,37 +19,9 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#include <boost/spirit/include/qi.hpp>
|
namespace ircd
|
||||||
//#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
|
|
||||||
|
|
||||||
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