Compare commits

...

3 commits

Author SHA1 Message Date
ba44e0ed48 Merge branch 'v2' of https://git.jordanwages.com/wagesj45/cs-mic into v2 2026-06-24 02:35:11 -05:00
2a7077eedd Update .gitignore
Github isn't the primary repository anymore, so github specific config should be unnecessary.
2026-06-24 02:34:59 -05:00
3ec3858ff2 XMLDoc 2026-06-24 02:33:34 -05:00
8 changed files with 120 additions and 3 deletions

1
.gitignore vendored
View file

@ -409,3 +409,4 @@ FodyWeavers.xsd
/src/core/cocor/Scanner.cs.old
/src/core/cocor/Parser.cs
/src/core/cocor/Scanner.cs
/src/.github

View file

@ -6,15 +6,32 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary> An encapsulated function argument. </summary>
public class FunctionArgument
{
#region Properties
/// <summary> Gets or sets the name. </summary>
/// <value> The name. </value>
public string Name { get; set; }
/// <summary> Gets or sets the value. </summary>
/// <value> The value. </value>
public FunctionValue Value { get; set; }
#endregion
#region Constructors
/// <summary> Constructor. </summary>
/// <param name="name"> The name. </param>
/// <param name="fv"> The fv. </param>
public FunctionArgument(string name, FunctionValue fv)
{
this.Name = name;
this.Value = fv;
}
#endregion
}
}

View file

@ -7,28 +7,77 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary> An encapsulated function value. </summary>
public class FunctionValue
{
#region Properties
/// <summary> Gets or sets the value type of a function. </summary>
/// <value> The type. </value>
public FunctionValueType Type { get; set; }
/// <summary> Gets or sets the value. </summary>
/// <value> The value. </value>
public object? Value { get; set; }
#endregion
#region Constants
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents a <c>true</c> <see cref="bool"/>
/// whose value is <c>1</c>.
/// </summary>
public static readonly FunctionValue TRUE = new FunctionValue(FunctionValueType.Numeric, 1m);
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents a <c>false</c> <see cref="bool"/>
/// whose value is <c>0</c>.
/// </summary>
public static readonly FunctionValue FALSE = new FunctionValue(FunctionValueType.Numeric, 0m);
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents a undefined value.
/// </summary>
public static readonly FunctionValue NONE = new FunctionValue(FunctionValueType.None, null);
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents a numeric value. The
/// default value is <c>0</c>.
/// </summary>
public static readonly FunctionValue NUMBER = new FunctionValue(FunctionValueType.Numeric, 0m);
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents a string value. The default
/// value is <see cref="string.Empty"/>.
/// </summary>
public static readonly FunctionValue STRING = new FunctionValue(FunctionValueType.String, string.Empty);
/// <summary>
/// (Immutable) A defined <see cref="FunctionValue"/> that represents the number zero.
/// </summary>
public static readonly FunctionValue ZERO = new FunctionValue(FunctionValueType.Numeric, 0m);
#endregion
#region Constructors
/// <summary> Default constructor. </summary>
public FunctionValue()
{
this.Type = FunctionValueType.None;
this.Value = null;
}
/// <summary> Constructor. </summary>
/// <param name="type"> The type. </param>
/// <param name="value"> The value. </param>
public FunctionValue(FunctionValueType type, object? value)
{
this.Type = type;
this.Value = value;
}
#endregion
}
}

View file

@ -6,10 +6,14 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary> Values that represent function value types. </summary>
public enum FunctionValueType
{
/// <summary> An enum constant representing an undefined or unsupported function value type. </summary>
None,
/// <summary> An enum constant representing a numeric function value type. </summary>
Numeric,
/// <summary> An enum constant representing a string function value type. </summary>
String
}
}

View file

