Commit 540ac513 authored by Akim Demaille's avatar Akim Demaille
Browse files

context: de-sugar the name of the labelsets

Currently we still support names such as "lal_char, b" internally,
although "lal" does not make much sense (but "letterset" does), and
"_char" is absurd, as it actually parameterize the "lal" part.

So instead of "lal_char(abc)", work with "letterset<char(abc)>", which
make more sense.  It is (still) unfortunate that we don't have a nice
concrete syntax for our types, but it was a mistake to design a broken
syntax which pleases neither the user, nor the implementation.

So now accept "lal_char(abc)" as a backward compatibility feature, but
record "letterset<char(abc)>" instead.

* vcsn/alphabets/char.hh (sname): Your name is "char_letter", not "char".
* vcsn/alphabets/setalpha.hh: Honor the basic letter type name.
* vcsn/labelset/letterset.hh: Your name is "letterset".
Use use the name of the letter type we use instead of hard coding it again
here.
* vcsn/labelset/wordset.hh: Likewise.

Improve the dyn support.

* vcsn/dyn/type-ast.hh (letterset, wordset): Rename their "alphabet" into
"generators".
Provide them with a "letter_type".
* lib/vcsn/dyn/context-parser.cc, lib/vcsn/dyn/context-printer.cc,
* lib/vcsn/dyn/signature-printer.cc: Adjust.

