15 static void check_eof(std::istream&
is, std::shared_ptr<ast_node> res)
23 "unexpected trailing characters after '",
44 std::string w =
word_();
45 auto res = std::shared_ptr<ast_node>{};
46 if (w ==
"delay_automaton"
47 || w ==
"determinized_automaton"
48 || w ==
"detweighted_automaton"
49 || w ==
"expression_automaton"
50 || w ==
"filter_automaton"
51 || w ==
"focus_automaton"
52 || w ==
"mutable_automaton"
53 || w ==
"name_automaton"
54 || w ==
"pair_automaton"
55 || w ==
"partition_automaton"
56 || w ==
"permutation_automaton"
57 || w ==
"product_automaton"
58 || w ==
"scc_automaton"
59 || w ==
"synchronized_automaton"
60 || w ==
"transpose_automaton"
61 || w ==
"tuple_automaton")
63 else if (w ==
"context")
65 else if (w ==
"expansionset")
67 else if (w ==
"expressionset")
73 else if (w ==
"polynomialset")
75 else if (w ==
"seriesset")
77 else if (w ==
"std::tuple")
89 if (
is_.peek() ==
'<')
91 res = std::make_shared<other>(w);
96 std::shared_ptr<ast_node>
102 std::shared_ptr<ast_node>
107 else if (w ==
"expressionset")
109 else if (w ==
"seriesset")
116 raise(
"invalid weightset or labelset name: " + w);
123 while (
is_.peek() ==
' ')
125 while ((c =
is_.get()) != EOF)
126 if (c ==
'<' || c ==
',' || c ==
'>' || c ==
'(')
142 while ((c =
is_.peek()) != EOF)
146 else if (c ==
'>' && --nesting == 0)
155 std::shared_ptr<const genset>
158 if (letter_type ==
"char" || letter_type ==
"string")
159 letter_type +=
"_letters";
161 if (
is_.peek() ==
'(')
165 while ((c =
is_.get()) != EOF && c !=
')')
171 require(c != EOF,
"unexpected end of file");
177 return std::make_shared<const genset>(letter_type, gens);
190 std::shared_ptr<context>
202 while (isspace(
is_.peek()))
207 return std::make_shared<context>(ls, ws);
215 std::shared_ptr<ast_node>
218 if (ls ==
"lal_char")
219 return std::make_shared<letterset>(
genset_(
"char_letters"));
220 else if (ls ==
"lan")
227 std::make_shared<nullableset>(std::make_shared<letterset>(gs));
229 else if (ls ==
"lan_char")
230 return std::make_shared<nullableset>(std::make_shared<letterset>
232 else if (ls ==
"lao")
233 return std::make_shared<oneset>();
234 else if (ls ==
"lat")
236 else if (ls ==
"law_char")
237 return std::make_shared<wordset>(
genset_(
"char_letters"));
238 else if (ls ==
"lal" || ls ==
"letterset")
243 return std::make_shared<letterset>(gs);
245 else if (ls ==
"law" || ls ==
"wordset")
250 return std::make_shared<wordset>(gs);
252 else if (ls ==
"nullableset")
258 res = std::make_shared<nullableset>(res);
261 else if (ls ==
"expressionset")
263 else if (ls ==
"seriesset")
265 raise(
"invalid labelset name: ",
str_escape(ls));
273 std::shared_ptr<ast_node>
277 return std::make_shared<weightset>(ws);
278 else if (ws ==
"expressionset")
280 else if (ws ==
"seriesset")
282 else if (ws ==
"polynomialset")
284 else if (ws ==
"lat")
287 raise(
"invalid weightset name: ",
str_escape(ws));
290 std::shared_ptr<automaton>
293 std::shared_ptr<automaton> res =
nullptr;
295 if (prefix ==
"focus_automaton")
298 res = std::make_shared<automaton>(
prefix,
299 std::make_shared<other>(
word_()));
305 else if (prefix ==
"delay_automaton"
306 || prefix ==
"determinized_automaton"
307 || prefix ==
"detweighted_automaton"
308 || prefix ==
"expression_automaton"
309 || prefix ==
"filter_automaton"
310 || prefix ==
"name_automaton"
311 || prefix ==
"pair_automaton"
312 || prefix ==
"partition_automaton"
313 || prefix ==
"permutation_automaton"
314 || prefix ==
"scc_automaton"
315 || prefix ==
"synchronized_automaton"
316 || prefix ==
"transpose_automaton")
319 res = std::make_shared<automaton>(
prefix,
324 else if (prefix ==
"mutable_automaton")
327 res = std::make_shared<automaton>(
prefix,
332 else if (prefix ==
"product_automaton"
333 || prefix ==
"tuple_automaton")
336 res = std::make_shared<automaton>(
prefix,
338 while (
is_.peek() ==
',')
346 raise(
"invalid automaton name: ",
str_escape(prefix));
350 std::shared_ptr<tuple>
355 res.emplace_back(
any_());
356 while (
is_.peek() ==
',')
359 res.emplace_back(
any_());
362 return std::make_shared<tuple>(res);
365 std::shared_ptr<tupleset>
371 while (
is_.peek() ==
',')
377 return std::make_shared<tupleset>(res);
380 std::shared_ptr<expressionset>
387 if (
is_.peek() ==
'(')
393 return std::make_shared<expressionset>(
context,
ids);
396 std::shared_ptr<expressionset>
402 return std::make_shared<expressionset>(
context,
409 eat(
is_,
"expressionset");
418 auto res = std::make_shared<polynomialset>(
context_());
std::shared_ptr< expressionset > expressionset_()
"expressionset" "\<" "\>", possibly followed by identities.
std::set< std::string > labelsets_
The set of weightset names.
std::shared_ptr< ast_node > labelset_or_weightset_()
|
std::ostream & str_escape(std::ostream &os, const std::string &str)
Output a string, escaping special characters.
std::shared_ptr< ast_node > any_()
Accept anything.
std::shared_ptr< const genset > genset_()
A generator set (e.g., char_letters(abc) or char).
std::shared_ptr< const detail::context_base > context
A dyn::context.
std::shared_ptr< automaton > automaton_(std::string prefix)
static void check_eof(std::istream &is, std::shared_ptr< ast_node > res)
We managed to read res in is, check that is is finished.
std::istringstream is
The input stream: the specification to translate.
char eat(std::istream &is, char c)
Check lookahead character and advance.
std::vector< std::shared_ptr< ast_node >> value_t
std::shared_ptr< ast_node > parse_context()
Accept only a valid context.
std::string parameters_()
The next parameters in the stream.
std::shared_ptr< ast_node > labelset_()
.
std::shared_ptr< ast_node > weightset_()
.
std::set< std::string > weightsets_
The set of terminal weightset names.
std::shared_ptr< tuple > tuple_()
Traditional plus distribution. Used for series identities.
std::shared_ptr< tupleset > tupleset_()
"\<" ( | ",")+ "\>".
static identities ids(const driver &d)
Get the identities of the driver.
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::shared_ptr< context > context_()
, .
std::vector< std::shared_ptr< ast_node >> value_t
An expressionset can implement several different sets of identities on expressions.
std::shared_ptr< ast_node > parse()
Accept anything.
std::shared_ptr< expansionset > expansionset_()
"expansionset" "\<" "\>".
ATTRIBUTE_PURE bool has(const std::deque< T, Allocator > &s, const T &e)
Whether e is member of s.
auto prefix(const Aut &aut) -> decltype(::vcsn::copy(aut))
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
Indentation relative functions.
std::shared_ptr< expressionset > seriesset_()
No optional argument.
std::shared_ptr< polynomialset > polynomialset_()
"polynomialset" "\<" "\>".
std::istringstream & is_
The stream we are parsing.
std::string word_()
The next word in the stream.