From c84dc83799cec33b71126e624cd914125d8d2a43 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Mon, 5 Jul 2010 09:15:20 +0200 Subject: [PATCH] Parser: handle abbreviations as advertized in the manual. 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 | 13 +++---------- ginac/parser/parse_context.h | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/ginac/parser/parse_context.cpp b/ginac/parser/parse_context.cpp index 7a7867a0..2230d614 100644 --- a/ginac/parser/parse_context.cpp +++ b/ginac/parser/parse_context.cpp @@ -27,19 +27,12 @@ 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(p->second)) - return ex_to(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( diff --git a/ginac/parser/parse_context.h b/ginac/parser/parse_context.h index fe52700d..1145a871 100644 --- a/ginac/parser/parse_context.h +++ b/ginac/parser/parse_context.h @@ -41,12 +41,12 @@ namespace GiNaC { typedef std::map 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); -- 2.44.0