public void TestAttributeParser()
        {
            var data4   = new ParsableData("base KNZ:varchar(len=\"50\", primary_key=\"true\");");
            var p4      = new AttributeParser(data4);
            var result4 = p4.Parse();

            Console.WriteLine($"Result4: {result4.AttributeType} {result4.Name} {result4.Parameters.Count}");

            data4   = new ParsableData("base KURZBEZ:varchar ( len = \"100\"  ) ;          ");
            p4      = new AttributeParser(data4);
            result4 = p4.Parse();
            Console.WriteLine($"Result4: {result4.AttributeType} {result4.Name} {result4.Parameters.Count}");

            data4   = new ParsableData("fact Anzahl_F:decimal(len=\"1,0\",\n\t default=\"1\"); // ein default=\"1\" wäre hier noch nett");
            p4      = new AttributeParser(data4);
            result4 = p4.Parse();
            Console.WriteLine($"Result4: {result4.AttributeType} {result4.Name} {result4.Parameters.Count}");

            data4   = new ParsableData("ref JaNein.KNZ as Zulassung; // Zulassung_JaNein");
            p4      = new AttributeParser(data4);
            result4 = p4.Parse();
            Console.WriteLine($"Result4: {result4.AttributeType} {result4.InterfaceName}.{result4.FieldName} {result4.Alias}");

            // Neuer Testfall: ref-Attribute sollen auch Primärschlüssel-Bestandteile sein können!
            data4   = new ParsableData("ref Tag.KNZ(primary_key=\"true\");");
            p4      = new AttributeParser(data4);
            result4 = p4.Parse();
            Console.WriteLine($"Result4: {result4.AttributeType} {result4.InterfaceName}.{result4.FieldName} {result4.Alias}");
        }
        private static string AppendCreateDictionaryLocalVariable(string dictionary, CodeDomClassBuilder builder)
        {
            var parser = new AttributeParser(dictionary);
            parser.Parse();


            var keyValuePairType = new CodeTypeReference(typeof(KeyValuePair<string,object>));

            var createDictionaryMethod = new CodeMethodInvokeExpression();


            foreach (var attribute in parser.Attributes)
            {

                var newKeyValueExpression = new CodeObjectCreateExpression {CreateType = keyValuePairType};

                var keyExpression = new CodePrimitiveExpression {Value = attribute.Name};
                newKeyValueExpression.Parameters.Add(keyExpression);

                if (attribute.Type == ParsedAttributeType.String)
                {
                    AppendStringDictValue(attribute, newKeyValueExpression);
                }
                else
                {
                    newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                                                             {
                                                                 Value = attribute.Value

                                                             });
                }

                createDictionaryMethod.Parameters.Add(newKeyValueExpression);
            }



            var getDictionaryMethod = new CodeMethodReferenceExpression
                                          {
                                              MethodName = "GetDictionaryFromKeyValue",
                                              TargetObject =
                                                  new CodeVariableReferenceExpression
                                                      {
                                                          VariableName = "NHamlMonoRailView"
                                                      }
                                          };
            createDictionaryMethod.Method = getDictionaryMethod;

            var variableName = string.Format("nhamlTempDictionary{0}", tempDictionaryCount);
            tempDictionaryCount++;
            var dictionaryDecleration = new CodeVariableDeclarationStatement
                             {
                                 InitExpression = createDictionaryMethod,
                                 Name = variableName,
                                 Type = new CodeTypeReference(typeof (IDictionary<string, object>))
                             };
            builder.RenderMethod.Statements.Add(dictionaryDecleration);
            return variableName;
        }
Example #3
0
        public void Empty()
        {
            var parser = new AttributeParser("");

            parser.Parse();

            Assert.AreEqual(0, parser.Attributes.Count);
        }
Example #4
0
            public void Empty()
            {
            var parser = new AttributeParser("");

            parser.Parse();

            Assert.AreEqual(0, parser.Attributes.Count);
            }
