mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Saving work * Move shit to engine * lord * merg * awa * bql is kill * forgot the fucking bike rack * bql is kill for real * pjb will kill me * aughfhbdj * yo ho here we go on my way to the MINES * a * adgddf * gdsgvfvxshngfgh * b * hfsjhghj * hbfdjjh * tf you mean i have to document it * follow C# standards * Assorted cleanup and documentation pass, minor bugfix in ValueRefParser. * Start porting old commands, remove that pesky prefix in favor of integrating with the shell. * Fix valueref up a bit, improve autocomplete for it. * e * Toolshed type system adventure. * a log * a * a e i o u * awa * fix tests * Arithmetic commands. * a * parse improvements --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
107 lines
2.3 KiB
C#
107 lines
2.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Toolshed.Errors;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.Toolshed.Syntax;
|
|
|
|
public sealed class ValueRef<T> : ValueRef<T, T>
|
|
{
|
|
public ValueRef(ValueRef<T, T> inner)
|
|
{
|
|
InnerBlock = inner.InnerBlock;
|
|
VarName = inner.VarName;
|
|
HasValue = inner.HasValue;
|
|
Value = inner.Value;
|
|
Expression = inner.Expression;
|
|
RefSpan = inner.RefSpan;
|
|
}
|
|
public ValueRef(string varName) : base(varName)
|
|
{
|
|
}
|
|
|
|
public ValueRef(Block<T> innerBlock) : base(innerBlock)
|
|
{
|
|
}
|
|
|
|
public ValueRef(T value) : base(value)
|
|
{
|
|
}
|
|
}
|
|
|
|
[Virtual]
|
|
public class ValueRef<T, TAuto>
|
|
{
|
|
internal Block<T>? InnerBlock;
|
|
internal string? VarName;
|
|
internal bool HasValue = false;
|
|
internal T? Value;
|
|
internal string? Expression;
|
|
internal Vector2i? RefSpan;
|
|
|
|
protected ValueRef()
|
|
{
|
|
}
|
|
|
|
public ValueRef(string varName)
|
|
{
|
|
VarName = varName;
|
|
}
|
|
|
|
public ValueRef(Block<T> innerBlock)
|
|
{
|
|
InnerBlock = innerBlock;
|
|
}
|
|
|
|
public ValueRef(T value)
|
|
{
|
|
Value = value;
|
|
HasValue = true;
|
|
}
|
|
|
|
public bool LikelyConst => VarName is not null || HasValue;
|
|
|
|
|
|
public T? Evaluate(IInvocationContext ctx)
|
|
{
|
|
if (Value is not null && HasValue)
|
|
{
|
|
return Value;
|
|
}
|
|
else if (VarName is not null)
|
|
{
|
|
return (T?)ctx.ReadVar(VarName);
|
|
}
|
|
else if (InnerBlock is not null)
|
|
{
|
|
return InnerBlock.Invoke(null, ctx);
|
|
}
|
|
else
|
|
{
|
|
throw new UnreachableException();
|
|
}
|
|
}
|
|
|
|
public void Set(IInvocationContext ctx, T? value)
|
|
{
|
|
if (VarName is null)
|
|
throw new NotImplementedException();
|
|
|
|
ctx.WriteVar(VarName!, value);
|
|
}
|
|
}
|
|
|
|
public record struct BadVarTypeError(Type Got, Type Expected, string VarName) : IConError
|
|
{
|
|
public FormattedMessage DescribeInner()
|
|
{
|
|
return FormattedMessage.FromMarkup(
|
|
$"Got unexpected type {Got.PrettyName()} in {VarName}, expected {Expected.PrettyName()}");
|
|
}
|
|
|
|
public string? Expression { get; set; }
|
|
public Vector2i? IssueSpan { get; set; }
|
|
public StackTrace? Trace { get; set; }
|
|
}
|