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 if (w ==
"blind_automaton"
46 || w ==
"determinized_automaton"
47 || w ==
"detweighted_automaton"
48 || w ==
"filter_automaton"
49 || w ==
"mutable_automaton"
50 || w ==
"pair_automaton"
51 || w ==
"partition_automaton"
52 || w ==
"permutation_automaton"
53 || w ==
"product_automaton"
54 || w ==
"ratexp_automaton"
55 || w ==
"transpose_automaton"
56 || w ==
"tuple_automaton")
62 std::shared_ptr<ast_node> res =
labelset_(w);
63 if (
is_.peek() ==
',')
69 std::shared_ptr<tupleset> res =
tupleset_();
70 if (
is_.peek() ==
',')
76 else if (w ==
"polynomialset")
79 auto res = std::make_shared<polynomialset>(
context_());
84 else if (w ==
"std::integral_constant")
91 return std::make_shared<other>(w);
94 else if (w ==
"const std::vector")
99 return std::make_shared<other>(w);
102 return std::make_shared<other>(w);
105 std::shared_ptr<ast_node>
111 std::shared_ptr<ast_node>
116 else if (w ==
"ratexpset")
118 else if (w ==
"seriesset")
125 raise(
"invalid weightset or labelset name: " + w);
132 while (
is_.peek() ==
' ')
134 while ((c =
is_.get()) != EOF)
135 if (c ==
'<' || c ==
',' || c ==
'>' || c ==
'(')
145 std::shared_ptr<const genset>
149 if (
is_.peek() ==
'(')
153 while ((c =
is_.get()) != EOF)
160 return std::make_shared<const genset>(letter_type, gens);
173 std::shared_ptr<context>
177 while (isspace(
is_.peek()))
179 return std::make_shared<context>(ls,
weightset_());
182 std::shared_ptr<context>
193 std::shared_ptr<ast_node>
196 if (ls ==
"lal_char")
197 return std::make_shared<letterset>(
genset_(
"char_letters"));
198 else if (ls ==
"lan")
203 res = std::make_shared<nullableset>(res);
207 else if (ls ==
"lan_char")
208 return std::make_shared<nullableset>(std::make_shared<letterset>
210 else if (ls ==
"lao")
211 return std::make_shared<oneset>();
212 else if (ls ==
"lat")
214 else if (ls ==
"law_char")
215 return std::make_shared<wordset>(
genset_(
"char_letters"));
216 else if (ls ==
"letterset")
221 return std::make_shared<letterset>(gs);
223 else if (ls ==
"wordset")
228 return std::make_shared<wordset>(gs);
230 else if (ls ==
"ratexpset")
232 else if (ls ==
"seriesset")
234 raise(
"invalid labelset name: ",
str_escape(ls));
242 std::shared_ptr<ast_node>
246 return std::make_shared<weightset>(ws);
247 else if (ws ==
"ratexpset")
249 else if (ws ==
"seriesset")
251 else if (ws ==
"polynomialset")
253 else if (ws ==
"lat")
256 raise(
"invalid weightset name: ",
str_escape(ws));
259 std::shared_ptr<automaton>
262 std::shared_ptr<automaton> res =
nullptr;
264 if (prefix ==
"blind_automaton")
267 res = std::make_shared<automaton>(
prefix,
268 std::make_shared<other>(
word_()));
274 else if (prefix ==
"determinized_automaton"
275 || prefix ==
"detweighted_automaton"
276 || prefix ==
"filter_automaton"
277 || prefix ==
"pair_automaton"
278 || prefix ==
"partition_automaton"
279 || prefix ==
"permutation_automaton"
280 || prefix ==
"ratexp_automaton"
281 || prefix ==
"transpose_automaton")
284 res = std::make_shared<automaton>(
prefix,
289 else if (prefix ==
"mutable_automaton")
292 res = std::make_shared<automaton>(
prefix,
297 else if (prefix ==
"product_automaton"
298 || prefix ==
"tuple_automaton")
301 res = std::make_shared<automaton>(
prefix,
303 while (
is_.peek() ==
',')
311 raise(
"invalid automaton name: ",
str_escape(prefix));
315 std::shared_ptr<tupleset>
321 while (
is_.peek() ==
',')
327 return std::make_shared<tupleset>(res);
330 std::shared_ptr<ratexpset>
337 if (
is_.peek() ==
'(')
346 std::shared_ptr<ratexpset>
358 auto res = std::make_shared<polynomialset>(
context_());
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::shared_ptr< const genset > genset_()
A generator set (e.g., "char(abc)" or "char").
std::string word_()
Return the next word in the stream.
Indentation relative functions.
std::shared_ptr< tupleset > tupleset_()
std::shared_ptr< automaton > automaton_(std::string prefix)
std::shared_ptr< ast_node > any_()
Accept anything.
std::shared_ptr< ast_node > weightset_()
.
std::ostream & str_escape(std::ostream &os, const std::string &str)
Output a string, escaping special characters.
std::shared_ptr< ratexpset > ratexpset_series_()
std::set< std::string > weightsets_
The set of terminal weightset names.
std::shared_ptr< ast_node > labelset_or_weightset_()
|
Trivial identities plus series identities.
std::shared_ptr< ast_node > parse()
Accept anything.
std::set< std::string > labelsets_
The set of weightset names.
std::shared_ptr< context > context_()
, .
std::istringstream is
The input stream: the specification to translate.
std::shared_ptr< ratexpset > ratexpset_()
"ratexpset" "\<" "\>".
std::istringstream & is_
The stream we are parsing.
std::vector< std::shared_ptr< ast_node >> value_t
std::shared_ptr< const detail::context_base > context
std::shared_ptr< polynomialset > polynomialset_()
"polynomialset" "\<" "\>".
char eat(std::istream &is, char c)
Check lookahead character and advance.
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, std::string explanation)
Throw an exception after failing to read from is.
std::shared_ptr< ast_node > parse_context()
Accept only a valid context.
std::shared_ptr< ast_node > labelset_()
.
identities
A ratexpset can implement several different sets of identities on expressions.
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
auto prefix(const Aut &aut) -> decltype(::vcsn::copy(aut))