コード例 #1
0
        private List <DekiScriptXmlElement.Attribute> BuildAttributes(XmlNode current)
        {
            List <DekiScriptXmlElement.Attribute> result = new List <DekiScriptXmlElement.Attribute>(current.Attributes.Count);

            for (int i = 0; i < current.Attributes.Count; ++i)
            {
                XmlAttribute attribute = current.Attributes[i];
                PushNode(attribute);

                // check if attribute needs to be evaluated
                if (attribute.NamespaceURI == XDekiScript.ScriptNS)
                {
                    // NOTE (steveb): eval:key="value"
                    DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, null, DekiScriptExpression.Constant(attribute.LocalName), Parse(Location, attribute.Value));
                    result.Add(attr);
                }
                else if (attribute.Value.StartsWithInvariant("{{") && attribute.Value.EndsWithInvariant("}}"))
                {
                    // NOTE (steveb): key="{{value}}"
                    DekiScriptExpression           expr = Parse(Location, StripCode(attribute.Value.Substring(2, attribute.Value.Length - 4)));
                    DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, attribute.Prefix, DekiScriptExpression.Constant(attribute.LocalName), expr);
                    result.Add(attr);
                }
                else if (!attribute.NamespaceURI.EqualsInvariant("http://www.w3.org/2000/xmlns/") || !attribute.Value.EqualsInvariant("http://mindtouch.com/2007/dekiscript"))
                {
                    // skip "init", "if", "foreach", "block", "where", "function" since they have already been processed
                    if (!attribute.NamespaceURI.EqualsInvariant(string.Empty) || !(
                            attribute.LocalName.EqualsInvariant("init") ||
                            attribute.LocalName.EqualsInvariant("if") ||
                            attribute.LocalName.EqualsInvariant("foreach") ||
                            attribute.LocalName.EqualsInvariant("where") ||
                            attribute.LocalName.EqualsInvariant("block") ||
                            attribute.LocalName.EqualsInvariant("function")
                            ))
                    {
                        // add static attribute
                        DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, attribute.Prefix, DekiScriptExpression.Constant(attribute.LocalName), DekiScriptExpression.Constant(attribute.Value));
                        result.Add(attr);
                    }
                }
                PopNode();
            }
            return(result);
        }
コード例 #2
0
        private List<DekiScriptXmlElement.Attribute> BuildAttributes(XmlNode current) {
            List<DekiScriptXmlElement.Attribute> result = new List<DekiScriptXmlElement.Attribute>(current.Attributes.Count);
            for(int i = 0; i < current.Attributes.Count; ++i) {
                XmlAttribute attribute = current.Attributes[i];
                PushNode(attribute);

                // check if attribute needs to be evaluated
                if(attribute.NamespaceURI == XDekiScript.ScriptNS) {

                    // NOTE (steveb): eval:key="value"
                    DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, null, DekiScriptExpression.Constant(attribute.LocalName), Parse(Location, attribute.Value));
                    result.Add(attr);
                } else if(attribute.Value.StartsWithInvariant("{{") && attribute.Value.EndsWithInvariant("}}")) {

                    // NOTE (steveb): key="{{value}}"
                    DekiScriptExpression expr = Parse(Location, StripCode(attribute.Value.Substring(2, attribute.Value.Length - 4)));
                    DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, attribute.Prefix, DekiScriptExpression.Constant(attribute.LocalName), expr);
                    result.Add(attr);
                } else if(!attribute.NamespaceURI.EqualsInvariant("http://www.w3.org/2000/xmlns/") || !attribute.Value.EqualsInvariant("http://mindtouch.com/2007/dekiscript")) {

                    // skip "init", "if", "foreach", "block", "where", "function" since they have already been processed
                    if(!attribute.NamespaceURI.EqualsInvariant(string.Empty) || !(
                        attribute.LocalName.EqualsInvariant("init") ||
                        attribute.LocalName.EqualsInvariant("if") ||
                        attribute.LocalName.EqualsInvariant("foreach") ||
                        attribute.LocalName.EqualsInvariant("where") ||
                        attribute.LocalName.EqualsInvariant("block") ||
                        attribute.LocalName.EqualsInvariant("function")
                    )) {

                        // add static attribute
                        DekiScriptXmlElement.Attribute attr = new DekiScriptXmlElement.Attribute(Location, attribute.Prefix, DekiScriptExpression.Constant(attribute.LocalName), DekiScriptExpression.Constant(attribute.Value));
                        result.Add(attr);
                    }
                }
                PopNode();
            }
            return result;
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: StackableRegiments/metl2011
	void XmlAttribute(out DekiScriptXmlElement.Attribute attribute) {
		string name = null; 
		string text = null;
		bool block = false;
		DekiScriptExpression expr = null; 
		attribute = null; 
		DekiScriptExpression nameExpr = null; 
		Location location = Location.None;
		
		if (StartOf(11)) {
			AnyName(out name);
			location = t.Location; 
		} else if (la.kind == 22) {
			Get();
			Expression(out nameExpr);
			Expect(23);
			location = nameExpr.Location; 
		} else SynErr(97);
		Expect(12);
		if (la.kind == 3 || la.kind == 4) {
			AnyString(out text, out block);
			if(!block && StringUtil.StartsWithInvariant(text, "{{") && StringUtil.EndsWithInvariant(text, "}}")) {
			expr = DekiScriptParser.Parse(new Location(t.origin, t.line, t.col + 3), text.Substring(2, text.Length - 4)); 
			} else {
				expr = DekiScriptExpression.Constant(text); 
			}
			
		} else if (la.kind == 22) {
			Get();
			Statements(out expr);
			Expect(23);
		} else SynErr(98);
		attribute = new DekiScriptXmlElement.Attribute(location, null, nameExpr ?? DekiScriptExpression.Constant(name), expr); 
	}