- Localized Eval.
This commit is contained in:
Paul Beckingham 2014-07-04 17:40:11 -04:00
parent 6eee9e0544
commit 70156d3c3d
6 changed files with 38 additions and 35 deletions

View file

@ -24,6 +24,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <iostream>
#include <map>
#include <time.h>
@ -31,6 +32,8 @@
#include <Task.h>
#include <Color.h>
#include <Eval.h>
#include <text.h>
#include <i18n.h>
extern Context context;
extern Task& contextTask;
@ -228,11 +231,7 @@ void Eval::evaluatePostfixStack (
Variant& result) const
{
if (tokens.size () == 0)
{
std::cout << "No expression to evaluate.\n";
result = Variant ("");
return;
}
throw std::string (STRING_EVAL_NO_EXPRESSION);
// This is stack used by the postfix evaluator.
std::vector <Variant> values;
@ -318,7 +317,7 @@ void Eval::evaluatePostfixStack (
else if (token->first == "_hastag_") left = left.operator_hastag (right, contextTask);
else if (token->first == "_notag_") left = left.operator_notag (right, contextTask);
else
std::cout << "Unrecognized operator '" << token->first << "'\n";
throw format (STRING_EVAL_UNSUPPORTED, token->first);
if (_debug)
std::cout << "[" << values.size () << "] eval result push '" << (std::string) left << "'\n";
@ -341,8 +340,7 @@ void Eval::evaluatePostfixStack (
break;
case Lexer::typeOperator:
if (_debug)
std::cout << "Error: operator unexpected.\n";
throw std::string (STRING_EVAL_OP_EXPECTED);
break;
case Lexer::typeIdentifier:
@ -393,7 +391,7 @@ void Eval::evaluatePostfixStack (
// If there is more than one variant left on the stack, then the original
// expression was not valid.
if (values.size () != 1)
throw std::string ("The expression could not be evaluated.");
throw std::string (STRING_EVAL_NO_EVAL);
result = values[0];
}
@ -802,7 +800,7 @@ void Eval::infixToPostfix (
{
if (op_stack.back ().first == "(" ||
op_stack.back ().first == ")")
throw std::string ("Mismatched parentheses in expression");
throw std::string (STRING_PAREN_MISMATCH);
postfix.push_back (op_stack.back ());
op_stack.pop_back ();

View file

@ -602,11 +602,12 @@
// Duration
#define STRING_DURATION_UNRECOGNIZED "The duration '{1}' was not recognized as valid, with correct units like '3days'."
// E9
#define STRING_E9_UNSUPPORTED "Unsupported operator '{1}'."
#define STRING_E9_NO_OPERANDS "There are no operands for the '{1}' operator."
#define STRING_E9_INSUFFICIENT_OP "There are not enough operands for the '{1}' operator."
#define STRING_E9_MORE_OP "Found extra operands."
// Eval
#define STRING_EVAL_NO_EXPRESSION "No expression to evaluate."
#define STRING_EVAL_UNSUPPORTED "Unsupported operator '{1}'."
#define STRING_EVAL_OP_EXPECTED "Operator expected."
#define STRING_EVAL_NO_EVAL "The expression could not be evaluated."
#define STRING_PAREN_MISMATCH "Mismatched parentheses in expression"
// edit
#define STRING_EDIT_NO_CHANGES "No edits were detected."

View file

@ -615,11 +615,12 @@
// Duration
#define STRING_DURATION_UNRECOGNIZED "La duración '{1}' no se reconoció como válida, con unidades correctas como '3days'."
// E9
#define STRING_E9_UNSUPPORTED "Operador no soportado '{1}'."
#define STRING_E9_NO_OPERANDS "No hay operandos para el operador '{1}'."
#define STRING_E9_INSUFFICIENT_OP "No hay suficientes operandos para el operador '{1}'."
#define STRING_E9_MORE_OP "Encontrados operandos de más."
// Eval
#define STRING_EVAL_NO_EXPRESSION "No expression to evaluate."
#define STRING_EVAL_UNSUPPORTED "Operador no soportado '{1}'."
#define STRING_EVAL_OP_EXPECTED "Operator expected."
#define STRING_EVAL_NO_EVAL "The expression could not be evaluated."
#define STRING_PAREN_MISMATCH "Mismatched parentheses in expression"
// edit
#define STRING_EDIT_NO_CHANGES "No se detectaron modificaciones."

View file

@ -601,11 +601,12 @@
// Duration
#define STRING_DURATION_UNRECOGNIZED "The duration '{1}' was not recognized as valid, with correct units like '3days'."
// E9
#define STRING_E9_UNSUPPORTED "Unsupported operator '{1}'."
#define STRING_E9_NO_OPERANDS "There are no operands for the '{1}' operator."
#define STRING_E9_INSUFFICIENT_OP "There are not enough operands for the '{1}' operator."
#define STRING_E9_MORE_OP "Found extra operands."
// Eval
#define STRING_EVAL_NO_EXPRESSION "No expression to evaluate."
#define STRING_EVAL_UNSUPPORTED "Unsupported operator '{1}'."
#define STRING_EVAL_OP_EXPECTED "Operator expected."
#define STRING_EVAL_NO_EVAL "The expression could not be evaluated."
#define STRING_PAREN_MISMATCH "Mismatched parentheses in expression"
// edit
#define STRING_EDIT_NO_CHANGES "Aucunes modifications détectées."

View file

@ -602,11 +602,12 @@
// Duration
#define STRING_DURATION_UNRECOGNIZED "La durata '{1}' non è valida, con nità corrette come '3days'."
// E9
#define STRING_E9_UNSUPPORTED "Operatore non supportato '{1}'."
#define STRING_E9_NO_OPERANDS "Non ci sono operandi per l'operatore '{1}'."
#define STRING_E9_INSUFFICIENT_OP "Non ci sono abbastanza operandi per l'operatore '{1}'."
#define STRING_E9_MORE_OP "Trovati operandi in eccesso."
// Eval
#define STRING_EVAL_NO_EXPRESSION "No expression to evaluate."
#define STRING_EVAL_UNSUPPORTED "Operatore non supportato '{1}'."
#define STRING_EVAL_OP_EXPECTED "Operator expected."
#define STRING_EVAL_NO_EVAL "The expression could not be evaluated."
#define STRING_PAREN_MISMATCH "Mismatched parentheses in expression"
// edit
#define STRING_EDIT_NO_CHANGES "Nessuna modifica riscontrata."

View file

@ -602,11 +602,12 @@
// Duration
#define STRING_DURATION_UNRECOGNIZED "A duração '{1}' não foi reconhecida como válid, com unidades corretas como '3days'." // Can we translate '3days' to '3dias' ?
// E9
#define STRING_E9_UNSUPPORTED "Operador não suportado '{1}'."
#define STRING_E9_NO_OPERANDS "Não existem operandos para o operador '{1}'."
#define STRING_E9_INSUFFICIENT_OP "Não existem operandos suficientes para o operador '{1}'."
#define STRING_E9_MORE_OP "Operandos em excesso."
// Eval
#define STRING_EVAL_NO_EXPRESSION "No expression to evaluate."
#define STRING_EVAL_UNSUPPORTED "Operador não suportado '{1}'."
#define STRING_EVAL_OP_EXPECTED "Operator expected."
#define STRING_EVAL_NO_EVAL "The expression could not be evaluated."
#define STRING_PAREN_MISMATCH "Mismatched parentheses in expression"
// edit
#define STRING_EDIT_NO_CHANGES "Não foram detetadas alterações."