]> www.ginac.de Git - ginac.git/commitdiff
Quick and dirty bug fix for the parser to read GiNaC::lst again.
authorJens Vollinga <jens.vollinga@googlemail.com>
Tue, 26 Jul 2011 18:39:29 +0000 (20:39 +0200)
committerJens Vollinga <jens.vollinga@googlemail.com>
Tue, 26 Jul 2011 18:39:29 +0000 (20:39 +0200)
The parser only accepts lst in the form lst(...) not {...}, though.
Function prototype can now have a argument size of 0 to indicate
functions with an arbitrary number of arguments (like lst).

ginac/parser/default_reader.cpp
ginac/parser/parse_context.h

index 4f8c69c365d19be46be795cd7e003eb4e2a011ad..69b1a0c428d6ce632912e862d577dfff4b1d967f 100644 (file)
@@ -40,15 +40,22 @@ static ex sqrt_reader(const exvector& ev)
 {
        return GiNaC::sqrt(ev[0]);
 }
+
 static ex pow_reader(const exvector& ev)
 {
        return GiNaC::pow(ev[0], ev[1]);
 }
+
 static ex power_reader(const exvector& ev)
 {
        return GiNaC::power(ev[0], ev[1]);
 }
 
+static ex lst_reader(const exvector& ev)
+{
+       return GiNaC::lst(ev.begin(), ev.end());
+}
+
 
 // function::registered_functions() is protected, but we need to access it
 // TODO: add a proper const method to the `function' class, so we don't
@@ -87,6 +94,7 @@ const prototype_table& get_default_reader()
                reader[make_pair("sqrt", 1)] = sqrt_reader;
                reader[make_pair("pow", 2)] = pow_reader;
                reader[make_pair("power", 2)] = power_reader;
+               reader[make_pair("lst", 0)] = lst_reader;
                std::vector<function_options>::const_iterator it =
                        registered_functions_hack::get_registered_functions().begin();
                std::vector<function_options>::const_iterator end =
@@ -112,6 +120,7 @@ const prototype_table& get_builtin_reader()
                reader[make_pair("sqrt", 1)] = sqrt_reader;
                reader[make_pair("pow", 2)] = pow_reader;
                reader[make_pair("power", 2)] = power_reader;
+               reader[make_pair("lst", 0)] = lst_reader;
                enum {
                        log,
                        exp,
index f10425289ff7f895656f71271f4c2eab914029af..60151fd37988af0538f6b000bd50285930ee8d7d 100644 (file)
@@ -88,7 +88,20 @@ typedef ex (*reader_func)(const exvector& args);
  *       function pointer!! The unsigned has to correspond to the serial number of
  *       the defined GiNaC function.
  */
-typedef std::map<prototype, reader_func> prototype_table;
+class PrototypeLess
+{
+public:
+       bool operator()(const prototype& p1, const prototype& p2) const
+       {
+               int s = p1.first.compare(p2.first);
+               if (s == 0) {
+                       if ((p1.second == 0) || (p2.second == 0)) return false;
+                       return p1.second < p2.second;
+               }
+               return s < 0;
+       }
+};
+typedef std::map<prototype, reader_func, PrototypeLess> prototype_table;
 
 /**
  * Default prototype table.