private void CompileConditions(Compiler compiler) { NavigatorInput input = compiler.Input; bool when = false; bool otherwise = false; do { switch (input.NodeType) { case XPathNodeType.Element: compiler.PushNamespaceScope(); string nspace = input.NamespaceURI; string name = input.LocalName; if (Ref.Equal(nspace, input.Atoms.UriXsl)) { IfAction action = null; if (Ref.Equal(name, input.Atoms.When)) { if (otherwise) { throw XsltException.Create(Res.Xslt_WhenAfterOtherwise); } action = compiler.CreateIfAction(IfAction.ConditionType.ConditionWhen); when = true; } else if (Ref.Equal(name, input.Atoms.Otherwise)) { if (otherwise) { throw XsltException.Create(Res.Xslt_DupOtherwise); } action = compiler.CreateIfAction(IfAction.ConditionType.ConditionOtherwise); otherwise = true; } else { throw compiler.UnexpectedKeyword(); } AddAction(action); } else { throw compiler.UnexpectedKeyword(); } compiler.PopScope(); break; case XPathNodeType.Comment: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw XsltException.Create(Res.Xslt_InvalidContents, "choose"); } } while (compiler.Advance()); if (! when) { throw XsltException.Create(Res.Xslt_NoWhen); } }
private void CompileInstruction(Compiler compiler) { NavigatorInput input = compiler.Input; CompiledAction?action = null; Debug.Assert(Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl)); string name = input.LocalName; if (Ref.Equal(name, input.Atoms.ApplyImports)) { action = compiler.CreateApplyImportsAction(); } else if (Ref.Equal(name, input.Atoms.ApplyTemplates)) { action = compiler.CreateApplyTemplatesAction(); } else if (Ref.Equal(name, input.Atoms.Attribute)) { action = compiler.CreateAttributeAction(); } else if (Ref.Equal(name, input.Atoms.CallTemplate)) { action = compiler.CreateCallTemplateAction(); } else if (Ref.Equal(name, input.Atoms.Choose)) { action = compiler.CreateChooseAction(); } else if (Ref.Equal(name, input.Atoms.Comment)) { action = compiler.CreateCommentAction(); } else if (Ref.Equal(name, input.Atoms.Copy)) { action = compiler.CreateCopyAction(); } else if (Ref.Equal(name, input.Atoms.CopyOf)) { action = compiler.CreateCopyOfAction(); } else if (Ref.Equal(name, input.Atoms.Element)) { action = compiler.CreateElementAction(); } else if (Ref.Equal(name, input.Atoms.Fallback)) { return; } else if (Ref.Equal(name, input.Atoms.ForEach)) { action = compiler.CreateForEachAction(); } else if (Ref.Equal(name, input.Atoms.If)) { action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf); } else if (Ref.Equal(name, input.Atoms.Message)) { action = compiler.CreateMessageAction(); } else if (Ref.Equal(name, input.Atoms.Number)) { action = compiler.CreateNumberAction(); } else if (Ref.Equal(name, input.Atoms.ProcessingInstruction)) { action = compiler.CreateProcessingInstructionAction(); } else if (Ref.Equal(name, input.Atoms.Text)) { action = compiler.CreateTextAction(); } else if (Ref.Equal(name, input.Atoms.ValueOf)) { action = compiler.CreateValueOfAction(); } else if (Ref.Equal(name, input.Atoms.Variable)) { action = compiler.CreateVariableAction(VariableType.LocalVariable); } else { if (compiler.ForwardCompatibility) { action = compiler.CreateNewInstructionAction(); } else { throw compiler.UnexpectedKeyword(); } } Debug.Assert(action != null); AddAction(action); }
private void CompileConditions(Compiler compiler) { NavigatorInput input = compiler.Input; bool when = false; bool otherwise = false; do { switch (input.NodeType) { case XPathNodeType.Element: compiler.PushNamespaceScope(); string nspace = input.NamespaceURI; string name = input.LocalName; if (Keywords.Equals(nspace, input.Atoms.XsltNamespace)) { IfAction action = null; if (Keywords.Equals(name, input.Atoms.When)) { if (otherwise) { throw XsltException.Create(Res.Xslt_WhenAfterOtherwise); } action = compiler.CreateIfAction(IfAction.ConditionType.ConditionWhen); when = true; } else if (Keywords.Equals(name, input.Atoms.Otherwise)) { if (otherwise) { throw XsltException.Create(Res.Xslt_DupOtherwise); } action = compiler.CreateIfAction(IfAction.ConditionType.ConditionOtherwise); otherwise = true; } else { throw compiler.UnexpectedKeyword(); } AddAction(action); } else { throw compiler.UnexpectedKeyword(); } compiler.PopScope(); break; case XPathNodeType.Comment: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw XsltException.Create(Res.Xslt_InvalidContents, Keywords.s_Choose); } }while (compiler.Advance()); if (!when) { throw XsltException.Create(Res.Xslt_NoWhen); } }
void CompileInstruction(Compiler compiler) { NavigatorInput input = compiler.Input; CompiledAction action = null; Debug.Assert(Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl)); string name = input.LocalName; if (Ref.Equal(name, input.Atoms.ApplyImports)) { action = compiler.CreateApplyImportsAction(); } else if (Ref.Equal(name, input.Atoms.ApplyTemplates)) { action = compiler.CreateApplyTemplatesAction(); } else if (Ref.Equal(name, input.Atoms.Attribute)) { action = compiler.CreateAttributeAction(); } else if (Ref.Equal(name, input.Atoms.CallTemplate)) { action = compiler.CreateCallTemplateAction(); } else if (Ref.Equal(name, input.Atoms.Choose)) { action = compiler.CreateChooseAction(); } else if (Ref.Equal(name, input.Atoms.Comment)) { action = compiler.CreateCommentAction(); } else if (Ref.Equal(name, input.Atoms.Copy)) { action = compiler.CreateCopyAction(); } else if (Ref.Equal(name, input.Atoms.CopyOf)) { action = compiler.CreateCopyOfAction(); } else if (Ref.Equal(name, input.Atoms.Element)) { action = compiler.CreateElementAction(); } else if (Ref.Equal(name, input.Atoms.Fallback)) { return; } else if (Ref.Equal(name, input.Atoms.ForEach)) { action = compiler.CreateForEachAction(); } else if (Ref.Equal(name, input.Atoms.If)) { action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf); } else if (Ref.Equal(name, input.Atoms.Message)) { action = compiler.CreateMessageAction(); } else if (Ref.Equal(name, input.Atoms.Number)) { action = compiler.CreateNumberAction(); } else if (Ref.Equal(name, input.Atoms.ProcessingInstruction)) { action = compiler.CreateProcessingInstructionAction(); } else if (Ref.Equal(name, input.Atoms.Text)) { action = compiler.CreateTextAction(); } else if (Ref.Equal(name, input.Atoms.ValueOf)) { action = compiler.CreateValueOfAction(); } else if (Ref.Equal(name, input.Atoms.Variable)) { action = compiler.CreateVariableAction(VariableType.LocalVariable); } else { if (compiler.ForwardCompatibility) action = compiler.CreateNewInstructionAction(); else throw compiler.UnexpectedKeyword(); } Debug.Assert(action != null); AddAction(action); }