Commit 5ed90c28 authored by Akim Demaille's avatar Akim Demaille
Browse files

to-expansion: check that we can compute the expansion

Some expansions require special contexts: \e|a for instance must be
translated into '\e|a.[\e|\e]', where '\e|a' is a label: hence we need
lan here.

* vcsn/core/rat/expansionset.hh: Make sure that the denormalization
succeeded.
* tests/python/to-expansion.py: Check.
parent eb8cade4
......@@ -110,6 +110,8 @@ def SKIP(*msg):
PASS('# SKIP', *msg)
def XFAIL(fun, exp = None):
'''Run `fun`: it should fail. If `exp` is given, check that the
exception includes it.'''
try:
fun()
except RuntimeError as e:
......
......@@ -287,3 +287,19 @@ check('(abc|xyz) & (a|xy)*(bc|z)*',
'a|xy.[bc|z&(a|xy)*(bc|z)*]')
check('(<X>abc|xyz) & (<Y>a|xy)*(<Z>bc|z)*',
'a|xy.[<XY>bc|z&(<Y>a|xy)*(<Z>(bc)|z)*]')
c = vcsn.context("lat<lan_char(abc), lan_char(xyz)>, q")
check('\e|\e',
'<1>')
check('a|x',
'a|x.[\e]')
check('a*|x*',
'<1> + \e|x.[\e|x*] + a|\e.[a*|\e] + a|x.[a*|x*]')
c = vcsn.context("lat<lal_char(abc), lal_char(xyz)>, q")
check('\e|\e',
'<1>')
check('a|x',
'a|x.[\e]')
XFAIL(lambda: c.expression('a*|x*').expansion(),
'to-expansion: cannot denormalize')
......@@ -54,6 +54,12 @@ namespace vcsn
return res;
}
/// The expressionset.
const expressionset_t& expressionset() const
{
return rs_;
}
/// Print this valueset.
std::ostream& print_set(std::ostream& o, format fmt = {}) const
{
......@@ -448,7 +454,11 @@ namespace vcsn
template <size_t Tape>
void denormalize_tape(typename focus_t<Tape>::value_t& e)
{
eset_.template focus<Tape>().denormalize(e);
auto es = eset_.template focus<Tape>();
es.denormalize(e);
require(es.expressionset().weightset()->is_zero(e.constant),
es, ": to-expansion: cannot denormalize ", to_string(es, e),
", need support for label one (the empty label)");
}
/// Denormalize on all these tapes.
......@@ -548,7 +558,7 @@ namespace vcsn
private:
/// The expressionset used for the expressions.
const expressionset_t& rs_;
expressionset_t rs_;
/// Shorthand to the labelset.
const labelset_t& ls_ = *rs_.labelset();
/// Shorthand to the weightset.
......
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