Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CSharp/CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<LangVersion>10.0</LangVersion>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand All @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Antlr4.Runtime.Standard" Version="4.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2"/>
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
Expand Down
16 changes: 9 additions & 7 deletions CSharp/Interpreter/ArcscriptExceptions.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
namespace Arcweave.Interpreter;

public class RuntimeException : Exception
namespace Arcweave.Interpreter
{
public class RuntimeException : System.Exception
{
public RuntimeException(string message) : base(message)
{
}

public RuntimeException(string message, Exception innerException) : base(message, innerException)
public RuntimeException(string message, System.Exception innerException) : base(message, innerException)
{
}
}

public class ParseException : Exception
public class ParseException : System.Exception
{
public ParseException(string message) : base(message)
{
}

public ParseException(string message, Exception innerException) : base(message, innerException)
public ParseException(string message, System.Exception innerException) : base(message, innerException)
{
}
}
}
}

5 changes: 2 additions & 3 deletions CSharp/Interpreter/ArcscriptExpression.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

#nullable enable
using System;
using System.Collections;

namespace Arcweave.Interpreter
{
public class Expression : ArcscriptExpressionBase, IComparable
{
public object Value { get; set; }
public Expression() { Value = null; }
public object Value { get; private set; }
public Expression(object value) { Value = value; }
public Expression(object value, Type type) { Value = Convert.ChangeType(value, type); }
public Expression(Expression expression) { Value = expression.Value; }
Expand Down
8 changes: 5 additions & 3 deletions CSharp/Interpreter/ArcscriptExpressionBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Globalization;

namespace Arcweave.Interpreter;

namespace Arcweave.Interpreter
{
public class ArcscriptExpressionBase
{
public NumberFormatInfo NumberFormat { get; private set; }
Expand All @@ -13,4 +13,6 @@ public ArcscriptExpressionBase()
NumberGroupSeparator = ","
};
}
}
}
}

