public DocumentView(IHost host, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, Document document) { DocumentHost = documentHost; _host = host; _rendererFactory = rendererFactory; _document = document; }
public bool Parse(System.IO.Stream stream, out Document document) { document = new Document(); try { var tokenizer = new Tokenizer(stream); IList<Token> tokens = tokenizer.Tokens(); var tokenStream = new Stream(tokens); foreach (var statement in Parse(tokenStream)) { foreach (var s in statement) { ParseStatementErrors(s); document.Children.Add(s); } } } catch (System.IO.EndOfStreamException) { Errors.Add(new EndOfStreamException { Index = (int)stream.Length }); } document.Errors = Errors; return true; }
public string Render(AbstractNode node, object model) { dynamic localModel = model; Document document = new Document(_host) { Children = localModel.Children }; return _host.DependencyResolver.Resolve<DocumentRenderer>().Render(document, localModel.Model); }
public string Render(Document document, object model) { var factory = Host.DependencyResolver.Resolve<IRendererFactory>(); StringBuilder sb = new StringBuilder(); foreach (var element in document.Children) { var renderer = factory.GetRenderer(element.Name); sb.AppendLine(renderer.Render(element, model)); } return sb.ToString(); }
public Document(Document document, Statement statement) { Children = document.Children; Children.Add(statement); }
public Document(IHost host, Document document, Statement statement) : this(host) { Children = document.Children; Children.Add(statement); }
public bool Parse(string text, out Document document) { return Parse(new MemoryStream(System.Text.Encoding.Default.GetBytes(text)), out document); }
public bool Parse(StringReader sourceReader, out Document document) { _parser = ParserFactory.CreateParser(sourceReader); _parser.TrimReductions = true; _context = new ParserContext(_parser); document = null; while (true) { switch (_parser.Parse()) { case ParseMessage.LexicalError: _errorString = string.Format("Lexical Error. Line {0}. Token {1} was not expected.", _parser.LineNumber, _parser.TokenText); return false; case ParseMessage.SyntaxError: StringBuilder text = new StringBuilder(); foreach (Symbol tokenSymbol in _parser.GetExpectedTokens()) { text.Append(' '); text.Append(tokenSymbol.ToString()); } _errorString = string.Format("Syntax Error. Line {0}. Expecting: {1}.", _parser.LineNumber, text); return false; case ParseMessage.Reduction: _parser.TokenSyntaxNode = _context.CreateASTNode(); break; case ParseMessage.Accept: var result = _parser.TokenSyntaxNode as BlockNodeList; if (result == null) { result = new BlockNodeList(_parser.TokenSyntaxNode as BlockNode); } document = new Document { Children = result }; _errorString = null; return true; case ParseMessage.TokenRead: //=== Make sure that we store token string for needed tokens. _parser.TokenSyntaxNode = _context.GetTokenText(); break; case ParseMessage.InternalError: _errorString = "Internal Error. Something is horribly wrong."; return false; case ParseMessage.NotLoadedError: _errorString = "Grammar Table is not loaded."; return false; case ParseMessage.CommentError: _errorString = "Comment Error. Unexpected end of input."; return false; case ParseMessage.CommentBlockRead: case ParseMessage.CommentLineRead: // don't do anything break; } } }
public bool Parse(string source, out Document document) { return Parse(new StringReader(source), out document); }