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); }
public DekiScriptExpression Visit(DekiScriptXmlElement expr, DekiScriptExpressionEvaluationState state) { // TODO (steveb): missing code return(expr); }
public DekiScriptOutputBuffer.Range Visit(DekiScriptXmlElement expr, DekiScriptExpressionEvaluationState state) { // check if any namespaces are being defined state.Namespaces.PushScope(); int marker = state.Buffer.Marker; try { Dictionary <string, string> namespaces = null; List <Tuplet <string, string, string> > attributes = null; string ctor = null; string id = null; string type = null; // TODO (steveb): validate that all prefixes are defined! // evaluate element name string name = XmlConvert.EncodeLocalName(state.Pop(expr.Name.VisitWith(this, state)).AsString()); // loop over all attributes foreach (var attribute in expr.Attributes) { string attrPrefix = attribute.Prefix; string attrName = state.Pop(attribute.Name.VisitWith(this, state)).AsString(); if (string.IsNullOrEmpty(attrName)) { continue; } string attrValue = state.Pop(attribute.Value.VisitWith(this, state)).AsString(); if (attrValue == null) { continue; } bool isNamespaceDeclaration = string.IsNullOrEmpty(attrPrefix) ? attrName.EqualsInvariant(XMLNS) : attrPrefix.EqualsInvariant(XMLNS); // check if attribute is a namespace declaration if (isNamespaceDeclaration) { // add attribute to namespace declarations namespaces = namespaces ?? new Dictionary <string, string>(); // check if the default namespace is being defined if (string.IsNullOrEmpty(attrPrefix)) { namespaces.Add(string.Empty, attrValue); } else { namespaces.Add(attrName, attrValue); } } else { // add attribute to list of attributes attributes = attributes ?? new List <Tuplet <string, string, string> >(); attributes.Add(new Tuplet <string, string, string>(attrPrefix, attrName, attrValue)); if (string.IsNullOrEmpty(attrPrefix)) { switch (attrName) { case "ctor": ctor = attrValue; break; case "id": id = attrValue; break; case "type": type = attrValue; break; } } } } // check if current node needs to be replaced entirely string jem = null; if (string.IsNullOrEmpty(expr.Prefix) && !string.IsNullOrEmpty(type) && name.EqualsInvariant("script") && type.EqualsInvariant("text/jem")) { // NOTE: process <script type="text/jem"> // evaluate nested expressions DekiScriptLiteral contents = state.Pop(expr.Node.VisitWith(this, state)); if (contents is DekiScriptString) { jem = ((DekiScriptString)contents).Value; } else { jem = contents.ToString(); } jem = DekiJemProcessor.Parse(jem, null, state.Env, state.Runtime); } else { // check if @ctor is defined without an @id if (!string.IsNullOrEmpty(ctor) && (id == null)) { id = StringUtil.CreateAlphaNumericKey(8); attributes.Add(new Tuplet <string, string, string>(null, "id", id)); } // append start xml element to buffer state.Buffer.PushXmlStart(expr.Prefix, name, namespaces, attributes); // evaluate nested expressions expr.Node.VisitWith(this, state); // append end xml element to buffer state.Buffer.PushXmlEnd(); // check if the element has a JEM @ctor attribute if (!string.IsNullOrEmpty(ctor)) { // generate JEM code jem = DekiJemProcessor.Parse(ctor, id, state.Env, state.Runtime); } } // check if JEM code was generated if (jem != null) { // create <script> element var scriptAttributes = new List <Tuplet <string, string, string> > { new Tuplet <string, string, string>(null, "type", "text/javascript") }; state.Buffer.PushXmlStart(null, "script", null, scriptAttributes); state.Push(DekiScriptExpression.Constant(jem)); state.Buffer.PushXmlEnd(); } } catch { state.Buffer.Reset(marker); throw; } finally { // restore previous xml namespace definitions state.Namespaces.PopScope(); } return(state.Buffer.Since(marker)); }