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.

74 {
75 InputNode = inputNode;
76 OutputNode = outputNode;
77 ExecutionContext = executionContext;
78 FilePath = filePath;
79 Source = source;
80 Options = options;
81 FileSystem = fileSystem;
82 }
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 130 of file BadHtmlContext.cs.

131 {
132 return new BadSourcePosition(FilePath, Source, attribute.ValueStartIndex, attribute.Value.Length);
133 }
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 109 of file BadHtmlContext.cs.

113 {
114 return new BadHtmlContext(
115 inputNode,
116 outputNode,
117 executionContext ?? ExecutionContext,
118 FilePath,
119 Source,
120 Options,
122 );
123 }
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 139 of file BadHtmlContext.cs.

140 {
141 return new BadSourcePosition(FilePath, Source, InputNode.InnerStartIndex, InputNode.InnerLength);
142 }

◆ CreateOuterPosition()

BadSourcePosition BadHtml.BadHtmlContext.CreateOuterPosition ( )

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

Returns
Source Position

Definition at line 148 of file BadHtmlContext.cs.

149 {
150 return new BadSourcePosition(FilePath, Source, InputNode.InnerStartIndex, InputNode.InnerLength);
151 }

◆ 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 273 of file BadHtmlContext.cs.

274 {
275 try
276 {
277 BadObject result = ExecutionContext.ExecuteScript(expression);
278
279 // if (ExecutionContext.Scope.IsError)
280 // {
281 // throw new BadRuntimeErrorException(ExecutionContext.Scope.Error);
282 // }
283
284 return result.Dereference();
285 }
286 catch (BadRuntimeException e)
287 {
288 throw new BadRuntimeException(e.Message, position);
289 }
290 }
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 251 of file BadHtmlContext.cs.

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

◆ 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 211 of file BadHtmlContext.cs.

212 {
213 try
214 {
215 BadExpression[] expressions = BadSourceParser.Parse(FilePath, code).ToArray();
216
217 foreach (BadExpression expression in VisitAll(expressions))
218 {
220 FilePath,
221 Source,
222 pos.Index + expression.Position.Index,
223 expression.Position.Length
224 );
225 expression.SetPosition(newPosition);
226 }
227
228 return expressions;
229 }
231 {
232 if (e.Position == null)
233 {
235 }
236
237 throw new BadSourceReaderException(
240 );
241 }
242 }
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 298 of file BadHtmlContext.cs.

299 {
300 BadExpression[] expressions = Parse(code, pos);
301
302 return Execute(expressions, pos);
303 }
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 311 of file BadHtmlContext.cs.

312 {
313 BadExpression expression = ParseSingle(code, pos);
314
315 return Execute(expression, pos);
316 }
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 170 of file BadHtmlContext.cs.

171 {
172 try
173 {
175 BadExpression expression = parser.ParseExpression();
176
177 foreach (BadExpression expr in expression.GetDescendantsAndSelf())
178 {
180 FilePath,
181 Source,
182 pos.Index + expr.Position.Index,
183 expr.Position.Length
184 );
185 expr.SetPosition(newPosition);
186 }
187
188 return expression;
189 }
191 {
192 if (e.Position == null)
193 {
195 }
196
197 throw new BadSourceReaderException(
200 );
201 }
202 }
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 158 of file BadHtmlContext.cs.

159 {
160 return expressions.SelectMany(expression => expression.GetDescendantsAndSelf());
161 }

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 87 of file BadHtmlContext.cs.

87{ get; }

◆ InputDocument

HtmlDocument BadHtml.BadHtmlContext.InputDocument
get

The Input Document.

Definition at line 92 of file BadHtmlContext.cs.

◆ OutputDocument

HtmlDocument BadHtml.BadHtmlContext.OutputDocument
get

The Output Document.

Definition at line 97 of file BadHtmlContext.cs.


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