Skip to content

Commit 6b2b59c

Browse files
committed
Accept all ranges of values for Indices
If a sequence works when passed to Integer, it should also work when it is the values keyword passed to Indices. The validation code really only needs to run on expressions that are not sequences. Signed-off-by: Connor Behan <[email protected]>
1 parent cb9e61c commit 6b2b59c

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

core/properties/Indices.cc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ bool Indices::parse(Kernel& kernel, std::shared_ptr<Ex> ex, keyval_t& keyvals)
6565
}
6666
else if(ki->first=="values") {
6767
//std::cerr << "got values keyword " << *(ki->second->name) << std::endl;
68+
if(*ki->second->name=="\\sequence") {
69+
auto args = std::make_shared<cadabra::Ex>(ki->second);
70+
kernel.inject_property(new Integer(), ex, args);
71+
++ki;
72+
continue;
73+
}
6874
collect_index_values(ki->second);
6975

7076
// If all values are indices, add an `Integer' property for the object,
@@ -125,24 +131,6 @@ void Indices::validate(const Kernel& k, const Ex& ex) const
125131

126132
void Indices::collect_index_values(Ex::iterator ind_values)
127133
{
128-
if(*ind_values->name=="\\sequence") {
129-
// We have been given a sequence, not a list.
130-
// FIXME: guard against errors or large ranges.
131-
auto ch = Ex::begin(ind_values);
132-
size_t start = to_long(*ch->multiplier);
133-
++ch;
134-
size_t end = to_long(*ch->multiplier);
135-
if(end<start)
136-
throw ArgumentException("Index range must be increasing.");
137-
if(end-start > 100)
138-
throw ArgumentException("Number of index values larger than 100, probably a typo.");
139-
140-
for(size_t i=start; i<=end; ++i) {
141-
values.push_back(Ex(i));
142-
}
143-
return;
144-
}
145-
146134
Ex tmp;
147135
cadabra::do_list(tmp, ind_values, [&](Ex::iterator ind) {
148136
values.push_back(Ex(ind));

0 commit comments

Comments
 (0)