17 #ifndef AWALI_ALGOS_JS_PARSER_HH
18 # define AWALI_ALGOS_JS_PARSER_HH
21 #include <awali/common/json/node.cc>
33 namespace awali {
namespace sttc {
38 template<
typename RatExpSet>
43 using ratexp_t =
typename ratexpset_t::value_t;
57 for(
unsigned i=1; i<v.size(); ++i)
63 for(
unsigned i=1; i<v.size(); ++i)
69 e= rs_.atom(ls_.value_from_json(jo->
at(
"label")));
75 raise(
"Json parser: ratexp:",
"none expected field found");
78 e=rs_.lmul(ws_.value_from_json(jo->
at(
"lweight")), e);
80 e=rs_.rmul(e, ws_.value_from_json(jo->
at(
"lweight")));
92 template <
typename RatExpSet>
94 typename RatExpSet::ratexp_t
102 template <
typename Context>
103 mutable_automaton<Context>
111 std::unordered_map<unsigned,state_t>
states;
118 states[s]=aut->add_state();
122 auto history=aut->history();
124 history=std::make_shared<string_history>();
125 aut->set_history(history);
131 aut->set_initial(
states[s] , ws->value_from_json(jstate->
at(
"initial")));
133 aut->set_final(
states[s] , ws->value_from_json(jstate->
at(
"final")));
139 require(jtr->
has_child(
"destination"),
"js automaton:",
"no transition destination");
141 unsigned t=jtr->
at(
"destination")->
to_int();
143 auto l = ls->value_from_json(jtr->
at(
"label"));
145 auto w = ws->value_from_json(jtr->
at(
"weight"));
153 auto w = ws->value_from_json(jtr->
at(
"weight"));
162 template <
typename Aut>
std::vector< node_t * > const & values
Definition: node.hh:436
virtual std::string to_string() const
Coerces this node_t to an std::string.
Definition: node.hh:331
virtual int to_int() const
Coerces this node_t to int.
Definition: node.hh:321
node_kind_t const kind
Definition: node.hh:196
virtual array_t const * array() const
Casts this node to array_t.
Definition: node.hh:207
virtual bool has_child(std::string const &key) const override
Definition: node.hh:380
virtual node_t * at(std::string const &key) override
carries the algebraic settings of automata
Definition: context.hh:40
const weightset_ptr & weightset() const
Definition: context.hh:157
const labelset_ptr & labelset() const
Definition: context.hh:152
Definition: string_history.hh:29
void add_state(state_t s, const std::string &str)
Definition: string_history.hh:89
@ NO_HISTORY
The state has no history.
std::vector< state_t > states(abstract_automaton_t const *aut, bool all)
@ OBJECT
Definition: node.hh:93
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
RatExpSet::ratexp_t js_parse_exp_content(const RatExpSet &rs, json::node_t const *p)
Definition: js_parser.hh:95
mutable_automaton< Context > js_parse_aut_content(const Context &context, json::object_t const *p)
Definition: js_parser.hh:104
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:915
transition_t new_epsilon_trans(Aut a, state_t src, state_t dst, weight_t_of< Aut > w)
Helper to create a new epsilon transition.
Definition: add_epsilon_trans.hh:165
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
void js_add_metadata(Aut &aut, json::object_t *p)
Definition: js_parser.hh:164
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
Definition: js_parser.hh:39
labelset_t_of< context_t > labelset_t
Definition: js_parser.hh:42
typename ratexpset_t::value_t ratexp_t
Definition: js_parser.hh:43
RatExpSet ratexpset_t
Definition: js_parser.hh:40
ratexp_t parseNode(json::node_t const *p)
Definition: js_parser.hh:50
js_exp_parser(const ratexpset_t &rs)
Definition: js_parser.hh:46
weightset_t_of< ratexpset_t > weightset_t
Definition: js_parser.hh:44
context_t_of< ratexpset_t > context_t
Definition: js_parser.hh:41