@ -6,18 +6,32 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary>
/// Interface for a coded function that can be created at compiletime and invoked at runtime.
/// </summary>
public interface ICodedFunction
{
#region Properties
/// <summary> Gets the name of the function. </summary>
/// <value> The name. </value>
string Name { get; }
/// <summary> Gets the expected arguments of the function. </summary>
/// <value> The expected arguments. </value>
IEnumerable<FunctionArgument> ExpectedArguments { get; }
/// <summary> Gets the return value of the function. </summary>
/// <value> The return value. </value>
FunctionValue ReturnValue { get; }
#endregion
#region Methods
/// <summary> Executes the function with the given arguments. </summary>
/// <param name="args"> A variable-length parameters list containing arguments. </param>
/// <returns> A FunctionValue representing the result of the function execution. </returns>
FunctionValue Execute(params FunctionArgument[] args);
#endregion

View file

@ -6,20 +6,26 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary> An encapsulated variable that names a runtime value. </summary>
public class Variable
{
#region Members
/// <summary> The type of the variable. </summary>
private VariableType type;
/// <summary> The name of the variable. </summary>
private string name;
/// <summary> The value assigned to the variable. </summary>
private object? value;
#endregion
#region Properties
/// <summary> Gets the variable type. </summary>
/// <value> The type. </value>
public VariableType Type
{
get
@ -28,6 +34,8 @@ namespace CSMic
}
}
/// <summary> Gets the variable name. </summary>
/// <value> The name. </value>
public string Name
{
get
@ -36,6 +44,8 @@ namespace CSMic
}
}
/// <summary> Gets the assigned value. </summary>
/// <value> The assigned value. </value>
public object? Value
{
get
@ -48,6 +58,7 @@ namespace CSMic
#region Constructor
/// <summary> Default constructor. </summary>
public Variable()
{
this.type = VariableType.None;
@ -55,6 +66,10 @@ namespace CSMic
this.value = null;
}
/// <summary> Constructor. </summary>
/// <param name="type"> The type of the variable. </param>
/// <param name="name"> The name of the variable. </param>
/// <param name="value"> The value assigned to the variable. </param>
public Variable(VariableType type, string name, object? value)
{
this.type = type;

View file

@ -6,11 +6,16 @@ using System.Threading.Tasks;
namespace CSMic
{
/// <summary> Values that represent variable types supported by the parser. </summary>
public enum VariableType
{
/// <summary> An enum constant representing an unknown or unsupported type. </summary>
None,
/// <summary> An enum constant representing a numeric type backed by a <see cref="decimal"/>. </summary>
Numeric,
/// <summary> An enum constant representing numeric array backed by a <see cref="Array"/> of <see cref="decimal"/>. </summary>
NumericArray,
/// <summary> An enum constant representing an expression type backed by a <see cref="string"/> and interpreted by the parser at runtime. </summary>
Expression,
}
}

View file

@ -2,10 +2,15 @@
namespace CSMic.StandardLibrary.Functions
{
/// <summary> A base class that handles base function handling. </summary>
public abstract class FunctionBase
{
/// <summary> Gets the expected arguments. </summary>
/// <value> The expected arguments. </value>
public virtual IEnumerable<FunctionArgument> ExpectedArguments { get; }
/// <summary> Gets the return value. </summary>
/// <value> The return value. </value>
public virtual FunctionValue ReturnValue
{
get
@ -15,6 +20,9 @@ namespace CSMic.StandardLibrary.Functions
}
}
/// <summary> Checks the provided arguments to ensure the function contract is honored. </summary>
/// <param name="args"> A variable-length parameters list containing arguments. </param>
/// <returns> True if it succeeds, false if it fails. </returns>
public bool ArgumentCheck(params FunctionArgument[] args)
{
// Top level sanity checks.
@ -49,6 +57,10 @@ namespace CSMic.StandardLibrary.Functions
return true;
}
/// <summary> Executes a standard library function. </summary>
/// <param name="args"> A variable-length parameters list containing arguments. </param>
/// <param name="action"> The functions action body. </param>
/// <returns> A <see cref="FunctionValue"/>. </returns>
public FunctionValue Execute(FunctionArgument[] args, Func<FunctionArgument[], FunctionValue> action)
{
if (!ArgumentCheck(args))