Commit 10e61ad7 authored by Akim Demaille's avatar Akim Demaille
Browse files

edit-automaton: don't insert transitions with the special label

We parse in `lan, q`, we parse `<1/2>` as `<1/2>$`, not as `<1/2>\e`.
This is to support pre- and post-transition labels (e.g., `$ 0 <1/2>`).
Unfortunately it's easy, in particular with lao, to forget to write
`\e`, and I have been bitten: I tried to get the weight-series

    context = lao, expressionset<lal, q>
    $ -> 0
    0 -> 1 <a>
    1 -> 1 <b>
    1 -> 2 <c>
    2 -> $

But I got `<a+c>`.  The culprit was actually proper/is_proper: both
consider that automaton to be proper.  And the real culprit is
actually the user: there are indeed no spontaneous transitions in this
automaton: they are labeled with `$` because we did not use `\e`.
This error is too easy, so be sure to be kind to the user, and map the
special label to one when building the automaton.

It turns out that the test suite itself contained such an error: a
proper automaton still had a pseudo-spontaneous transition.

* vcsn/algos/edit-automaton.hh: Map $ to \e when adding an inner
transition.
* tests/python/proper.dir/lao-r.out.gv: Fix.
parent 8b90f28f
......@@ -6,14 +6,12 @@ digraph
{
node [shape = point, width = 0]
I0
F1
F0
}
{
node [shape = circle, style = rounded, width = 0.5]
0
1
}
I0 -> 0 [label = "<3>"]
0 -> 1 [label = "<5>"]
1 -> F1 [label = "<154>"]
0 -> F0 [label = "<770>"]
}
......@@ -14,6 +14,7 @@
#include <vcsn/dyn/fwd.hh>
#include <vcsn/misc/symbol.hh>
#include <vcsn/misc/raise.hh>
#include <vcsn/misc/static-if.hh>
#include <vcsn/misc/stream.hh>
#include <vcsn/weightset/polynomialset.hh>
......@@ -193,8 +194,26 @@ namespace vcsn
auto p = emap_.emplace(entry, entry_t{});
if (p.second)
p.first->second = conv(ps_, entry, sep_);
for (auto e: p.first->second)
res_->add_transition(s, d, label_of(e), weight_of(e));
for (auto m: p.first->second)
{
detail::static_if<labelset_t::has_one()>
([&](const auto& ls)
{
res_->add_transition
(s, d,
ls.is_special(label_of(m)) ? ls.one() : label_of(m),
weight_of(m));
},
[&](const auto& ls)
{
VCSN_REQUIRE(!ls.is_special(label_of(m)),
"edit_automaton: invalid entry: ",
entry.get());
res_->add_transition(s, d,
label_of(m), weight_of(m));
})
(ls);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment