public IkadnBaseObject Parse(IkadnReader reader) { reader.SkipWhiteSpaces(); char formatterType = reader.Read(); string formatterParameter = reader.ReadWhile(c => !char.IsWhiteSpace(c)); Func <double, string> formatter; switch (formatterType) { case 'd': case 'D': formatter = new DecimalsFormatter(0, formatterParameter.Length > 0 ? int.Parse(formatterParameter, CultureInfo.InvariantCulture) : 0 ).Format; break; case 't': case 'T': formatter = ( (formatterParameter == AutomaticThousands) ? new ThousandsFormatter() : new ThousandsFormatter(formatterParameter) ).Format; break; default: throw new FormatException("Unexpected expression formatter: " + formatterType); } reader.SkipWhiteSpaces(); string expressionText = reader.ReadUntil(EndingChar); reader.Read(); if (expressionText.Length == 0) { throw new FormatException("Expression at " + reader.PositionDescription + " is empty (zero length)"); } var expParser = new ExpressionParser(expressionText); expParser.Parse(); if (expParser.errors.count > 0) { throw new FormatException("Expression at " + reader.PositionDescription + " is invalid: " + expParser.errors.errorMessages); } //TODO(later) substitute subformulas return(new ExpressionText(expParser.ParsedFormula, formatter)); }
protected override IkadnBaseObject ParseObject(IkadnReader reader) { reader.SkipWhiteSpaces(); return(new IkonText(reader.ReadWhile(x => !char.IsWhiteSpace(x)).Trim())); }