]> www.ginac.de Git - ginac.git/commitdiff
Parser: handle abbreviations as advertized in the manual.
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Mon, 5 Jul 2010 07:15:20 +0000 (09:15 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 5 Jul 2010 07:16:58 +0000 (09:16 +0200)
The following example from the tutorial

GiNaC::symbol x, y;
GiNaC::symtab table;
table["x"] = x+log(y)+1;
GiNaC::parser reader(table);
GiNaC::ex e = reader("5*x3 - x2");

fails with the following exception:

terminate called after throwing an instance of 'std::invalid_argument'
what(): find_or_insert_symbol: name "x" does not correspond to a symbol

Remove silly checks from find_or_insert_symbol, and fix its return value
(should be ex, not symbol).

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

index 7a7867a0a1069c5a02b57d2829ab0a3922bac2e3..2230d614913fe56fe9a7feb82d5a1070d363092a 100644 (file)
 
 namespace GiNaC {
 
-symbol
+ex
 find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
 {
        symtab::const_iterator p = syms.find(name);
-       if (p != syms.end()) {
-               if (is_a<symbol>(p->second))
-                       return ex_to<symbol>(p->second);
-               else
-                       throw std::invalid_argument(
-                               std::string("find_or_insert_symbol: name \"")
-                               + name + "\" does not correspond to a symbol");
-       }
-
+       if (p != syms.end())
+               return p->second;
 
        if (strict)
                throw std::invalid_argument(
index fe52700d35465fb1f053219655b8bcfe4b49b238..1145a871cb4b2da67a95373d44ea0812ab2567a5 100644 (file)
@@ -41,12 +41,12 @@ namespace GiNaC {
 typedef std::map<std::string, ex> symtab;
 
 /**
- * Find the symbol with the @a name in the symbol table @a syms.
+ * Find the symbol (or abbreviation) with the @a name in the symbol table @a syms.
  *
  * If symbol is missing and @a strict = false, insert it, otherwise
  * throw an exception.
  */
-extern symbol
+extern ex 
 find_or_insert_symbol(const std::string& name, symtab& syms,
                      const bool strict);