Adjust the test suite.
parent e59b3836
......@@ -60,7 +60,9 @@ namespace vcsn
|| w == "lao"
|| w == "law_char"
|| w == "ratexpset"
|| w == "seriesset")
|| w == "seriesset"
|| w == "letterset"
|| w == "wordset")
{
std::shared_ptr<ast_node> res = labelset_(w);
if (is_.peek() == ',')
......@@ -124,7 +126,9 @@ namespace vcsn
|| w == "lan"
|| w == "lan_char"
|| w == "lao"
|| w == "law_char")
|| w == "law_char"
|| w == "letterset"
|| w == "wordset")
return labelset_(w);
else if (has(weightsets_, w))
return weightset_(w);
......@@ -149,21 +153,27 @@ namespace vcsn
return res;
}
std::string context_parser::alphabet_()
std::shared_ptr<const genset>
context_parser::genset_(const std::string& letter_type)
{
std::string res;
std::string gens;
if (is_.peek() == '(')
{
res += '(';
gens += '(';
int c = is_.get();
while ((c = is_.get()) != EOF)
{
res += c;
gens += c;
if (c == ')')
break;
}
}
return res;
return std::make_shared<const genset>(letter_type, gens);
}
std::shared_ptr<const genset> context_parser::genset_()
{
return genset_(word_());
}
std::shared_ptr<context> context_parser::context_()
......@@ -195,7 +205,7 @@ namespace vcsn
context_parser::labelset_(const std::string& ls)
{
if (ls == "lal_char")
return std::make_shared<letterset>(alphabet_());
return std::make_shared<letterset>(genset_("char_letters"));
else if (ls == "lan")
{
eat(is_, '<');
......@@ -207,13 +217,27 @@ namespace vcsn
}
else if (ls == "lan_char")
return std::make_shared<nullableset>(std::make_shared<letterset>
(alphabet_()));
(genset_("char_letters")));
else if (ls == "lao")
return std::make_shared<oneset>();
else if (ls == "lat")
return tupleset_();
else if (ls == "law_char")
return std::make_shared<wordset>(alphabet_());
return std::make_shared<wordset>(genset_("char_letters"));
else if (ls == "letterset")
{
eat(is_, '<');
auto gs = genset_();
eat(is_, '>');
return std::make_shared<letterset>(gs);
}
else if (ls == "wordset")
{
eat(is_, '<');
auto gs = genset_();
eat(is_, '>');
return std::make_shared<wordset>(gs);
}
else if (ls == "ratexpset")
return ratexpset_();
else if (ls == "seriesset")
......
......@@ -184,7 +184,7 @@ namespace vcsn
DEFINE(nullableset)
{
header("vcsn/ctx/lan_char.hh");
header("vcsn/labelset/nullableset.hh");
os_ << "vcsn::nullableset<" << incendl;
t.get_labelset()->accept(*this);
os_ << decendl << ">";
......@@ -197,13 +197,20 @@ namespace vcsn
os_ << "vcsn::oneset";
}
DEFINE(genset)
{
header("vcsn/alphabets/setalpha.hh"); // set_alphabet
if (t.letter_type() == "char_letters")
header("vcsn/alphabets/char.hh");
os_ << "vcsn::set_alphabet<vcsn::" << t.letter_type() << '>';
}
DEFINE(letterset)
{
(void) t;
header("vcsn/labelset/letterset.hh");
// Some instantiation happen here:
header("vcsn/ctx/lal_char.hh");
os_ << "vcsn::letterset<vcsn::set_alphabet<vcsn::char_letters>>";
os_ << "vcsn::letterset<";
t.genset()->accept(*this);
os_ << '>';
}
DEFINE(ratexpset)
......@@ -224,9 +231,10 @@ namespace vcsn
DEFINE(wordset)
{
(void) t;
header("vcsn/ctx/law_char.hh");
os_ << "vcsn::wordset<vcsn::set_alphabet<vcsn::char_letters>>";
header("vcsn/labelset/wordset.hh");
os_ << "vcsn::wordset<";
t.genset()->accept(*this);
os_ << '>';
}
DEFINE(other)
......
......@@ -71,11 +71,18 @@ namespace vcsn
os_ << "lao";
}
DEFINE(letterset)
DEFINE(genset)
{
os_ << "lal_char";
os_ << t.letter_type();
if (full_)
os_ << t.get_alpha();
os_ << t.generators();
}
DEFINE(letterset)
{
os_ << "letterset<";
t.genset()->accept(*this);
os_ << '>';
}
DEFINE(ratexpset)
......@@ -94,9 +101,9 @@ namespace vcsn
DEFINE(wordset)
{
os_ << "law_char";
if (full_)
os_ << t.get_alpha();
os_ << "wordset<";
t.genset()->accept(*this);
os_ << '>';
}
DEFINE(other)
......
......@@ -146,7 +146,7 @@ def normalize(a):
if 'lan' in str(a.context()):
a = a.proper()
# Eliminate nullablesets if there are that remain.
to = re.sub(r'lan<(lal_char\(.*?\))>', r'\1', a.context().format('text'))
to = re.sub(r'lan<(lal_char\(.*?\)|letterset<char_letters\(.*?\)>)>', r'\1', a.context().format('text'))
return a.automaton(vcsn.context(to))
......
......@@ -38,7 +38,7 @@ digraph {
}''',
'''digraph
{
vcsn_context = "law_char(ab), b"
vcsn_context = "wordset<char_letters(ab)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -77,7 +77,7 @@ digraph {
''',
'''digraph
{
vcsn_context = "law_char(ab), b"
vcsn_context = "wordset<char_letters(ab)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -110,7 +110,7 @@ digraph {
''',
'''digraph
{
vcsn_context = "law_char(ab), b"
vcsn_context = "wordset<char_letters(ab)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
}''')
......@@ -130,7 +130,7 @@ digraph {
''',
'''digraph
{
vcsn_context = "law_char(ab), b"
vcsn_context = "wordset<char_letters(ab)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -327,7 +327,7 @@ digraph
}
''', '''digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -360,7 +360,7 @@ digraph
}
''', '''digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
context = "lal_char(a), b"
context = "letterset<char_letters(a)>, b"
$ -> 0
0 -> 1 "a"
1 -> $
digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [texmode = math, lblstyle = auto]
d2toptions = "--format tikz --tikzedgelabels --graphstyle=automaton --crop --nominsize --autosize"
......
context = "lal_char(abc), q"
context = "letterset<char_letters(abc)>, q"
$ -> 0 "<3>"
0 -> 1 "<1/2>a, <1/3>b"
1 -> $ "<2>"
digraph
{
vcsn_context = "lal_char(abc), q"
vcsn_context = "letterset<char_letters(abc)>, q"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lal_char(abc), q"
vcsn_context = "letterset<char_letters(abc)>, q"
rankdir = LR
edge [texmode = math, lblstyle = auto]
d2toptions = "--format tikz --tikzedgelabels --graphstyle=automaton --crop --nominsize --autosize"
......
context = "lan<lal_char(a)>, b"
context = "lan<letterset<char_letters(a)>>, b"
$ -> 0
0 -> 1 "\\e, a"
1 -> $
digraph
{
vcsn_context = "lan<lal_char(a)>, b"
vcsn_context = "lan<letterset<char_letters(a)>>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lan<lal_char(a)>, b"
vcsn_context = "lan<letterset<char_letters(a)>>, b"
rankdir = LR
edge [texmode = math, lblstyle = auto]
d2toptions = "--format tikz --tikzedgelabels --graphstyle=automaton --crop --nominsize --autosize"
......
context = "lal_char(a), b"
context = "letterset<char_letters(a)>, b"
$ -> 0
0 -> 1 "a"
0 -> 2 "a"
......
digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lal_char(a), b"
vcsn_context = "letterset<char_letters(a)>, b"
rankdir = LR
edge [texmode = math, lblstyle = auto]
d2toptions = "--format tikz --tikzedgelabels --graphstyle=automaton --crop --nominsize --autosize"
......
......@@ -205,7 +205,7 @@ c = vcsn.context('lan_char(ab), z')
a = c.ratexp('<2>a+<2>b').thompson()
CHECK_EQ('''digraph
{
vcsn_context = "lan<lal_char(ab)>, z"
vcsn_context = "lan<letterset<char_letters(ab)>>, z"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -236,7 +236,7 @@ CHECK_EQ('''digraph
# conjunction: state names, and useless states, etc.
CHECK_EQ('''digraph
{
vcsn_context = "lan<lal_char(ab)>, z"
vcsn_context = "lan<letterset<char_letters(ab)>>, z"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -279,7 +279,7 @@ CHECK_EQ('''digraph
# Tooltip.
CHECK_EQ('''digraph
{
vcsn_context = "lan<lal_char(ab)>, z"
vcsn_context = "lan<letterset<char_letters(ab)>>, z"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -322,7 +322,7 @@ CHECK_EQ('''digraph
# Transitions.
CHECK_EQ('''digraph
{
vcsn_context = "lan<lal_char(ab)>, z"
vcsn_context = "lan<letterset<char_letters(ab)>>, z"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......@@ -366,7 +366,7 @@ CHECK_EQ('''digraph
# Empty set.
CHECK_EQ('''digraph
{
vcsn_context = "lal_char(), b"
vcsn_context = "letterset<char_letters()>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
digraph
{
vcsn_context = "lat<lan<lal_char(ab)>, lan<lal_char(ab)>>, b"
vcsn_context = "lat<lan<letterset<char_letters(ab)>>, lan<letterset<char_letters(ab)>>>, b"
rankdir = LR
edge [arrowhead = vee, arrowsize = .6]
{
......
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