EP 0.1.1 转换
This commit is contained in:
@@ -8,9 +8,9 @@ namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public readonly FunctionSymbol FunctionInfo;
|
||||
|
||||
protected Function(string symbolName,string functionName, Type returnType, Type[] parameterTypes, Modification[] modifiers) : base(symbolName)
|
||||
protected Function(string symbolName,string functionName, Type returnType, Type[] parameterTypes) : base(symbolName)
|
||||
{
|
||||
FunctionInfo = new(functionName, returnType, parameterTypes, modifiers);
|
||||
FunctionInfo = new(functionName, returnType, parameterTypes);
|
||||
}
|
||||
public abstract Variable Invoke(SymbolizationContext context, Variable[] parameters);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace Convention.Symbolization.Internal
|
||||
public readonly MethodInfo methodInfo;
|
||||
|
||||
public DelegationalFunction(string symbolName, MethodInfo methodInfo)
|
||||
: base(symbolName, methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters().ToList().ConvertAll(x => x.ParameterType).ToArray(), Array.Empty<Modification>())
|
||||
: base(symbolName, methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters().ToList().ConvertAll(x => x.ParameterType).ToArray())
|
||||
{
|
||||
this.methodInfo = methodInfo!;
|
||||
}
|
||||
@@ -44,22 +44,43 @@ namespace Convention.Symbolization.Internal
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ScriptFunction : Function
|
||||
{
|
||||
public ScriptFunction(string symbolName,
|
||||
string functionName, Type returnType, Type[] parameterTypes)
|
||||
: base(symbolName, functionName, returnType, parameterTypes)
|
||||
{
|
||||
}
|
||||
|
||||
public override Function CloneVariable(string targetSymbolName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Equals(Function other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Variable Invoke(SymbolizationContext context, Variable[] parameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct FunctionSymbol
|
||||
{
|
||||
public readonly string FunctionName;
|
||||
public readonly Type ReturnType;
|
||||
public readonly Type[] ParameterTypes;
|
||||
public readonly Modification[] Modifiers;
|
||||
public readonly string FullName;
|
||||
|
||||
public FunctionSymbol(string symbolName, Type returnType, Type[] parameterTypes, Modification[] modifiers)
|
||||
public FunctionSymbol(string symbolName, Type returnType, Type[] parameterTypes)
|
||||
{
|
||||
this.FunctionName = symbolName;
|
||||
this.ReturnType = returnType;
|
||||
this.ParameterTypes = parameterTypes;
|
||||
this.Modifiers = modifiers;
|
||||
this.FullName = $"{returnType.FullName} {symbolName}({string.Join(',', parameterTypes.ToList().ConvertAll(x => x.FullName))}) {string.Join(' ', modifiers.ToList().ConvertAll(x => x.ToString()))}";
|
||||
this.FullName = $"{returnType.FullName} {symbolName}({string.Join(',', parameterTypes.ToList().ConvertAll(x => x.FullName))})";
|
||||
}
|
||||
|
||||
public bool Equals(FunctionSymbol other)
|
||||
|
@@ -1,34 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public abstract class Keyword : Variable
|
||||
public abstract class Keyword : CloneableVariable<Keyword>
|
||||
{
|
||||
protected Keyword(string keyword, Type realType) : base(new(keyword, realType))
|
||||
protected Keyword(string keyword) : base(keyword)
|
||||
{
|
||||
Keywords.Add(keyword, this);
|
||||
Keywords.TryAdd(keyword, this);
|
||||
}
|
||||
|
||||
public static readonly Dictionary<string, Keyword> Keywords = new();
|
||||
|
||||
public override bool Equals(Keyword other)
|
||||
{
|
||||
return this.GetType() == other.GetType();
|
||||
}
|
||||
|
||||
public abstract Keyword ControlContext(SymbolizationContext context, ScriptWordVariable next);
|
||||
}
|
||||
|
||||
public abstract class Keyword<T> : Keyword where T:Keyword<T>,new()
|
||||
public abstract class Keyword<T> : Keyword where T : Keyword<T>, new()
|
||||
{
|
||||
private static T MyInstance = new();
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return MyInstance;
|
||||
}
|
||||
}
|
||||
|
||||
protected Keyword(string keyword) : base(keyword, typeof(T))
|
||||
protected Keyword(string keyword) : base(keyword)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -50,6 +47,36 @@ namespace Convention.Symbolization.Keyword
|
||||
public Import() : base("import")
|
||||
{
|
||||
}
|
||||
|
||||
public override Internal.Keyword CloneVariable(string targetSymbolName)
|
||||
{
|
||||
return new Import();
|
||||
}
|
||||
|
||||
private ToolFile ImportFile = new("./");
|
||||
private string buffer = "";
|
||||
|
||||
public override Internal.Keyword ControlContext(SymbolizationContext context, Internal.ScriptWordVariable next)
|
||||
{
|
||||
if (next.word == ";")
|
||||
{
|
||||
var importContext = new SymbolizationContext(context);
|
||||
importContext.Compile(ImportFile);
|
||||
return null;
|
||||
}
|
||||
else if(next.word==".")
|
||||
{
|
||||
ImportFile = ImportFile | buffer;
|
||||
buffer = "";
|
||||
if (ImportFile.Exists() == false)
|
||||
throw new FileNotFoundException($"File path not found: {ImportFile}", ImportFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer += next.word;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +90,7 @@ namespace Convention.Symbolization.Keyword
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <b><see langword="def"/> FunctionName(parameter-list) -> return-type { ... return return-type-instance; }</b>
|
||||
/// <b><see langword="def"/> FunctionName(parameter-list) return-type { ... return return-type-instance; }</b>
|
||||
/// </summary>
|
||||
public sealed class FunctionDef : Internal.Keyword<FunctionDef>
|
||||
{
|
||||
|
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public abstract class Modification : Variable
|
||||
{
|
||||
protected Modification(string modificationalName, Type type) : base(new(modificationalName, type))
|
||||
{
|
||||
}
|
||||
}
|
||||
public abstract class Modification<T> : Modification where T : Modification<T>
|
||||
{
|
||||
protected Modification(string modificationalName) : base(modificationalName, typeof(T))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user