BadScript 2
Loading...
Searching...
No Matches
BadHtml.BadHtmlContext Class Reference

Implements the Html Context for the Transformation Process. More...

Public Member Functions

 BadHtmlContext (HtmlNode inputNode, HtmlNode outputNode, BadExecutionContext executionContext, string filePath, string source, BadHtmlTemplateOptions options, IFileSystem fileSystem)
 Constructs a new Html Context.
 
BadHtmlContext CreateChild (HtmlNode inputNode, HtmlNode outputNode, BadExecutionContext? executionContext=null)
 Creates a child context with the specified input, output node and optional execution context.
 
BadSourcePosition CreateAttributePosition (HtmlAttribute attribute)
 Creates the Source Position of the specified Attribute.
 
BadSourcePosition CreateInnerPosition ()
 Creates the Source Position of the current Input Nodes Inner Content.
 
BadSourcePosition CreateOuterPosition ()
 Creates the Source Position of the current Input Nodes Outer Content.
 
BadExpression ParseSingle (string code, BadSourcePosition pos)
 Parses a single Expression from the specified code and returns it with its position set to the specified position.
 
BadExpression[] Parse (string code, BadSourcePosition pos)
 Parses the specified code and returns the expressions with their positions set to the specified position.
 
BadObject Execute (IEnumerable< BadExpression > expressions, BadSourcePosition position)
 Executes the specified expressions.
 
BadObject Execute (BadExpression expression, BadSourcePosition position)
 Executes the specified expression.
 
BadObject ParseAndExecute (string code, BadSourcePosition pos)
 Parses and executes the specified code.
 
BadObject ParseAndExecuteSingle (string code, BadSourcePosition pos)
 Parses and executes the specified code and returns the result of the last expression.
 

Public Attributes

readonly BadExecutionContext ExecutionContext
 The Execution Context that is used to evaluate badscript code.
 
readonly string FilePath
 The File Path of the Template.
 
readonly HtmlNode InputNode
 The Current Input Node.
 
readonly BadHtmlTemplateOptions Options
 The Html Template Options.
 
readonly HtmlNode OutputNode
 The Current Output Node.
 
readonly string Source
 The Source Code of the Template.
 

Properties

IFileSystem FileSystem [get]
 The Filesystem of the Current Template Context.
 
HtmlDocument InputDocument [get]
 The Input Document.
 
HtmlDocument OutputDocument [get]
 The Output Document.
 

Static Private Member Functions

static IEnumerable< BadExpressionVisitAll (IEnumerable< BadExpression > expressions)
 Returns an enumeration of all expressions in the specified expressions and their descendants.
 

Detailed Description

Implements the Html Context for the Transformation Process.

Definition at line 24 of file BadHtmlContext.cs.

Constructor & Destructor Documentation

◆ BadHtmlContext()

BadHtml.BadHtmlContext.BadHtmlContext ( HtmlNode  inputNode,
HtmlNode  outputNode,
BadExecutionContext  executionContext,
string  filePath,
string  source,
BadHtmlTemplateOptions  options,
IFileSystem  fileSystem 
)

Constructs a new Html Context.

Parameters
inputNodeThe Input Node
outputNodeThe Output Node
executionContextThe Execution Context
filePathThe File Path of the Template
sourceThe Source of the Template
optionsThe Html Template Options
fileSystemThe Filesystem of the Current Template Context

Definition at line 66 of file BadHtmlContext.cs.

73 {
74 InputNode = inputNode;
75 OutputNode = outputNode;
76 ExecutionContext = executionContext;
77 FilePath = filePath;
78 Source = source;
79 Options = options;
80 FileSystem = fileSystem;
81 }
IFileSystem FileSystem
The Filesystem of the Current Template Context.
readonly BadHtmlTemplateOptions Options
The Html Template Options.
readonly string Source
The Source Code of the Template.
readonly string FilePath
The File Path of the Template.
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.

Member Function Documentation

◆ CreateAttributePosition()

BadSourcePosition BadHtml.BadHtmlContext.CreateAttributePosition ( HtmlAttribute  attribute)

Creates the Source Position of the specified Attribute.

Parameters
attributeThe Attribute
Returns
Source Position

Definition at line 127 of file BadHtmlContext.cs.

128 {
129 return new BadSourcePosition(FilePath, Source, attribute.ValueStartIndex, attribute.Value.Length);
130 }
Describes a specific position inside a source file.

◆ CreateChild()

BadHtmlContext BadHtml.BadHtmlContext.CreateChild ( HtmlNode  inputNode,
HtmlNode  outputNode,
BadExecutionContext executionContext = null 
)

Creates a child context with the specified input, output node and optional execution context.

Parameters
inputNodeThe Input Node
outputNodeThe Output Node
executionContextThe Optional Execution Context. If not specified, the context will be inherited from this instance
Returns
Child Context

Definition at line 108 of file BadHtmlContext.cs.

