0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::json: Synthesized repropagation of recursive grammars.

This commit is contained in:
Jason Volk 2019-06-24 04:27:15 -07:00
parent 425f277eaa
commit d58e119f7b

View file

@ -127,7 +127,13 @@ struct ircd::json::input
_r1_type depth;
[[noreturn]] static void throws_exceeded();
// primary recursive
// primary recursive rule
const rule<unused_type(uint)> value
{
lit_false | lit_null | lit_true | string | number | object(depth + 1) | array(depth + 1)
,"value"
};
const rule<unused_type(uint)> member
{
name >> -ws >> name_sep >> -ws >> value(depth)
@ -150,12 +156,6 @@ struct ircd::json::input
,"array"
};
const rule<unused_type(uint)> value
{
lit_false | lit_null | lit_true | string | number | object(depth + 1) | array(depth + 1)
,"value"
};
// type checkers
const rule<enum json::type> type
{
@ -179,7 +179,17 @@ struct ircd::json::input
input()
:input::base_type{rule<>{}} // required by spirit
{}
{
// synthesized repropagation of recursive rules
value %= lit_false
| lit_null
| lit_true
| string
| number
| object(depth + 1)
| array(depth + 1)
;
}
};
struct ircd::json::output
@ -238,47 +248,30 @@ struct ircd::json::output
{ '\0', "\\0" },
};
karma::symbols<char, const char *> escaped
const karma::symbols<char, const char *> escaped
{
"escaped"
};
rule<char()> character
const rule<char()> character
{
escaped | char_
};
rule<string_view> string
const rule<string_view> string
{
quote << *(character) << quote
,"string"
};
rule<string_view> name
const rule<string_view> name
{
string
,"name"
};
rule<json::object> object
{
object_begin << -(member % value_sep) << object_end
,"object"
};
rule<json::array> array
{
array_begin << -(value % value_sep) << array_end
,"array"
};
rule<json::object::member> member
{
name << name_sep << value
,"member"
};
rule<string_view> value
// primary recursive rule
const rule<string_view> value
{
(&object << object)
| (&array << array)
@ -288,11 +281,37 @@ struct ircd::json::output
,"value"
};
const rule<json::object::member> member
{
name << name_sep << value
,"member"
};
const rule<json::object> object
{
object_begin << -(member % value_sep) << object_end
,"object"
};
const rule<json::array> array
{
array_begin << -(value % value_sep) << array_end
,"array"
};
output()
:output::base_type{rule<>{}}
{
for(const auto &p : escapes)
escaped.add(p.first, p.second);
// synthesized repropagation of recursive rules
value %= (&object << object)
| (&array << array)
| (&literal << literal)
| (&number << number)
| string
;
}
};