0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-01 17:48:56 +02: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,54 +248,55 @@ 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
// primary recursive rule
const rule<string_view> value
{
object_begin << -(member % value_sep) << object_end
,"object"
(&object << object)
| (&array << array)
| (&literal << literal)
| (&number << number)
| string
,"value"
};
rule<json::array> array
{
array_begin << -(value % value_sep) << array_end
,"array"
};
rule<json::object::member> member
const rule<json::object::member> member
{
name << name_sep << value
,"member"
};
rule<string_view> value
const rule<json::object> object
{
(&object << object)
| (&array << array)
| (&literal << literal)
| (&number << number)
| string
,"value"
object_begin << -(member % value_sep) << object_end
,"object"
};
const rule<json::array> array
{
array_begin << -(value % value_sep) << array_end
,"array"
};
output()
@ -293,6 +304,14 @@ struct ircd::json::output
{
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
;
}
};