2 changes: 1 addition & 1 deletion CSharp/Interpreter/ArcscriptParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public bool assertMention(IList<ArcscriptParser.Mention_attributesContext> attrC
}
attrs.Add(attrName, attrValue);
}
string[] classList = attrs["class"].Split(" ");
string[] classList = attrs["class"].Split(' ');
if ( !classList.Contains("mention") ) {
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions CSharp/Interpreter/ArcscriptState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Arcweave.Interpreter.INodes;
using Arcweave.Project;

namespace Arcweave.Interpreter
{
Expand Down Expand Up @@ -28,7 +30,7 @@ public ArcscriptState(string elementId, IProject project, System.Action<string>?
}
}

public IVariable GetVariable(string name) {
public IVariable? GetVariable(string name) {
try
{
return this.project.Variables.First(variable => variable.Name == name);
Expand Down Expand Up @@ -56,9 +58,12 @@ public void SetVarValues(string[] names, string[] values) {

public void ResetVisits()
{
foreach (var projectElement in project.Elements)
foreach (var board in project.Boards)
{
projectElement.Value.Visits = 0;
foreach (var element in board.Nodes.OfType<Element>())
{
element.Visits = 0;
}
}
_emit("resetVisits");
}
Expand Down
4 changes: 2 additions & 2 deletions CSharp/Interpreter/ArcscriptTranspiler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#nullable enable
using Antlr4.Runtime;
using System.Collections.Generic;
using Arcweave.Interpreter.INodes;

namespace Arcweave.Interpreter
{

public class AwInterpreter
{
private IProject Project { get; set; }
Expand Down Expand Up @@ -64,7 +64,7 @@ public TranspilerOutput RunScript(string code)
{
tree = this.GetParseTree(code);
}
catch (Exception e)
catch (System.Exception e)
{
throw new ParseException(e.Message, e);
}
Expand Down
25 changes: 15 additions & 10 deletions CSharp/Interpreter/ArcscriptVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
using Antlr4.Runtime.Misc;
using System.Globalization;
using Antlr4.Runtime.Tree;
Expand Down Expand Up @@ -38,7 +41,7 @@ public override object VisitInput([NotNull] ArcscriptParser.InputContext context

public override object VisitScript_section([NotNull] ArcscriptParser.Script_sectionContext context) {
if ( context == null ) {
return null;
return null!;
}

var blockquoteContexts = context.blockquote();
Expand Down Expand Up @@ -121,7 +124,7 @@ public override object VisitConditional_section([NotNull] ArcscriptParser.Condit
return elseSection.Script;
}
this.state.Outputs.AddScriptOutput(null);
return null;
return null!;
}

public override object VisitIf_section([NotNull] ArcscriptParser.If_sectionContext context) {
Expand Down Expand Up @@ -158,12 +161,11 @@ public override object VisitElse_if_clause([NotNull] ArcscriptParser.Else_if_cla

public override object VisitStatement_assignment([NotNull] ArcscriptParser.Statement_assignmentContext context) {
string variableName = context.VARIABLE().GetText();
IVariable variable = this.state.GetVariable(variableName);

Expression compound_condition_or = (Expression)this.VisitCompound_condition_or(context.compound_condition_or());
if ( context.ASSIGN() != null ) {
this.state.SetVarValue(variableName, compound_condition_or.Value);
return null;
return null!;
}

Expression variableValue = new Expression(this.state.GetVarValue(variableName));
Expand All @@ -181,7 +183,7 @@ public override object VisitStatement_assignment([NotNull] ArcscriptParser.State
}

this.state.SetVarValue(variableName, variableValue.Value);
return null;
return null!;
}

public override object VisitCompound_condition_or([NotNull] ArcscriptParser.Compound_condition_orContext context) {
Expand Down Expand Up @@ -356,7 +358,7 @@ public override object VisitUnary_numeric_expression([NotNull] ArcscriptParser.U
public override object VisitVoid_function_call([NotNull] ArcscriptParser.Void_function_callContext context)
{
string fname = "";
IList<object> argument_list_result = null;
IList<object>? argument_list_result = null;
if (context.VFNAME() != null)
{
fname = context.VFNAME().GetText();
Expand All @@ -380,7 +382,7 @@ public override object VisitVoid_function_call([NotNull] ArcscriptParser.Void_fu
}

public override object VisitFunction_call([NotNull] ArcscriptParser.Function_callContext context) {
IList<object> argument_list_result = null;
IList<object>? argument_list_result = null;
if ( context.argument_list() != null ) {
argument_list_result = (IList<object>)this.VisitArgument_list(context.argument_list());
}
Expand All @@ -398,8 +400,11 @@ public override object VisitVariable_list([NotNull] ArcscriptParser.Variable_lis
List<object> variables = new List<object>();
foreach (ITerminalNode variable in context.VARIABLE())
{
IVariable varObject = this.state.GetVariable(variable.GetText());
variables.Add(varObject);
var varObject = this.state.GetVariable(variable.GetText());
if (varObject != null)
{
variables.Add(varObject);
}
}
return variables;
}
Expand Down Expand Up @@ -445,7 +450,7 @@ public override object VisitMention_attributes([NotNull] ArcscriptParser.Mention
object value = true;
if ( ctxvalue != null ) {
string strvalue = ctxvalue.GetText();
if ( ( strvalue.StartsWith('"') && strvalue.EndsWith('"') ) ||
if ( ( strvalue.StartsWith("\"") && strvalue.EndsWith("\"") ) ||
( strvalue.StartsWith("'") && strvalue.EndsWith("'") ) ) {
strvalue = strvalue.Substring(1, strvalue.Length - 2);
}
Expand Down
10 changes: 7 additions & 3 deletions CSharp/Interpreter/ErrorListener.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.IO;
using Antlr4.Runtime;

namespace Arcweave.Interpreter;

namespace Arcweave.Interpreter
{
public class ErrorListener<S>: ConsoleErrorListener<S>
{
public bool HasErrors = false;
Expand All @@ -14,4 +16,6 @@ public override void SyntaxError(TextWriter output, IRecognizer recognizer, S of
Errors.Add($"line {line}:{charPositionInLine} {msg}");
base.SyntaxError(output, recognizer, offendingSymbol, line, charPositionInLine, msg, e);
}
}
}
}

3 changes: 2 additions & 1 deletion CSharp/Interpreter/INodes/IProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public interface IProject
{
#if GODOT
public Array<Arcweave.Project.Variable> Variables { get; }
public Array<Arcweave.Project.Board> Boards { get; }
#else
public List<Arcweave.Project.Variable> Variables { get; }
public List<Arcweave.Project.Board> Boards { get; }
#endif
public Dictionary<string, Element> Elements { get; }
public Arcweave.Project.Element ElementWithId(string id);

public Arcweave.Project.Variable GetVariable(string name);
Expand Down
9 changes: 6 additions & 3 deletions CSharp/Project/Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Arcweave.Interpreter.INodes;

namespace Arcweave.Project;

namespace Arcweave.Project
{

public partial class Attribute
{
public string Name { get; }
public IAttribute.DataType Type { get; }
public IAttribute.ContainerType containerType { get; }
public string containerId { get; }
}
}
}

20 changes: 20 additions & 0 deletions CSharp/Project/Board.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using Arcweave.Interpreter.INodes;

namespace Arcweave.Project
{
public partial class Board
{
public string Id { get; set; }
public List<INode> Nodes { get; set; }

public Board(string id, List<INode> nodes)
{
Id = id;
Nodes = nodes;
}

public T NodeWithID<T>(string id) where T : INode => Nodes.OfType<T>().FirstOrDefault(x => x.Id == id);
}
}
9 changes: 7 additions & 2 deletions CSharp/Project/Component.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace Arcweave.Project;
using System;
using System.Collections.Generic;

namespace Arcweave.Project
{
public partial class Component
{
public List<Attribute> Attributes { get; }
public void AddAttribute(Attribute attribute)
{
throw new NotImplementedException();
}
}
}
}

11 changes: 7 additions & 4 deletions CSharp/Project/Connection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Arcweave.Interpreter.INodes;

namespace Arcweave.Project;
using System;
using Arcweave.Interpreter.INodes;

namespace Arcweave.Project
{
public partial class Connection
{
public string Id { get; }
Expand All @@ -24,4 +25,6 @@ public Path ResolvePath(Path p)
{
throw new NotImplementedException();
}
}
}
}

14 changes: 12 additions & 2 deletions CSharp/Project/Element.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
namespace Arcweave.Project;
using System;
using System.Collections.Generic;

namespace Arcweave.Project
{
public partial class Element
{
public string Id { get; }
public Project Project { get; }

public Element(string id)
{
Id = id;
}

public Path ResolvePath(Path path)
{
Expand All @@ -29,4 +37,6 @@ public Options GetOptions()
{
throw new NotImplementedException();
}
}
}
}

Loading
Loading