1using System.Collections.Generic;
20 return context.InputNode.Name ==
"bs:if";
34 out IEnumerable<HtmlNode>? elseBranch)
36 List<(HtmlAttribute, IEnumerable<HtmlNode>)> branches =
new List<(HtmlAttribute, IEnumerable<HtmlNode>)>();
37 List<HtmlNode> currentBranch =
new List<HtmlNode>();
38 HtmlAttribute? conditionAttribute = node.Attributes[
"test"];
40 if (conditionAttribute ==
null)
44 "Missing 'test' attribute in 'bs:if' node",
49 if (
string.IsNullOrEmpty(conditionAttribute.Value))
53 "Empty 'test' attribute in 'bs:if' node",
58 foreach (HtmlNode child
in node.ChildNodes)
60 if (child.Name ==
"bs:else")
62 branches.Add((conditionAttribute!, currentBranch));
64 currentBranch =
new List<HtmlNode>();
65 HtmlAttribute? nextCondition = child.Attributes[
"test"];
67 if (conditionAttribute ==
null)
69 if (nextCondition !=
null)
72 context.ExecutionContext.Scope,
73 "Found bs:else node with attribute 'test' after bs:else node without 'test' attribute",
74 context.CreateAttributePosition(nextCondition)
79 context.ExecutionContext.Scope,
80 "Found bs:else node after bs:else node without 'test' attribute",
81 context.CreateInnerPosition()
85 conditionAttribute = child.Attributes[
"test"];
87 if (conditionAttribute ==
null)
92 if (
string.IsNullOrEmpty(conditionAttribute.Value))
95 context.ExecutionContext.Scope,
96 "Empty 'test' attribute in 'bs:else' node",
97 context.CreateAttributePosition(conditionAttribute)
103 currentBranch.Add(child);
107 if (conditionAttribute ==
null)
109 elseBranch = currentBranch;
114 branches.Add((conditionAttribute, currentBranch));
130 conditionAttribute.Value,
138 "Result of 'test' attribute in 'bs:if' node is not a boolean",
149 List<(HtmlAttribute, IEnumerable<HtmlNode>)> branches =
152 bool executedAny =
false;
154 foreach ((HtmlAttribute condition, IEnumerable<HtmlNode> block) branch in branches)
170 foreach (HtmlNode? child
in branch.block)
178 if (executedAny || elseBranch ==
null)
191 foreach (HtmlNode? child
in elseBranch)
Implements the Html Context for the Transformation Process.
BadSourcePosition CreateAttributePosition(HtmlAttribute attribute)
Creates the Source Position of the specified Attribute.
BadSourcePosition CreateOuterPosition()
Creates the Source Position of the current Input Nodes Outer Content.
BadHtmlContext CreateChild(HtmlNode inputNode, HtmlNode outputNode, BadExecutionContext? executionContext=null)
Creates a child context with the specified input, output node and optional execution context.
readonly HtmlNode InputNode
The Current Input Node.
readonly BadExecutionContext ExecutionContext
The Execution Context that is used to evaluate badscript code.
readonly HtmlNode OutputNode
The Current Output Node.
BadObject ParseAndExecuteSingle(string code, BadSourcePosition pos)
Parses and executes the specified code and returns the result of the last expression.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Gets thrown by the runtime.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Base Class for all BadScript Objects.
Implements the Interface for Native Boolean.
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Contains the Runtime Objects.
Contains the Runtime Implementation.