Parrot node that contains a string literal statement
Inheritance: Statement
Exemplo n.º 1
0
        public void BeforeRender(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model)
        {
            //process parameters
            if (statement.Parameters != null && statement.Parameters.Any())
            {
                foreach (var parameter in statement.Parameters)
                {
                    if (parameter.Value != null && ((parameter.Value.StartsWith("\"") && parameter.Value.EndsWith("\"")) || (parameter.Value.StartsWith("'") && parameter.Value.EndsWith("'"))))
                    {
                        var stringLiteral = new StringLiteral(parameter.Value);
                        var renderer = rendererFactory.GetRenderer("string");
                        var w = new StandardWriter();
                        {
                            renderer.Render(w, rendererFactory, stringLiteral, documentHost, model);
                        }

                        parameter.CalculatedValue = w.Result();
                    }
                }
            }
        }
Exemplo n.º 2
0
            public void StringLiteralParserTests(string delimiter, StringLiteralPartType encoding)
            {
                var parts = new StringLiteral(string.Format("\"this {0}is awesome {0}right\"", delimiter)).Values;

                Assert.AreEqual(4, parts.Count);
                Assert.AreEqual(StringLiteralPartType.Literal, parts[0].Type);
                Assert.AreEqual(encoding, parts[1].Type);
                Assert.AreEqual(StringLiteralPartType.Literal, parts[2].Type);
                Assert.AreEqual(encoding, parts[1].Type);

                Assert.AreEqual("this ", parts[0].Data);
                Assert.AreEqual("is", parts[1].Data);
                Assert.AreEqual(" awesome ", parts[2].Data);
                Assert.AreEqual("right", parts[3].Data);

                parts = new StringLiteral(string.Format("\"this contains a {0} but not a keyword\"", delimiter)).Values;
                Assert.AreEqual(1, parts.Count);
                Assert.AreEqual(StringLiteralPartType.Literal, parts[0].Type);

                parts = new StringLiteral(string.Format("\"{0}keyword_only\"", delimiter)).Values;
                Assert.AreEqual(1, parts.Count);
                Assert.AreEqual(encoding, parts[0].Type);
                Assert.AreEqual("keyword_only", parts[0].Data);

                parts = new StringLiteral(string.Format("\"{0}keyword_first followed by more words\"", delimiter)).Values;
                Assert.AreEqual(2, parts.Count);
                Assert.AreEqual(encoding, parts[0].Type);
                Assert.AreEqual(StringLiteralPartType.Literal, parts[1].Type);

                parts = new StringLiteral(string.Format("\"{0}keyword.with.dot\"", delimiter)).Values;
                Assert.AreEqual(1, parts.Count);
                Assert.AreEqual(encoding, parts[0].Type);
                Assert.AreEqual("keyword.with.dot", parts[0].Data);

                parts = new StringLiteral(string.Format("\"this is an {0}{0} escaped colon\"", delimiter)).Values;
                Assert.AreEqual(1, parts.Count);
                Assert.AreEqual(string.Format("this is an {0} escaped colon", delimiter), parts[0].Data);

                parts = new StringLiteral(string.Format("\"{0}keyword_only_endsin. a dot\"", delimiter)).Values;
                Assert.AreEqual(2, parts.Count);
                Assert.AreEqual(encoding, parts[0].Type);
                Assert.AreEqual(StringLiteralPartType.Literal, parts[1].Type);
                Assert.AreEqual("keyword_only_endsin", parts[0].Data);
                Assert.AreEqual(". a dot", parts[1].Data);
            }
Exemplo n.º 3
0
        private Attribute ParseAttribute(Stream stream)
        {
            var identifier = stream.Next();
            var equalsToken = stream.Peek() as EqualToken;
            if (equalsToken != null)
            {
                stream.NextNoReturn();
                var valueToken = stream.Peek();
                if (valueToken == null)
                {
                    //TODO: Errors.Add(stream.Next());
                    Errors.Add(new UnexpectedToken(identifier));
                    return new Attribute(identifier.Content, null);
                    //throw new ParserException(string.Format("Unexpected end of stream"));
                }

                if (valueToken.Type == TokenType.CloseBracket)
                {
                    //then it's an invalid declaration
                    Errors.Add(new AttributeValueMissing { Index = valueToken.Index });
                }

                Statement value = ParseStatement(stream).SingleOrDefault();
                //force this as an attribute type
                if (value == null)
                {
                }
                else
                {
                    switch (value.Name)
                    {
                        case "true":
                        case "false":
                        case "null":
                            value = new StringLiteral("\"" + value.Name + "\"");
                            break;
                    }
                }

                //reduction
                return new Attribute(identifier.Content, value);
            }

            //single attribute only
            return new Attribute(identifier.Content, null);
        }