Example #5
0
        private static void ParseAndRenderAttributes(TemplateClassBuilder builder, Match tagMatch)
        {
            var idAndClasses   = tagMatch.Groups[2].Value;
            var attributesHash = tagMatch.Groups[4].Value.Trim();

            var match = _idClassesRegex.Match(idAndClasses);

            var classes = new List <string>();

            foreach (Capture capture in match.Groups[2].Captures)
            {
                classes.Add(capture.Value);
            }

            if (classes.Count > 0)
            {
                attributesHash = PrependAttribute(attributesHash, Class, string.Join(" ", classes.ToArray()));
            }

            string id = null;

            foreach (Capture capture in match.Groups[1].Captures)
            {
                id = capture.Value;
                break;
            }

            if (!string.IsNullOrEmpty(id))
            {
                attributesHash = PrependAttribute(attributesHash, Id, id);
            }

            if (string.IsNullOrEmpty(attributesHash))
            {
                return;
            }

            var attributeParser = new AttributeParser(attributesHash);

            attributeParser.Parse();
            foreach (var attribute in attributeParser.Attributes)
            {
                if (attribute.Type == ParsedAttributeType.String)
                {
                    var expressionStringParser = new ExpressionStringParser(attribute.Value);

                    expressionStringParser.Parse();

                    builder.AppendAttributeTokens(attribute.Schema, attribute.Name, expressionStringParser.ExpressionStringTokens);
                }
                else
                {
                    var token = new ExpressionStringToken(attribute.Value, true);

                    builder.AppendAttributeTokens(attribute.Schema, attribute.Name, new[] { token });
                }
            }
        }
Example #6
0
            public void EmptyValue()
            {
            var parser = new AttributeParser(@"a=""""");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "", ParsedAttributeType.String);
            }
Example #7
0
        public void EmptyValue()
        {
            var parser = new AttributeParser(@"a=""""");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "", ParsedAttributeType.String);
        }