111 {
112 return new BadHtmlContext(inputNode,
113 outputNode,
114 executionContext ?? ExecutionContext,
115 FilePath,
116 Source,
117 Options,
119 );
120 }
BadHtmlContext(HtmlNode inputNode, HtmlNode outputNode, BadExecutionContext executionContext, string filePath, string source, BadHtmlTemplateOptions options, IFileSystem fileSystem)
Constructs a new Html Context.

◆ CreateInnerPosition()

BadSourcePosition BadHtml.BadHtmlContext.CreateInnerPosition ( )

Creates the Source Position of the current Input Nodes Inner Content.

Returns
Source Position

Definition at line 136 of file BadHtmlContext.cs.

137 {
138 return new BadSourcePosition(FilePath, Source, InputNode.InnerStartIndex, InputNode.InnerLength);
139 }

◆ CreateOuterPosition()

BadSourcePosition BadHtml.BadHtmlContext.CreateOuterPosition ( )

Creates the Source Position of the current Input Nodes Outer Content.

Returns
Source Position

Definition at line 145 of file BadHtmlContext.cs.

146 {
147 return new BadSourcePosition(FilePath, Source, InputNode.InnerStartIndex, InputNode.InnerLength);
148 }

◆ Execute() [1/2]

BadObject BadHtml.BadHtmlContext.Execute ( BadExpression  expression,
BadSourcePosition  position 
)

Executes the specified expression.

Parameters
expressionThe Expression
positionThe Source Position of the Expression
Returns
The Result of the Execution
Exceptions
BadRuntimeErrorExceptionGets raised if the execution failed.
BadRuntimeExceptionGets raised if the execution failed.

Definition at line 275 of file BadHtmlContext.cs.

276 {
277 try
278 {
279 BadObject result = ExecutionContext.ExecuteScript(expression);
280
281 // if (ExecutionContext.Scope.IsError)
282 // {
283 // throw new BadRuntimeErrorException(ExecutionContext.Scope.Error);
284 // }
285
286 return result.Dereference(null);
287 }
288 catch (BadRuntimeException e)
289 {
290 throw new BadRuntimeException(e.Message, position);
291 }
292 }
BadObject ExecuteScript(IEnumerable< BadExpression > expressions)
Executes an enumeration of expressions and returns the last value.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14

◆ Execute() [2/2]

BadObject BadHtml.BadHtmlContext.Execute ( IEnumerable< BadExpression expressions,
BadSourcePosition  position 
)

Executes the specified expressions.

Parameters
expressionsThe Expressions
positionThe Source Position of the Expressions
Returns
The Result of the Execution
Exceptions
BadRuntimeErrorExceptionGets raised if the execution failed.

Definition at line 253 of file BadHtmlContext.cs.

254 {
255 try
256 {
257 BadObject result = ExecutionContext.ExecuteScript(expressions);
258
259 return result.Dereference(null);
260 }
261 catch (BadRuntimeException e)
262 {
263 throw new BadRuntimeException(e.Message, position);
264 }
265 }

◆ Parse()

BadExpression[] BadHtml.BadHtmlContext.Parse ( string  code,
BadSourcePosition  pos 
)

Parses the specified code and returns the expressions with their positions set to the specified position.

Parameters
codeThe Bad Script Source Code
posThe Source Position of the Code
Returns
Parsed Expressions
Exceptions
BadSourceReaderExceptionGets raised if the Source Could not be parsed.

Definition at line 210 of file BadHtmlContext.cs.

211 {
212 try
213 {
214 BadExpression[] expressions = BadSourceParser.Parse(FilePath, code)
215 .ToArray();
216
217 foreach (BadExpression expression in VisitAll(expressions))
218 {
220 Source,
221 pos.Index + expression.Position.Index,
222 expression.Position.Length
223 );
224 expression.SetPosition(newPosition);
225 }
226
227 return expressions;
228 }
230 {
231 if (e.Position == null)
232 {
234 }
235
238 Source,
239 e.Position.Index + pos.Index,
241 )
242 );
243 }
244 }
static IEnumerable< BadExpression > VisitAll(IEnumerable< BadExpression > expressions)
Returns an enumeration of all expressions in the specified expressions and their descendants.
BadSourcePosition? Position
The source position of where the error occurred.
string OriginalMessage
The Original Error Message.
static BadSourcePosition Create(string fileName, string source, int index, int length)
Creates a new Source Position.
int Index
The Start Index of the Position.
int Length
The Length of the Position.
The Parser of the Language. It turns Source Code into an Expression Tree.
static IEnumerable< BadExpression > Parse(string fileName, string source)
Parses a BadExpression from the Source Reader.
Base Implementation for all Expressions used inside the Script.
BadSourcePosition Position
The source Position of the Expression.
void SetPosition(BadSourcePosition pos)
Sets the Source Position of the Expression.
Gets Raised if the Reader encounters an Error.

