Changeset 6908


Ignore:
Timestamp:
10/12/11 15:45:04 (9 years ago)
Author:
epitzer
Message:

#1622 Fix quote handling and simplify tokenizer in Calculator and provide better error message.

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Calculator.cs

    r6902 r6908  
    2525
    2626    private static readonly Regex TokenRegex =
    27       new Regex(@"[a-zA-Z0-9._]+|""([^""]|\\"")*""|'([^']|\\')*'|[-+*/<>^]|dup|swap|drop|log|true|false|if|==|not|isnull|null|ismatch|rename");
     27      new Regex(@"""(\\""|[^""])*""|'(\\'|[^'])*'|[^\s]+");
    2828
    2929    #endregion
     
    6161            stack.Push(d);
    6262          } else if (token.StartsWith("\"")) {
    63             stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace(@"\""", @"""")));
     63            stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace("\\\"", "\"")));
    6464          } else if (token.StartsWith("'")) {
    65             stack.Push(token.Substring(1, token.Length-2).Replace("\'", "'"));
     65            stack.Push(token.Substring(1, token.Length-2).Replace("\\'", "'"));
    6666          } else {
    6767            Apply(token, stack, variables);
     
    7070      } catch (Exception x) {
    7171        throw new Exception(string.Format(
    72           "Calculation Failed at token #{1}: '{2}' {0}current stack is: {0}{3}", Environment.NewLine,
    73           i, tokens[i], string.Join(Environment.NewLine, stack.Select(AsString))),
     72          "Calculation of '{1}'{0}failed at token #{2}: '{3}' {0}current stack is: {0}{4}", Environment.NewLine,
     73          Formula, i, tokens[i],
     74          string.Join(Environment.NewLine, stack.Select(AsString))),
    7475          x);
    7576      }
    76       if (stack.Count != 1) throw new Exception(string.Format("Invalid final evaluation stack size {0} (should be 1)", stack.Count));
     77      if (stack.Count != 1)
     78        throw new Exception(
     79          string.Format("Invalid final evaluation stack size {0} (should be 1) in formula '{1}'",
     80          stack.Count, Formula));
    7781      var result = stack.Pop();
    7882      if (result is string) return new StringValue((string)result);
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionDiscretizer.cs

    r6903 r6908  
    1010
    1111namespace HeuristicLab.Optimization {
    12   [Item("RunCollection Discretizer", "Creates several levels from the distribution of a certain result accross a run collection and assignes a discretized value.")]
     12  [Item("RunCollection Discretizer",
     13    "Creates several levels from the distribution of a certain result accross a run collection and " +
     14    "assigns a discretized value. Non-existing numbers as well as NaN and infinities are excluded from the caluclation.")]
    1315  [StorableClass]
    1416  public class RunCollectionDiscretizer : ParameterizedNamedItem, IRunCollectionModifier {
     
    139141      variables.TryGetValue(Source, out value);
    140142      var intValue = value as IntValue;
    141       if (intValue != null) {
     143      if (intValue != null)
    142144        return intValue.Value;
    143       } else {
    144         var doubleValue = value as DoubleValue;
    145         if (doubleValue != null)
    146           return doubleValue.Value;
    147       }
     145      var doubleValue = value as DoubleValue;
     146      if (doubleValue != null)
     147        return doubleValue.Value;
    148148      return null;
    149149    }
Note: See TracChangeset for help on using the changeset viewer.