Skip to content

Commit

Permalink
Added special handling for statements instead of just being arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Dec 17, 2024
1 parent 68d032c commit 0980766
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ For other OSes you can clone the [***branch***](https://github.com/Uralstech/ezr

The offline documentation is included as an optional component in the installers. You can also download them from here:

[![ezr² RE v0.11.3 documentation](https://img.shields.io/badge/ezr%C2%B2_RE_v0.11.3_%28documentation%29-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/docsrc/QuickStartDocumentation.pdf)
[![ezr² RE v0.11.3 API reference manual](https://img.shields.io/badge/ezr%C2%B2_RE_v0.11.3_%28API_reference_manual%29-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/api/APIReferenceManual.pdf)
This is documentation for the latest, bleeding-edge version of ezr² RE, so some things may not match up with the latest release:

[![ezr² RE documentation](https://img.shields.io/badge/ezr%C2%B2_RE_documentation-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/docsrc/QuickStartDocumentation.pdf)
[![ezr² RE API reference manual](https://img.shields.io/badge/ezr%C2%B2_RE_API_reference_manual-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/api/APIReferenceManual.pdf)

## Contributing

Expand Down
22 changes: 22 additions & 0 deletions src/Runtime/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ internal void VisitNode(Node astNode, Context executionContext, Context? calling
case ValueNode node:
VisitValueNode(node, executionContext);
break;
case StatementsNode node:
VisitStatementsNode(node, executionContext, callingContext, accessibilityModifiers);
break;
case ArrayLikeNode node when node.CreateList:
VisitArrayLikeNodeList(node, executionContext, callingContext, accessibilityModifiers);
break;
Expand Down Expand Up @@ -202,6 +205,25 @@ private void VisitValueNode(ValueNode node, Context executionContext)
}
}

/// <summary>
/// Interprets multiple statements.
/// </summary>
/// <param name="node">The <see cref="StatementsNode"/> to execute.</param>
/// <param name="executionContext">The <see cref="Context"/> under which the statements will be executed.</param>
/// <param name="callingContext">The <see cref="Context"/> calling on the execution of the statements.</param>
/// <param name="accessibilityModifiers">The accessibility modifiers for objects that will be assigned from executing the statements.</param>
private void VisitStatementsNode(StatementsNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
{
foreach (Node statement in node.Statements)
{
VisitNode(statement, executionContext, callingContext, accessibilityModifiers);
if (RuntimeResult.ShouldReturn)
return;
}

RuntimeResult.Success(node.Statements.Count > 0 ? RuntimeResult.Reference : ReferencePool.Get(EzrConstants.Nothing, AccessMod.PrivateConstant));
}

#region VisitArrayLikeNode

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions src/Runtime/Nodes/CollectionNodes/StatementsNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace EzrSquared.Runtime.Nodes;

/// <summary>
/// The <see cref="Node"/> structure for holding multiple statements.
/// </summary>
/// <param name="statements">The statements.</param>
/// <param name="startPosition">The starting <see cref="Position"/> of the <see cref="StatementsNode"/>.</param>
/// <param name="endPosition">The ending <see cref="Position"/> of the <see cref="StatementsNode"/>.</param>
public class StatementsNode(List<Node> statements, Position startPosition, Position endPosition) : Node(startPosition, endPosition)
{
/// <summary>
/// The statements being held by the node.
/// </summary>
public List<Node> Statements = statements;

/// <inheritdoc/>
public override string ToString()
{
string[] elements = new string[Statements.Count];
for (int i = 0; i < Statements.Count; i++)
elements[i] = Statements[i].ToString();

return $"{nameof(StatementsNode)}([{string.Join(", ", elements)}])";
}
}
2 changes: 1 addition & 1 deletion src/Syntax/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ or TokenType.KeywordElse
statements.Add(_result.Node);
}

_result.Success(new ArrayLikeNode(statements, false, startPosition, statements[^1].EndPosition));
_result.Success(new StatementsNode(statements, startPosition, statements[^1].EndPosition));
}

/// <summary>
Expand Down

0 comments on commit 0980766

Please sign in to comment.