◆ ParseAndExecute()

BadObject BadHtml.BadHtmlContext.ParseAndExecute ( string  code,
BadSourcePosition  pos 
)

Parses and executes the specified code.

Parameters
codeThe Bad Script Source Code
posThe Source Position of the Code
Returns
The Result of the Execution

Definition at line 300 of file BadHtmlContext.cs.

301 {
302 BadExpression[] expressions = Parse(code, pos);
303
304 return Execute(expressions, pos);
305 }
BadExpression[] Parse(string code, BadSourcePosition pos)
Parses the specified code and returns the expressions with their positions set to the specified posit...
BadObject Execute(IEnumerable< BadExpression > expressions, BadSourcePosition position)
Executes the specified expressions.

◆ ParseAndExecuteSingle()

BadObject BadHtml.BadHtmlContext.ParseAndExecuteSingle ( string  code,
BadSourcePosition  pos 
)

Parses and executes the specified code and returns the result of the last expression.

Parameters
codeThe Bad Script Source Code
posThe Source Position of the Code
Returns
The Result of the Execution

Definition at line 313 of file BadHtmlContext.cs.

314 {
315 BadExpression expression = ParseSingle(code, pos);
316
317 return Execute(expression, pos);
318 }
BadExpression ParseSingle(string code, BadSourcePosition pos)
Parses a single Expression from the specified code and returns it with its position set to the specif...

◆ ParseSingle()

BadExpression BadHtml.BadHtmlContext.ParseSingle ( string  code,
BadSourcePosition  pos 
)

Parses a single Expression from the specified code and returns it with its position set to the specified position.

Parameters
codeThe Bad Script Source Code
posThe Source Position of the Code
Returns
Parsed Expression
Exceptions
BadSourceReaderExceptionGets raised if the Source Could not be parsed.

Definition at line 167 of file BadHtmlContext.cs.

168 {
169 try
170 {
172 BadExpression expression = parser.ParseExpression();
173
174 foreach (BadExpression expr in expression.GetDescendantsAndSelf())
175 {
177 Source,
178 pos.Index + expr.Position.Index,
179 expr.Position.Length
180 );
181 expr.SetPosition(newPosition);
182 }
183
184 return expression;
185 }
187 {
188 if (e.Position == null)
189 {
191 }
192
195 Source,
196 e.Position.Index + pos.Index,
198 )
199 );
200 }
201 }
static BadSourceParser Create(string fileName, string source)
Creates a BadSourceParser Instance based on the source and filename provided.
BadExpression ParseExpression(BadExpression? left=null, int precedence=int.MaxValue)
Parses an Expression with a precedence greater than the given precedence. Moves the reader to the nex...
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.

◆ VisitAll()

static IEnumerable< BadExpression > BadHtml.BadHtmlContext.VisitAll ( IEnumerable< BadExpression expressions)
staticprivate

Returns an enumeration of all expressions in the specified expressions and their descendants.

Parameters
expressionsThe Expression Enumeration
Returns
Enumeration of all Expressions in the Tree

Definition at line 155 of file BadHtmlContext.cs.

156 {
157 return expressions.SelectMany(expression => expression.GetDescendantsAndSelf());
158 }

Member Data Documentation

◆ ExecutionContext

readonly BadExecutionContext BadHtml.BadHtmlContext.ExecutionContext

The Execution Context that is used to evaluate badscript code.

Definition at line 29 of file BadHtmlContext.cs.

◆ FilePath

readonly string BadHtml.BadHtmlContext.FilePath

The File Path of the Template.

Definition at line 34 of file BadHtmlContext.cs.

◆ InputNode

readonly HtmlNode BadHtml.BadHtmlContext.InputNode

The Current Input Node.

Definition at line 39 of file BadHtmlContext.cs.

◆ Options

readonly BadHtmlTemplateOptions BadHtml.BadHtmlContext.Options

The Html Template Options.

Definition at line 44 of file BadHtmlContext.cs.

◆ OutputNode

readonly HtmlNode BadHtml.BadHtmlContext.OutputNode

The Current Output Node.

Definition at line 49 of file BadHtmlContext.cs.

◆ Source

readonly string BadHtml.BadHtmlContext.Source

The Source Code of the Template.

Definition at line 54 of file BadHtmlContext.cs.

Property Documentation

◆ FileSystem

IFileSystem BadHtml.BadHtmlContext.FileSystem
get

The Filesystem of the Current Template Context.

Definition at line 86 of file BadHtmlContext.cs.

86{ get; }

◆ InputDocument

HtmlDocument BadHtml.BadHtmlContext.InputDocument
get

The Input Document.

Definition at line 91 of file BadHtmlContext.cs.

◆ OutputDocument

HtmlDocument BadHtml.BadHtmlContext.OutputDocument
get

The Output Document.

Definition at line 96 of file BadHtmlContext.cs.


The documentation for this class was generated from the following file: