@@ -76,19 +76,22 @@ bool Indices::parse(Kernel& kernel, std::shared_ptr<Ex> ex, keyval_t& keyvals)
7676 // If all values are indices, add an `Integer' property for the object,
7777 // listing these integers.
7878 bool is_number=true ;
79+ bool is_continuous=false ;
7980 for (auto & val: values)
8081 if (!val.begin ()->is_integer ()) {
8182 is_number=false ;
8283 break ;
8384 }
84- // FIXME: the above assumes no gap in the integer range, which is
85- // not always guaranteed, and will then break the Integer property
86- // assignment as the latter can only deal with continuous ranges.
8785 if (is_number) {
88- Ex from (values[0 ]), to (values[values.size ()-1 ]);
86+ std::sort (values.begin (), values.end (), [](Ex a, Ex b) {
87+ return a.to_integer () < b.to_integer ();
88+ });
89+ is_continuous = (int )values.size () == (values[values.size () - 1 ].to_integer () - values[0 ].to_integer () + 1 );
90+ }
91+ // FIXME: do not apply Integer to a list of integers with gaps as
92+ // the former can only deal with continuous ranges.
93+ if (is_continuous) {
8994// std::cerr << "Injecting Integer property" << std::endl;
90- // FIXME: this assumes that the values are in a continuous range (as Integer cannot
91- // represent anything else at this stage).
9295 kernel.inject_property (new Integer (), ex,
9396 kernel.ex_from_string (std::to_string (values[0 ].to_integer ())+" .."
9497 +std::to_string (values[values.size ()-1 ].to_integer ())
0 commit comments