1 #include <boost/algorithm/string/predicate.hpp>
2 #include <boost/algorithm/string/trim.hpp>
17 while (isspace(
is_.peek()))
47 "unexpected trailing characters after '",
57 while ((c =
is_.peek()) != EOF)
58 if (c ==
'<' || c ==
',' || c ==
'>' || c ==
'(')
66 boost::algorithm::trim_right(res);
76 while ((c =
peek_()) != EOF)
80 else if (c ==
'>' && --nesting == 0)
105 std::string w =
word_();
106 auto res = std::shared_ptr<ast_node>{};
107 if (boost::ends_with(w,
"_automaton"))
109 else if (w ==
"context")
111 else if (w ==
"expansionset")
113 else if (w ==
"expressionset")
119 else if (w ==
"polynomialset")
121 else if (w ==
"seriesset")
123 else if (w ==
"std::tuple")
137 res = std::make_shared<other>(w);
142 std::shared_ptr<ast_node>
148 std::shared_ptr<ast_node>
153 else if (w ==
"expressionset")
155 else if (w ==
"seriesset")
162 raise(
"invalid weightset or labelset name: " + w);
165 std::shared_ptr<const genset>
168 if (letter_type ==
"char" || letter_type ==
"string")
169 letter_type +=
"_letters";
175 while ((c =
is_.get()) != EOF && c !=
')')
181 require(c != EOF,
"unexpected end of file");
187 return std::make_shared<const genset>(letter_type, gens);
190 std::shared_ptr<const genset>
201 return genset_(
"char_letters");
209 std::shared_ptr<context>
224 return std::make_shared<context>(ls, ws);
232 std::shared_ptr<ast_node>
235 if (ls ==
"lal_char")
236 return std::make_shared<letterset>(
genset_(
"char_letters"));
237 else if (ls ==
"lan")
240 std::make_shared<nullableset>(std::make_shared<letterset>(
genset_()));
241 else if (ls ==
"lan_char")
242 return std::make_shared<nullableset>(std::make_shared<letterset>
244 else if (ls ==
"lao")
245 return std::make_shared<oneset>();
246 else if (ls ==
"lat")
248 else if (ls ==
"law_char")
249 return std::make_shared<wordset>(
genset_(
"char_letters"));
250 else if (ls ==
"lal" || ls ==
"letterset")
251 return std::make_shared<letterset>(
genset_());
252 else if (ls ==
"law" || ls ==
"wordset")
253 return std::make_shared<wordset>(
genset_());
254 else if (ls ==
"nullableset")
260 res = std::make_shared<nullableset>(res);
263 else if (ls ==
"expressionset")
265 else if (ls ==
"seriesset")
268 raise(
"invalid labelset name: ",
str_escape(ls));
276 std::shared_ptr<ast_node>
280 return std::make_shared<weightset>(ws);
281 else if (ws ==
"expressionset")
283 else if (ws ==
"seriesset")
285 else if (ws ==
"polynomialset")
287 else if (ws ==
"lat")
290 raise(
"invalid weightset name: ",
str_escape(ws));
293 std::shared_ptr<automaton>
299 std::shared_ptr<automaton>
302 auto res = std::shared_ptr<automaton>{};
304 if (prefix ==
"focus_automaton")
307 res = std::make_shared<automaton>(
prefix,
308 std::make_shared<other>(
word_()));
310 res->get_content().emplace_back(
automaton_());
314 else if (prefix ==
"delay_automaton"
315 || prefix ==
"expression_automaton"
316 || prefix ==
"filter_automaton"
317 || prefix ==
"insplit_automaton"
318 || prefix ==
"lazy_proper_automaton"
319 || prefix ==
"name_automaton"
320 || prefix ==
"pair_automaton"
321 || prefix ==
"partition_automaton"
322 || prefix ==
"permutation_automaton"
323 || prefix ==
"scc_automaton"
324 || prefix ==
"synchronized_automaton"
325 || prefix ==
"transpose_automaton")
332 else if (prefix ==
"determinized_automaton")
337 res->get_content().emplace_back(
any_());
339 res->get_content().emplace_back(
any_());
343 else if (prefix ==
"mutable_automaton")
350 else if (prefix ==
"derived_term_automaton")
352 eat_(
"<expressionset");
357 else if (prefix ==
"compose_automaton"
358 || prefix ==
"product_automaton"
359 || prefix ==
"tuple_automaton")
363 if (prefix !=
"tuple_automaton")
368 res = std::make_shared<automaton>(
prefix,
370 if (prefix !=
"tuple_automaton")
372 auto& c = res->get_content();
373 c.insert(c.begin(), std::make_shared<other>(w));
375 while (
peek_() ==
',')
378 res->get_content().emplace_back(
automaton_());
383 raise(
"invalid automaton name: ",
str_escape(prefix));
387 std::shared_ptr<tuple>
392 res.emplace_back(
any_());
393 while (
peek_() ==
',')
396 res.emplace_back(
any_());
399 return std::make_shared<tuple>(res);
402 std::shared_ptr<tupleset>
408 while (
peek_() ==
',')
414 return std::make_shared<tupleset>(res);
417 std::shared_ptr<expressionset>
430 return std::make_shared<expressionset>(
context,
ids);
433 std::shared_ptr<expressionset>
439 return std::make_shared<expressionset>(
context,
446 eat_(
"expressionset");
455 auto res = std::make_shared<polynomialset>(
context_());
std::string parameters_()
The next parameters in the stream.
std::shared_ptr< ast_node > labelset_()
.
std::shared_ptr< automaton > automaton_()
An expressionset can implement several different sets of identities on expressions.
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
char eat_(char c)
Accept this character, possibly preceded by spaces.
std::shared_ptr< tuple > tuple_()
std::shared_ptr< expressionset > expressionset_()
"expressionset" "\<" "\>", possibly followed by identities.
Indentation relative functions.
char eat(std::istream &is, char c)
Check lookahead character and advance.
Traditional plus distribution. Used for series identities.
std::shared_ptr< context > context_()
, .
auto prefix(const Aut &aut) -> decltype(::vcsn::copy(aut))
std::shared_ptr< ast_node > parse_context()
Accept only a valid context.
std::vector< std::shared_ptr< ast_node >> value_t
std::shared_ptr< const detail::context_base > context
A dyn::context.
std::shared_ptr< ast_node > labelset_or_weightset_()
|
void check_eof_(std::shared_ptr< ast_node > res)
We managed to read res in is, check that is_ is finished.
std::set< std::string > weightsets_
The set of terminal weightset names.
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
std::vector< std::shared_ptr< ast_node >> value_t
std::shared_ptr< ast_node > any_()
Accept anything.
std::shared_ptr< const genset > genset_()
An optional generator set in brackets (e.g., or ).
void skip_space_()
Skip white spaces.
std::shared_ptr< ast_node > parse()
Accept anything.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
int peek_()
The next character, possibly preceded by spaces.
std::shared_ptr< polynomialset > polynomialset_()
"polynomialset" "\<" "\>".
std::shared_ptr< expansionset > expansionset_()
"expansionset" "\<" "\>".
std::istringstream & is_
The stream we are parsing.
static identities ids(const driver &d)
Get the identities of the driver.
std::set< std::string > labelsets_
The set of weightset names.
std::shared_ptr< ast_node > weightset_()
.
std::shared_ptr< expressionset > seriesset_()
No optional argument.
std::string word_()
The next word in the stream.
std::shared_ptr< tupleset > tupleset_()
"\<" ( | ",")+ "\>".