Example #8
0
        public void SimpleSchemaReference()
        {
            var parser = new AttributeParser(" xml:lang=en:us ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "xml", "lang", "en:us", ParsedAttributeType.Reference);
        }
Example #9
0
        public void SimpleEncodingIsIgnoredIfItIsUsedAsStopper()
        {
            var parser = new AttributeParser(@"c=#{abc\\} ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "c", @"abc\\", ParsedAttributeType.Expression);
        }
Example #10
0
        public void SimpleReference()
        {
            var parser = new AttributeParser(" a=bb ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "bb", ParsedAttributeType.Reference);
        }
Example #11
0
        public void CurlyBracesInsideCode()
        {
            var parser = new AttributeParser(@"action = #{Convert.ToString(new { ID=5\})}");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "action", "Convert.ToString(new { ID=5\\})", ParsedAttributeType.Expression);
        }
Example #12
0
        public void SimpleSingleQuotes()
        {
            var parser = new AttributeParser("a='b'");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
        }
Example #13
0
        public void SimpleOnlyReferenceWithSpace()
        {
            var parser = new AttributeParser("a ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.String);
        }
Example #14
0
        public void SingleQuoteOpen()
        {
            var parser = new AttributeParser(@" a=text' ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "text'", ParsedAttributeType.Reference);
        }
Example #15
0
        public void ValueEndsWithCurly()
        {
            var parser = new AttributeParser(@" a=text} ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "text}", ParsedAttributeType.Reference);
        }
Example #16
0
        public void CurlyBracesInsideCode()
        {
            var parser = new AttributeParser(@"action = #{Convert.ToString(new { ID=5\})}");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "action", "Convert.ToString(new { ID=5\\})", ParsedAttributeType.Expression);
        }
Example #17
0
        public void ExpressionWithoutHash()
        {
            var parser = new AttributeParser(@"src = Html.Content().AppRoot() ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "src", "Html.Content().AppRoot()", ParsedAttributeType.Reference);
        }
Example #18
0
        public void SchemaOnly()
        {
            var parser = new AttributeParser(" a:b ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", "b", ParsedAttributeType.String);
        }
Example #19
0
        public void AttributeWithSchemaIsDifferent()
        {
            var parser = new AttributeParser("lang='en' xml:lang='en:us'");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, null, "lang", "en", ParsedAttributeType.String);
            AssertAttribute(parser, "xml", "lang", "en:us", ParsedAttributeType.String);
        }
Example #20
0
        public void AttributeWithSchemaIsDifferent()
        {
            var parser = new AttributeParser("lang='en' xml:lang='en:us'");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, null, "lang", "en", ParsedAttributeType.String);
            AssertAttribute(parser, "xml", "lang", "en:us", ParsedAttributeType.String);
        }
Example #21
0
        public void DoubleAndSingleQuotesEncoded()
        {
            var parser = new AttributeParser(@"b='a\'b\'' dd=""\""d\""e""");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, "b", @"a\'b\'", ParsedAttributeType.String);
            AssertAttribute(parser, "dd", @"\""d\""e", ParsedAttributeType.String);
        }
Example #22
0
        public void ExpressionInsideOfDoubleSingleQuotesAndEncodedQuotes()
        {
            var parser = new AttributeParser("a='#{\"a\"}' c=\"#{a}\"");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, "a", "#{\"a\"}", ParsedAttributeType.String);
            AssertAttribute(parser, "c", "#{a}", ParsedAttributeType.String);
        }
Example #23
0
        public void DoubleAndSingleQuotesEncoded()
        {
            var parser = new AttributeParser(@"b='a\'b\'' dd=""\""d\""e""");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, "b", @"a\'b\'", ParsedAttributeType.String);
            AssertAttribute(parser, "dd", @"\""d\""e", ParsedAttributeType.String);
            }
Example #24
0
        public void DoubleQuotes()
        {
            var parser = new AttributeParser("a=\"b\" cc=\"d\" eee=\"f\" ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "cc", "d", ParsedAttributeType.String);
            AssertAttribute(parser, "eee", "f", ParsedAttributeType.String);
        }
Example #25
0
        public void OnlyReference()
        {
            var parser = new AttributeParser("a cc e");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.String);
            AssertAttribute(parser, "cc", "cc", ParsedAttributeType.String);
            AssertAttribute(parser, "e", "e", ParsedAttributeType.String);
        }
Example #26
0
            public void DoubleQuotes()
            {
            var parser = new AttributeParser("a=\"b\" cc=\"d\" eee=\"f\" ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "cc", "d", ParsedAttributeType.String);
            AssertAttribute(parser, "eee", "f", ParsedAttributeType.String);
            }
Example #27
0
        public void SingleQuotes()
        {
            var parser = new AttributeParser("a='b' c='d' ee='f'");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "c", "d", ParsedAttributeType.String);
            AssertAttribute(parser, "ee", "f", ParsedAttributeType.String);
        }
Example #28
0
        public void EncodingIsIgnoredIfItIsUsedAsStopper()
        {
            var parser = new AttributeParser(@" a=""abc\\"" b='abc\\' c=#{abc\\} ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", @"abc\\", ParsedAttributeType.String);
            AssertAttribute(parser, "b", @"abc\\", ParsedAttributeType.String);
            AssertAttribute(parser, "c", @"abc\\", ParsedAttributeType.Expression);
        }
Example #29
0
        public void Schema()
        {
            var parser = new AttributeParser(@" a:b b:ccc='eee' eee:c=e ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "b", "ccc", "eee", ParsedAttributeType.String);
            AssertAttribute(parser, "eee", "c", "e", ParsedAttributeType.Reference);
        }
Example #30
0
        public void Expressions()
        {
            var parser = new AttributeParser("aaa=#{1+1} bb=#{\"t\"} c=#{f.ToString()} d=#{f=>\\{return 1\\}}");

            parser.Parse();

            Assert.AreEqual(4, parser.Attributes.Count);
            AssertAttribute(parser, "aaa", "1+1", ParsedAttributeType.Expression);
            AssertAttribute(parser, "bb", "\"t\"", ParsedAttributeType.Expression);
            AssertAttribute(parser, "c", "f.ToString()", ParsedAttributeType.Expression);
            AssertAttribute(parser, "d", @"f=>\{return 1\}", ParsedAttributeType.Expression);
        }
Example #31
0
        public void SpacesBettwenKeyAndValue()
        {
            var parser = new AttributeParser("a =a bbb= b c = 'c'  dd  =  #{d} ");

            parser.Parse();

            Assert.AreEqual(4, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.Reference);
            AssertAttribute(parser, "bbb", "b", ParsedAttributeType.Reference);
            AssertAttribute(parser, "c", "c", ParsedAttributeType.String);
            AssertAttribute(parser, "dd", "d", ParsedAttributeType.Expression);
        }
Example #32
0
        public void ReferenceAsValue()
        {
            var parser = new AttributeParser("aa=b c=d eee=f ff=ff.aa ggg=ggg.bb.aa");

            parser.Parse();

            Assert.AreEqual(5, parser.Attributes.Count);
            AssertAttribute(parser, "aa", "b", ParsedAttributeType.Reference);
            AssertAttribute(parser, "c", "d", ParsedAttributeType.Reference);
            AssertAttribute(parser, "eee", "f", ParsedAttributeType.Reference);
            AssertAttribute(parser, "ff", "ff.aa", ParsedAttributeType.Reference);
            AssertAttribute(parser, "ggg", "ggg.bb.aa", ParsedAttributeType.Reference);
        }
Example #33
0
        public void TestValidPermutations_Manual()
        {
            Console.WriteLine("Input,Visibility,Name,Type,Min,Max,Required,Identity,Value");
            foreach (string s in input)
            {
                string _input = s?.Split('{')[0].Trim(';');
                if (s == null)
                {
                    throw new Exception("bad input");
                }

                ParseResult result = AttributeParser.Parse(_input);
                Assert.IsNotNull(result, s);
                Console.WriteLine($"{s},{result.SetterVisibility ?? SetterAccessModifier.Public},{result.Name},{result.Type ?? "string"},{result.MinLength ?? 0},{result.MaxLength ?? 0},{result.Required ?? false},{result.IsIdentity},{result.InitialValue ?? "(null)"}");
            }
        }
Example #34
0
            public void SchemaOnly()
            {
            var parser = new AttributeParser(" a:b ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", "b", ParsedAttributeType.String);
            }
Example #35
0
            public void Schema()
            {
            var parser = new AttributeParser(@" a:b b:ccc='eee' eee:c=e ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "b", "ccc", "eee", ParsedAttributeType.String);
            AssertAttribute(parser, "eee", "c", "e", ParsedAttributeType.Reference);
            }
Example #36
0
            public void SingleQuotes()
            {
            var parser = new AttributeParser("a='b' c='d' ee='f'");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
            AssertAttribute(parser, "c", "d", ParsedAttributeType.String);
            AssertAttribute(parser, "ee", "f", ParsedAttributeType.String);
            }
Example #37
0
            public void SimpleSchemaReference()
            {
            var parser = new AttributeParser(" xml:lang=en:us ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "xml", "lang", "en:us", ParsedAttributeType.Reference);
            }
Example #38
0
            public void Expressions()
            {
            var parser = new AttributeParser("aaa=#{1+1} bb=#{\"t\"} c=#{f.ToString()} d=#{f=>\\{return 1\\}}");

            parser.Parse();

            Assert.AreEqual(4, parser.Attributes.Count);
            AssertAttribute(parser, "aaa", "1+1", ParsedAttributeType.Expression);
            AssertAttribute(parser, "bb", "\"t\"", ParsedAttributeType.Expression);
            AssertAttribute(parser, "c", "f.ToString()", ParsedAttributeType.Expression);
            AssertAttribute(parser, "d", @"f=>\{return 1\}", ParsedAttributeType.Expression);
            }
Example #39
0
            public void ExpressionInsideOfDoubleSingleQuotesAndEncodedQuotes()
            {
            var parser = new AttributeParser("a='#{\"a\"}' c=\"#{a}\"");

            parser.Parse();

            Assert.AreEqual(2, parser.Attributes.Count);
            AssertAttribute(parser, "a", "#{\"a\"}", ParsedAttributeType.String);
            AssertAttribute(parser, "c", "#{a}", ParsedAttributeType.String);
            }
Example #40
0
            public void ValueEndsWithCurly()
            {
            var parser = new AttributeParser(@" a=text} ");
            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "text
        }
Example #41
0
            public void SimpleOnlyReferenceWithSpace()
            {
            var parser = new AttributeParser("a ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.String);
            }
Example #42
0
        static void Main(string[] args)
        {
            IParser parser = new AttributeParser();

            parser.Parse();
        }
Example #43
0
        public void ExpressionWithoutHash()
        {
            var parser = new AttributeParser(@"src = Html.Content().AppRoot() ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "src", "Html.Content().AppRoot()", ParsedAttributeType.Reference);
        }
Example #44
0
        private static string AppendCreateDictionaryLocalVariable(string dictionary, CodeDomClassBuilder builder)
        {
            var parser = new AttributeParser(dictionary);

            parser.Parse();


            var keyValuePairType = new CodeTypeReference(typeof(KeyValuePair <string, object>));

            var createDictionaryMethod = new CodeMethodInvokeExpression();


            foreach (var attribute in parser.Attributes)
            {
                var newKeyValueExpression = new CodeObjectCreateExpression {
                    CreateType = keyValuePairType
                };

                var keyExpression = new CodePrimitiveExpression {
                    Value = attribute.Name
                };
                newKeyValueExpression.Parameters.Add(keyExpression);

                if (attribute.Type == ParsedAttributeType.String)
                {
                    var expressionStringParser = new ExpressionStringParser(attribute.Value);

                    expressionStringParser.Parse();
                    var values = expressionStringParser.Tokens;
                    if (values.Count == 1)
                    {
                        var expressionStringToken = values[0];
                        if (expressionStringToken.IsExpression)
                        {
                            newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                            {
                                Value = expressionStringToken.Value
                            });
                        }
                        else
                        {
                            newKeyValueExpression.Parameters.Add(new CodePrimitiveExpression
                            {
                                Value = expressionStringToken.Value
                            });
                        }
                    }
                    else
                    {
                        var concatExpression = CodeDomClassBuilder.GetConcatExpression(values);
                        newKeyValueExpression.Parameters.Add(concatExpression);
                    }
                }
                else
                {
                    newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                    {
                        Value = attribute.Value
                    });
                }


                createDictionaryMethod.Parameters.Add(newKeyValueExpression);
            }



            var getDictionaryMethod = new CodeMethodReferenceExpression
            {
                MethodName   = "GetDictionaryFromKeyValue",
                TargetObject =
                    new CodeVariableReferenceExpression
                {
                    VariableName = "NHamlMonoRailView"
                }
            };

            createDictionaryMethod.Method = getDictionaryMethod;

            var variableName = "nhamlTempDictionary" + tempDictionaryCount;

            tempDictionaryCount++;
            var _decl1 = new CodeVariableDeclarationStatement
            {
                InitExpression = createDictionaryMethod,
                Name           = variableName,
                Type           = new CodeTypeReference(typeof(IDictionary <string, object>))
            };

            builder.RenderMethod.Statements.Add(_decl1);
            return(variableName);
        }
Example #45
0
            public void EncodingIsIgnoredIfItIsUsedAsStopper()
            {
            var parser = new AttributeParser(@" a=""abc\\"" b='abc\\' c=#{abc\\} ");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", @"abc\\", ParsedAttributeType.String);
            AssertAttribute(parser, "b", @"abc\\", ParsedAttributeType.String);
            AssertAttribute(parser, "c", @"abc\\", ParsedAttributeType.Expression);
            }
Example #46
0
        private static void ParseAndRenderAttributes(TemplateClassBuilder builder, Match tagMatch)
        {
            var idAndClasses = tagMatch.Groups[2].Value;
            var attributesHash = tagMatch.Groups[4].Value.Trim();

            var match = _idClassesRegex.Match(idAndClasses);

            var classes = new List<string>();

            foreach (Capture capture in match.Groups[2].Captures)
            {
                classes.Add(capture.Value);
            }

            if (classes.Count > 0)
            {
                attributesHash = PrependAttribute(attributesHash, Class, string.Join(" ", classes.ToArray()));
            }

            string id = null;
            foreach (Capture capture in match.Groups[1].Captures)
            {
                id = capture.Value;
                break;
            }

            if (!string.IsNullOrEmpty(id))
            {
                attributesHash = PrependAttribute(attributesHash, Id, id);
            }

            if (string.IsNullOrEmpty(attributesHash))
            {
                return;
            }

            var attributeParser = new AttributeParser(attributesHash);
            attributeParser.Parse();
            foreach (var attribute in attributeParser.Attributes)
            {
                if (attribute.Type == ParsedAttributeType.String)
                {
                    var expressionStringParser = new ExpressionStringParser(attribute.Value);

                    expressionStringParser.Parse();

                    builder.AppendAttributeTokens(attribute.Schema, attribute.Name, expressionStringParser.ExpressionStringTokens);
                }
                else
                {
                    var token = new ExpressionStringToken(attribute.Value, true);

                    builder.AppendAttributeTokens(attribute.Schema, attribute.Name, new[] { token });
                }
            }
        }
Example #47
0
            public void SimpleReference()
            {
            var parser = new AttributeParser(" a=bb ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "bb", ParsedAttributeType.Reference);
            }
Example #48
0
            public void SingleQuoteOpen()
            {
            var parser = new AttributeParser(@" a=text' ");
            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "text'", ParsedAttributeType.Reference);
            }
Example #49
0
            public void ReferenceAsValue()
            {
            var parser = new AttributeParser("aa=b c=d eee=f ff=ff.aa ggg=ggg.bb.aa");

            parser.Parse();

            Assert.AreEqual(5, parser.Attributes.Count);
            AssertAttribute(parser, "aa", "b", ParsedAttributeType.Reference);
            AssertAttribute(parser, "c", "d", ParsedAttributeType.Reference);
            AssertAttribute(parser, "eee", "f", ParsedAttributeType.Reference);
            AssertAttribute(parser, "ff", "ff.aa", ParsedAttributeType.Reference);
            AssertAttribute(parser, "ggg", "ggg.bb.aa", ParsedAttributeType.Reference);
            }
Example #50
0
            public void SpacesBettwenKeyAndValue()
            {
            var parser = new AttributeParser("a =a bbb= b c = 'c'  dd  =  #{d} ");

            parser.Parse();

            Assert.AreEqual(4, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.Reference);
            AssertAttribute(parser, "bbb", "b", ParsedAttributeType.Reference);
            AssertAttribute(parser, "c", "c", ParsedAttributeType.String);
            AssertAttribute(parser, "dd", "d", ParsedAttributeType.Expression);
            }
Example #51
0
            public void OnlyReference()
            {
            var parser = new AttributeParser("a cc e");

            parser.Parse();

            Assert.AreEqual(3, parser.Attributes.Count);
            AssertAttribute(parser, "a", "a", ParsedAttributeType.String);
            AssertAttribute(parser, "cc", "cc", ParsedAttributeType.String);
            AssertAttribute(parser, "e", "e", ParsedAttributeType.String);
            }
Example #52
0
            public void SimpleSingleQuotes()
            {
            var parser = new AttributeParser("a='b'");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "a", "b", ParsedAttributeType.String);
            }
Example #53
0
        public ParseResult ParseTest(string txt)
        {
            ParseResult result = AttributeParser.Parse(txt);

            return(result);
        }
Example #54
0
        private static string AppendCreateDictionaryLocalVariable(string dictionary, CodeDomClassBuilder builder)
        {
            var parser = new AttributeParser(dictionary);
            parser.Parse();


            var keyValuePairType = new CodeTypeReference(typeof(KeyValuePair<string,object>));

            var createDictionaryMethod = new CodeMethodInvokeExpression();


            foreach (var attribute in parser.Attributes)
            {

                var newKeyValueExpression = new CodeObjectCreateExpression {CreateType = keyValuePairType};

                var keyExpression = new CodePrimitiveExpression {Value = attribute.Name};
                newKeyValueExpression.Parameters.Add(keyExpression);

                if (attribute.Type == ParsedAttributeType.String)
                {
                    var expressionStringParser = new ExpressionStringParser(attribute.Value);

                    expressionStringParser.Parse();
                    var values = expressionStringParser.Tokens;
                    if (values.Count == 1)
                    {
                        var expressionStringToken = values[0];
                        if (expressionStringToken.IsExpression)
                        {
                            newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                                                        {
                                                            Value = expressionStringToken.Value

                                                        });
                        }
                        else
                        {

                            newKeyValueExpression.Parameters.Add(new CodePrimitiveExpression
                                                        {
                                                            Value = expressionStringToken.Value

                                                        });
                        }
                    }
                    else
                    {
                        var concatExpression = CodeDomClassBuilder.GetConcatExpression(values);
                        newKeyValueExpression.Parameters.Add(concatExpression);
                    }
                }
                else
                {
                    newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                                                             {
                                                                 Value = attribute.Value

                                                             });

                }


                createDictionaryMethod.Parameters.Add(newKeyValueExpression);
            }



            var getDictionaryMethod = new CodeMethodReferenceExpression
                                          {
                                              MethodName = "GetDictionaryFromKeyValue",
                                              TargetObject =
                                                  new CodeVariableReferenceExpression
                                                      {
                                                          VariableName = "NHamlMonoRailView"
                                                      }
                                          };
            createDictionaryMethod.Method = getDictionaryMethod;

            var variableName = "nhamlTempDictionary" + tempDictionaryCount;
            tempDictionaryCount++;
            var _decl1 = new CodeVariableDeclarationStatement
                             {
                                 InitExpression = createDictionaryMethod,
                                 Name = variableName,
                                 Type = new CodeTypeReference(typeof (IDictionary<string, object>))
                             };
            builder.RenderMethod.Statements.Add(_decl1);
            return variableName;
        }
Example #55
0
        private static string AppendCreateDictionaryLocalVariable(string dictionary, CodeDomClassBuilder builder)
        {
            var parser = new AttributeParser(dictionary);

            parser.Parse();


            var keyValuePairType = new CodeTypeReference(typeof(KeyValuePair <string, object>));

            var createDictionaryMethod = new CodeMethodInvokeExpression();


            foreach (var attribute in parser.Attributes)
            {
                var newKeyValueExpression = new CodeObjectCreateExpression {
                    CreateType = keyValuePairType
                };

                var keyExpression = new CodePrimitiveExpression {
                    Value = attribute.Name
                };
                newKeyValueExpression.Parameters.Add(keyExpression);

                if (attribute.Type == ParsedAttributeType.String)
                {
                    AppendStringDictValue(attribute, newKeyValueExpression);
                }
                else
                {
                    newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
                    {
                        Value = attribute.Value
                    });
                }

                createDictionaryMethod.Parameters.Add(newKeyValueExpression);
            }



            var getDictionaryMethod = new CodeMethodReferenceExpression
            {
                MethodName   = "GetDictionaryFromKeyValue",
                TargetObject =
                    new CodeVariableReferenceExpression
                {
                    VariableName = "NHamlMonoRailView"
                }
            };

            createDictionaryMethod.Method = getDictionaryMethod;

            var variableName = string.Format("nhamlTempDictionary{0}", tempDictionaryCount);

            tempDictionaryCount++;
            var dictionaryDecleration = new CodeVariableDeclarationStatement
            {
                InitExpression = createDictionaryMethod,
                Name           = variableName,
                Type           = new CodeTypeReference(typeof(IDictionary <string, object>))
            };

            builder.RenderMethod.Statements.Add(dictionaryDecleration);
            return(variableName);
        }
Example #56
0
            public void SimpleEncodingIsIgnoredIfItIsUsedAsStopper()
            {
            var parser = new AttributeParser(@"c=#{abc\\} ");

            parser.Parse();

            Assert.AreEqual(1, parser.Attributes.Count);
            AssertAttribute(parser, "c", @"abc\\", ParsedAttributeType.Expression);
            }