Commit db398885 authored by Florent Jacquemard's avatar Florent Jacquemard
Browse files

symbol for parse error

RT for parse error (label ERROR)
parent a9a19efc
......@@ -150,6 +150,20 @@ label_t SymbLabel::make_fork(unsigned short int mult)
return make(2, SymbLabel::FORK, 0, mult);
}
// static function
label_t SymbLabel::make_space()
{
return make(0, SymbLabel::DUMMY, 1, 0);
}
// static function
label_t SymbLabel::make_error()
{
return make(0, SymbLabel::DUMMY, 2, 0);
}
// static function
label_t SymbLabel::make_dummy()
{
......@@ -247,7 +261,9 @@ bool SymbLabel::inside(label_t a)
(kind(a) == REST) ||
(kind(a) == CONT) ||
(kind(a) == MULT) ||
(kind(a) == GRACE));
(kind(a) == GRACE) ||
error(a) ||
space(a));
}
......@@ -380,10 +396,36 @@ bool SymbLabel::fork(label_t a)
}
// static function
bool SymbLabel::space(label_t a)
{
if (kind(a) != DUMMY)
return false;
assert(arity(a) == 0);
assert(specific2(a) == 0);
return (specific(a) == 1);
}
// static function
bool SymbLabel::error(label_t a)
{
if (kind(a) != DUMMY)
return false;
assert(arity(a) == 0);
assert(specific2(a) == 0);
return (specific(a) == 2);
}
// static function
bool SymbLabel::dummy(label_t a)
{
return (kind(a) == DUMMY);
if (kind(a) != DUMMY)
return false;
assert(arity(a) == 0);
assert(specific2(a) == 0);
return (specific(a) == 0);
}
......
......@@ -44,7 +44,9 @@
/// B2 | BAR | 2 | 0 | 0, 1 | bar seq. constructor
/// B0 | BAR | 0 | 0 | 0, 1 | bar seq. constructor
/// F | FORK | 2 | 0 | 0, 1 | fork constructor
/// other | DUMMY | 0 | 0 | 0 | parse error
/// _ | DUMMY | 0 | 1 | 0 | blank space
/// FAIL | DUMMY | 0 | 2 | 0 | parse error
/// U | DUMMY | 0 | 0 | 0 | other (undef)
/// ------------------------------------------------------------------------
///
///
......@@ -117,7 +119,7 @@ public:
/// symbol for concurrency (binary symbol).
/// time interval duplication = voice split.
FORK,
/// dummy symbol (error)
/// space or error or dummy symbol (undef)
DUMMY
};
......@@ -210,7 +212,17 @@ public:
/// specific info will be 0.
static label_t make_fork(unsigned short int mult=1);
/// construct a new symbol of kind fork.
/// construct a new symbol of whitespace.
/// arity will be 0.
/// specific info will be 1. multiplicity will be 0.
static label_t make_space();
/// construct a new symbol of error.
/// arity will be 0.
/// specific info will be 2. multiplicity will be 0.
static label_t make_error();
/// construct a new dummy symbol.
/// arity will be 0.
/// specific info will be 0. multiplicity will be 0.
static label_t make_dummy();
......@@ -306,7 +318,15 @@ public:
/// symbol for concurrency (time interval duplication)
static bool fork(label_t a);
/// dummy symbol (error)
/// whitespace symbol
static bool space(label_t a);
/// error symbol
static bool error(label_t a);
/// dummy symbol (undef)
static bool dummy(label_t a);
/// copy label a and set in copy the specific info to given info
......
......@@ -83,6 +83,12 @@ bool LabeledRhythmTree::multi() const
}
bool LabeledRhythmTree::error() const
{
return (SymbLabel::error(_label));
}
bool LabeledRhythmTree::dummy() const
{
return (SymbLabel::dummy(_label));
......@@ -91,13 +97,13 @@ bool LabeledRhythmTree::dummy() const
bool LabeledRhythmTree::single_event() const
{
return (Label::nbEvents(_label) == 1);
return (SymbLabel::nbEvents(_label) == 1);
}
size_t LabeledRhythmTree::nbgn() const
{
return (Label::nbGraceNotes(_label));
return (SymbLabel::nbGraceNotes(_label));
}
......
......@@ -95,6 +95,9 @@ public:
/// @brief label of root node is a multi.
virtual bool multi() const;
/// @brief label of root node is an error symbol.
virtual bool error() const;
/// @brief label of root node is a dummy symbol.
virtual bool dummy() const;
......
......@@ -43,13 +43,15 @@ public:
/// @param k key (index of row in table) can be partial or complete.
/// @param n (as in n-best) is the rank of the run with target the key
/// of the record. must be larger or equal to 1 (default).
/// @param unfailing if true, return a NULL tree
/// iff there is a NULL subrun in the n-best run for k in tab
/// (bottom-up NULL propagation).
/// otherwise the tree may contain NULL subtrees.
/// @warning even when the returned tree is not NULL,
/// it may contain NULL subtrees,
/// when parsing partially failed e.g. for 1 bar (NULL subrun).
/// @param unfailing if true, return a FAIL tree
/// iff there is a FAIL subrun in the n-best run for k in tab
/// (bottom-up FAIL propagation).
/// otherwise the tree may contain FAIL subtrees.
/// @return the tree associated to the best run. should never be NULL.
/// A parse error is signaled by a FAIL symbol.
/// @warning even when the returned tree is not FAIL,
/// it may contain FAIL subtrees,
/// when parsing partially failed e.g. for 1 bar (FAIL subrun).
static LabeledRhythmTree* best(Parsing::TableA<K>* tab,
const K& k,
size_t n=1,
......@@ -59,7 +61,9 @@ public:
/// @param tab table containing all the parse trees
/// @param r run to cast
/// @param m multiplicity (number of incoming edges) for the tree constructed.
/// @param unfailing wether must fail in case of NULL run.
/// @param unfailing wether must fail in case of FAIL run.
/// @return the tree associated to the best run. should never be NULL.
/// A parse error is signaled by a FAIL symbol.
/// @remark defined as factory because one cannot define template constructors.
static LabeledRhythmTree* projection(Parsing::TableA<K>* tab,
const Parsing::Run<K>* r,
......
......@@ -29,11 +29,11 @@ LRTFactory<K>::projection(Parsing::TableA<K>* tab,
bool unfailing)
{
assert(tab);
if (r == NULL)
{
WARN("LRT::projection: NULL subrun (partial fail)");
// return new LabeledRhythmTree(SymbLabel::make_dummy());
return NULL;
return new LabeledRhythmTree(SymbLabel::make_dummy());
}
assert (r);
......@@ -65,20 +65,23 @@ LRTFactory<K>::projection(Parsing::TableA<K>* tab,
if ((ri != NULL) || (unfailing == false))
{
LabeledRhythmTree* ti = projection(tab, ri, mi, unfailing);
if ((ti != NULL) || unfailing == false)
assert(ti);
assert((ri != NULL) || ti->error());
if (unfailing == false)
{
t->add(ti);
continue;
}
assert(ti == NULL);
}
assert(unfailing == true);
// case of NULL subrun ri or child ti and unfailing = true
// case of NULL subrun ri and unfailing = true
// assert(unfailing == true);
WARN("LRT::projection: NULL tree (unfailing mode)");
delete t;
return NULL;
return new LabeledRhythmTree(SymbLabel::make_dummy());
}
assert((t == NULL) || (t->nbc() == nbc));
assert(t);
assert(t->error() || (t->nbc() == nbc));
return t;
}
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