public Language(string code, IEnumerable <TracableStream> dataSources) { this.Code = code; foreach (var source in dataSources) { var parser = new IkadnParser(source.Stream); parser.RegisterFactory(new ContextFactory()); parser.RegisterFactory(new SingleLineFactory()); parser.RegisterFactory(new TextBlockFactory()); parser.RegisterFactory(new ExpressionTextFactory()); parser.RegisterFactory(new ConditionalTextFactory()); try { while (parser.HasNext()) { var conext = parser.ParseNext().To <Context>(); contexts.Add((string)conext.Tag, conext); } } catch (IOException e) { throw new IOException(source.SourceInfo, e); } catch (FormatException e) { throw new FormatException(source.SourceInfo, e); } } }
public IkadnBaseObject Parse(IkadnParser parser) { parser.Reader.SkipWhiteSpaces(); string expressionText = parser.Reader.ReadUntil(EndingChar); parser.Reader.Read(); if (expressionText.Length == 0) { throw new FormatException("Expression at " + parser.Reader + " is empty (zero length)"); } ExpressionParser expressionParser = new ExpressionParser(expressionText); expressionParser.Parse(); if (expressionParser.errors.count > 0) { throw new FormatException("Invalid expression at " + parser.Reader + ". Errors: " + expressionParser.errors.errorMessages); } if (!parser.HasNext()) { throw new FormatException("IKON value expected at " + parser.Reader.PositionDescription); } if (expressionParser.ParsedFormula.Variables.Count == 0) { throw new FormatException("Condition expression at " + parser.Reader + " is constant. If intentional, use format witout condition."); } return(new ConditionalText(expressionParser.ParsedFormula, parser.ParseNext().To <IText>())); }