EP Symbolization 重构line-word-index
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
{
|
{
|
||||||
public readonly FunctionSymbol FunctionInfo;
|
public readonly FunctionSymbol FunctionInfo;
|
||||||
|
|
||||||
protected Function(string symbolName,string functionName, Type returnType, Type[] parameterTypes) : base(symbolName)
|
protected Function(string symbolName,int lineIndex,int wordIndex,string functionName, Type returnType, Type[] parameterTypes) : base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
FunctionInfo = new(functionName, returnType, parameterTypes);
|
FunctionInfo = new(functionName, returnType, parameterTypes);
|
||||||
}
|
}
|
||||||
@@ -19,15 +19,16 @@ namespace Convention.Symbolization.Internal
|
|||||||
{
|
{
|
||||||
public readonly MethodInfo methodInfo;
|
public readonly MethodInfo methodInfo;
|
||||||
|
|
||||||
public DelegationalFunction(string symbolName, MethodInfo methodInfo)
|
public DelegationalFunction(string symbolName, int lineIndex, int wordIndex, MethodInfo methodInfo)
|
||||||
: base(symbolName, methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters().ToList().ConvertAll(x => x.ParameterType).ToArray())
|
: base(symbolName, lineIndex, wordIndex,
|
||||||
|
methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters().ToList().ConvertAll(x => x.ParameterType).ToArray())
|
||||||
{
|
{
|
||||||
this.methodInfo = methodInfo!;
|
this.methodInfo = methodInfo!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override DelegationalFunction CloneVariable(string targetSymbolName)
|
public override DelegationalFunction CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
return new DelegationalFunction(targetSymbolName, methodInfo);
|
return new DelegationalFunction(targetSymbolName, lineIndex, wordIndex, methodInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(Function other)
|
public override bool Equals(Function other)
|
||||||
@@ -46,13 +47,13 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public sealed class ScriptFunction : Function
|
public sealed class ScriptFunction : Function
|
||||||
{
|
{
|
||||||
public ScriptFunction(string symbolName,
|
public ScriptFunction(string symbolName, int lineIndex, int wordIndex,
|
||||||
string functionName, Type returnType, Type[] parameterTypes)
|
string functionName, Type returnType, Type[] parameterTypes)
|
||||||
: base(symbolName, functionName, returnType, parameterTypes)
|
: base(symbolName, lineIndex, wordIndex, functionName, returnType, parameterTypes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Function CloneVariable(string targetSymbolName)
|
public override Function CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
{
|
{
|
||||||
public abstract class Keyword : CloneableVariable<Keyword>
|
public abstract class Keyword : CloneableVariable<Keyword>
|
||||||
{
|
{
|
||||||
protected Keyword(string keyword) : base(keyword) { }
|
protected Keyword(string keyword, int lineIndex, int wordIndex) : base(keyword, lineIndex, wordIndex) { }
|
||||||
|
|
||||||
public static readonly Dictionary<string, Keyword> Keywords = new()
|
public static readonly Dictionary<string, Keyword> Keywords = new()
|
||||||
{
|
{
|
||||||
@@ -38,53 +38,48 @@ namespace Convention.Symbolization.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class Keyword<T> : Keyword where T : Keyword<T>, new()
|
public abstract class Keyword<T> : Keyword where T : Keyword<T>
|
||||||
{
|
{
|
||||||
protected Keyword(string keyword) : base(keyword) { }
|
protected Keyword(string keyword,int lineIndex,int wordIndex) : base(keyword, lineIndex, wordIndex) { }
|
||||||
|
|
||||||
public override bool Equals(Variable other)
|
public override bool Equals(Variable other)
|
||||||
{
|
{
|
||||||
return other is T;
|
return other is T;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Keyword CloneVariable(string targetSymbolName)
|
|
||||||
{
|
|
||||||
return new T();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Convention.Symbolization.Keyword
|
namespace Convention.Symbolization.Keyword
|
||||||
{
|
{
|
||||||
public abstract class SingleKeyword<T> : Internal.Keyword<T> where T : SingleKeyword<T>, new()
|
public abstract class SingleKeyword<T> : Internal.Keyword<T> where T : SingleKeyword<T>
|
||||||
{
|
{
|
||||||
protected SingleKeyword(string keyword) : base(keyword)
|
protected SingleKeyword(string keyword,int lineIndex,int wordIndex) : base(keyword, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
protected override bool ControlScope(SymbolizationContext context, Internal.Variable next)
|
protected override bool ControlScope(SymbolizationContext context, Internal.Variable next)
|
||||||
{
|
{
|
||||||
if (next is not Internal.ScriptWordVariable swv ||swv.word!=";")
|
if (next is not Internal.ScriptWordVariable swv ||swv.Word!=";")
|
||||||
throw new InvalidGrammarException($"Expected ';' but got {next}");
|
throw new InvalidGrammarException($"Expected ';' but got {next}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class SentenceKeyword<T> : Internal.Keyword<T> where T : SentenceKeyword<T>, new()
|
public abstract class SentenceKeyword<T> : Internal.Keyword<T> where T : SentenceKeyword<T>
|
||||||
{
|
{
|
||||||
protected SentenceKeyword(string keyword) : base(keyword)
|
protected SentenceKeyword(string keyword,int lineIndex,int wordIndex) : base(keyword, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
protected override bool ControlScope(SymbolizationContext context, Internal.Variable next)
|
protected override bool ControlScope(SymbolizationContext context, Internal.Variable next)
|
||||||
{
|
{
|
||||||
if (next is not Internal.ScriptWordVariable swv)
|
if (next is not Internal.ScriptWordVariable swv)
|
||||||
throw new InvalidGrammarException($"Not expected a key word: {next}");
|
throw new InvalidGrammarException($"Not expected a key Word: {next}");
|
||||||
return swv.word != ";";
|
return swv.Word != ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class NamespaceKeyword<T> : Internal.Keyword<T> where T : NamespaceKeyword<T>, new()
|
public abstract class NamespaceKeyword<T> : Internal.Keyword<T> where T : NamespaceKeyword<T>
|
||||||
{
|
{
|
||||||
protected NamespaceKeyword(string keyword) : base(keyword)
|
protected NamespaceKeyword(string keyword,int lineIndex,int wordIndex) : base(keyword, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
private enum Pause
|
private enum Pause
|
||||||
@@ -101,7 +96,7 @@ namespace Convention.Symbolization.Keyword
|
|||||||
{
|
{
|
||||||
if (next is Internal.ScriptWordVariable swv)
|
if (next is Internal.ScriptWordVariable swv)
|
||||||
{
|
{
|
||||||
if (swv.word == "{")
|
if (swv.Word == "{")
|
||||||
{
|
{
|
||||||
pause = Pause.Body;
|
pause = Pause.Body;
|
||||||
layer++;
|
layer++;
|
||||||
@@ -110,16 +105,16 @@ namespace Convention.Symbolization.Keyword
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidGrammarException($"Expected a script word variable for namespace name, but got {next}");
|
throw new InvalidGrammarException($"Expected a script Word variable for namespace name, but got {next}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (next is Internal.ScriptWordVariable swv)
|
if (next is Internal.ScriptWordVariable swv)
|
||||||
{
|
{
|
||||||
if (swv.word == "{")
|
if (swv.Word == "{")
|
||||||
layer++;
|
layer++;
|
||||||
else if (swv.word == "}")
|
else if (swv.Word == "}")
|
||||||
layer--;
|
layer--;
|
||||||
if (layer == 0)
|
if (layer == 0)
|
||||||
{
|
{
|
||||||
@@ -131,9 +126,9 @@ namespace Convention.Symbolization.Keyword
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class VerbObjectScopeKeyword<T> : Internal.Keyword<T> where T : VerbObjectScopeKeyword<T>, new()
|
public abstract class VerbObjectScopeKeyword<T> : Internal.Keyword<T> where T : VerbObjectScopeKeyword<T>
|
||||||
{
|
{
|
||||||
protected VerbObjectScopeKeyword(string keyword) : base(keyword)
|
protected VerbObjectScopeKeyword(string keyword,int lineIndex,int wordIndex) : base(keyword, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,15 +145,15 @@ namespace Convention.Symbolization.Keyword
|
|||||||
if (pause == Pause.BeforeExpression)
|
if (pause == Pause.BeforeExpression)
|
||||||
{
|
{
|
||||||
if (next is not Internal.ScriptWordVariable swv)
|
if (next is not Internal.ScriptWordVariable swv)
|
||||||
throw new InvalidGrammarException($"Not expected a key word: {next}");
|
throw new InvalidGrammarException($"Not expected a key Word: {next}");
|
||||||
if (swv.word == "(")
|
if (swv.Word == "(")
|
||||||
pause = Pause.Expression;
|
pause = Pause.Expression;
|
||||||
else
|
else
|
||||||
throw new InvalidGrammarException($"Expected '(' symbol for expression start, but got {next}");
|
throw new InvalidGrammarException($"Expected '(' symbol for expression start, but got {next}");
|
||||||
}
|
}
|
||||||
else if (pause == Pause.Expression)
|
else if (pause == Pause.Expression)
|
||||||
{
|
{
|
||||||
if (next is Internal.ScriptWordVariable swv && swv.word == ")")
|
if (next is Internal.ScriptWordVariable swv && swv.Word == ")")
|
||||||
{
|
{
|
||||||
pause = Pause.BeforeBody;
|
pause = Pause.BeforeBody;
|
||||||
}
|
}
|
||||||
@@ -167,7 +162,7 @@ namespace Convention.Symbolization.Keyword
|
|||||||
{
|
{
|
||||||
if (next is not Internal.ScriptWordVariable swv)
|
if (next is not Internal.ScriptWordVariable swv)
|
||||||
throw new InvalidGrammarException($"Not expected keyword for body start, but got {next}");
|
throw new InvalidGrammarException($"Not expected keyword for body start, but got {next}");
|
||||||
if (swv.word == "{")
|
if (swv.Word == "{")
|
||||||
{
|
{
|
||||||
pause = Pause.Body;
|
pause = Pause.Body;
|
||||||
layer++;
|
layer++;
|
||||||
@@ -179,9 +174,9 @@ namespace Convention.Symbolization.Keyword
|
|||||||
{
|
{
|
||||||
if (next is Internal.ScriptWordVariable swv)
|
if (next is Internal.ScriptWordVariable swv)
|
||||||
{
|
{
|
||||||
if (swv.word == "{")
|
if (swv.Word == "{")
|
||||||
layer++;
|
layer++;
|
||||||
else if (swv.word == "}")
|
else if (swv.Word == "}")
|
||||||
layer--;
|
layer--;
|
||||||
if (layer == 0)
|
if (layer == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -189,7 +184,7 @@ namespace Convention.Symbolization.Keyword
|
|||||||
}
|
}
|
||||||
else if (pause == Pause.SingleSentence)
|
else if (pause == Pause.SingleSentence)
|
||||||
{
|
{
|
||||||
if (next is Internal.ScriptWordVariable swv && swv.word == ";")
|
if (next is Internal.ScriptWordVariable swv && swv.Word == ";")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -203,9 +198,14 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Import : SentenceKeyword<Import>
|
public sealed class Import : SentenceKeyword<Import>
|
||||||
{
|
{
|
||||||
public Import() : base("import")
|
public Import(int lineIndex,int wordIndex) : base("import",lineIndex,wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Import(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -213,9 +213,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Namespace : NamespaceKeyword<Namespace>
|
public sealed class Namespace : NamespaceKeyword<Namespace>
|
||||||
{
|
{
|
||||||
public Namespace() : base("namespace")
|
public Namespace(int lineIndex,int wordIndex) : base("namespace", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Namespace(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -223,9 +227,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class FunctionDef : NamespaceKeyword<FunctionDef>
|
public sealed class FunctionDef : NamespaceKeyword<FunctionDef>
|
||||||
{
|
{
|
||||||
public FunctionDef() : base("def")
|
public FunctionDef(int lineIndex,int wordIndex) : base("def", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new FunctionDef(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -233,9 +241,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Return : SentenceKeyword<Return>
|
public sealed class Return : SentenceKeyword<Return>
|
||||||
{
|
{
|
||||||
public Return() : base("return")
|
public Return(int lineIndex,int wordIndex) : base("return", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Return(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -243,9 +255,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class If : VerbObjectScopeKeyword<If>
|
public sealed class If : VerbObjectScopeKeyword<If>
|
||||||
{
|
{
|
||||||
public If() : base("if")
|
public If(int lineIndex,int wordIndex) : base("if", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new If(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -254,9 +270,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Elif : VerbObjectScopeKeyword<Elif>
|
public sealed class Elif : VerbObjectScopeKeyword<Elif>
|
||||||
{
|
{
|
||||||
public Elif() : base("elif")
|
public Elif(int lineIndex,int wordIndex) : base("elif", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Elif(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -265,9 +285,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Else : NamespaceKeyword<Else>
|
public sealed class Else : NamespaceKeyword<Else>
|
||||||
{
|
{
|
||||||
public Else() : base("else")
|
public Else(int lineIndex,int wordIndex) : base("else", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Else(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -275,9 +299,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class While : VerbObjectScopeKeyword<While>
|
public sealed class While : VerbObjectScopeKeyword<While>
|
||||||
{
|
{
|
||||||
public While() : base("while")
|
public While(int lineIndex,int wordIndex) : base("while", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new While(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -285,9 +313,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Break : SingleKeyword<Break>
|
public sealed class Break : SingleKeyword<Break>
|
||||||
{
|
{
|
||||||
public Break() : base("break")
|
public Break(int lineIndex,int wordIndex) : base("break", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Break(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -295,9 +327,13 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Continue : SingleKeyword<Continue>
|
public sealed class Continue : SingleKeyword<Continue>
|
||||||
{
|
{
|
||||||
public Continue() : base("continue")
|
public Continue(int lineIndex,int wordIndex) : base("continue", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Continue(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -305,8 +341,12 @@ namespace Convention.Symbolization.Keyword
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Structure : NamespaceKeyword<Structure>
|
public sealed class Structure : NamespaceKeyword<Structure>
|
||||||
{
|
{
|
||||||
public Structure() : base("struct")
|
public Structure(int lineIndex,int wordIndex) : base("struct", lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public override Internal.Keyword CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
|
{
|
||||||
|
return new Structure(lineIndex, wordIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -118,10 +118,10 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public static Namespace CreateRootNamespace()
|
public static Namespace CreateRootNamespace()
|
||||||
{
|
{
|
||||||
return new("global");
|
return new("global", 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Namespace(string symbolName) : base(symbolName) { }
|
private Namespace(string symbolName, int lineIndex, int wordIndex) : base(symbolName, lineIndex, wordIndex) { }
|
||||||
|
|
||||||
public override bool Equals(Namespace other)
|
public override bool Equals(Namespace other)
|
||||||
{
|
{
|
||||||
|
@@ -4,7 +4,7 @@ namespace Convention.Symbolization.Primitive
|
|||||||
{
|
{
|
||||||
public class PrimitiveType<T> : Internal.Variable
|
public class PrimitiveType<T> : Internal.Variable
|
||||||
{
|
{
|
||||||
public PrimitiveType() : base(new(typeof(T).Name, typeof(T)))
|
public PrimitiveType() : base(new(typeof(T).Name, typeof(T), 0, 0))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,15 +34,15 @@ namespace Convention.Symbolization.Primitive
|
|||||||
private readonly PrimitiveType<T> MyPrimitiveType = new();
|
private readonly PrimitiveType<T> MyPrimitiveType = new();
|
||||||
public T Value;
|
public T Value;
|
||||||
|
|
||||||
public PrimitiveInstance(string symbolName, T value, PrimitiveType<T> primitiveType) : base(symbolName)
|
public PrimitiveInstance(string symbolName,int lineIndex,int wordIndex, T value, PrimitiveType<T> primitiveType) : base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
this.Value = value;
|
this.Value = value;
|
||||||
this.MyPrimitiveType = primitiveType;
|
this.MyPrimitiveType = primitiveType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override PrimitiveInstance<T> CloneVariable(string targetSymbolName)
|
public override PrimitiveInstance<T> CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
return new(targetSymbolName, MyPrimitiveType.CloneValue(this.Value), this.MyPrimitiveType);
|
return new(targetSymbolName, lineIndex, wordIndex, MyPrimitiveType.CloneValue(this.Value), this.MyPrimitiveType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(PrimitiveInstance<T> other)
|
public override bool Equals(PrimitiveInstance<T> other)
|
||||||
|
@@ -2,26 +2,25 @@
|
|||||||
{
|
{
|
||||||
public class ScriptWordVariable : CloneableVariable<ScriptWordVariable>
|
public class ScriptWordVariable : CloneableVariable<ScriptWordVariable>
|
||||||
{
|
{
|
||||||
public readonly string word;
|
public string Word => this.SymbolInfo.SymbolName;
|
||||||
|
|
||||||
public ScriptWordVariable(string word) : base("")
|
public ScriptWordVariable(string word, int lineIndex, int wordIndex) : base((string)word.Clone(), lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
this.word = (string)word.Clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ScriptWordVariable CloneVariable(string targetSymbolName)
|
public override ScriptWordVariable CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
return new ScriptWordVariable(word);
|
return new ScriptWordVariable(Word, lineIndex, wordIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(ScriptWordVariable other)
|
public override bool Equals(ScriptWordVariable other)
|
||||||
{
|
{
|
||||||
return other is not null && word.Equals(other.word);
|
return other is not null && Word.Equals(other.Word);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return word;
|
return Word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,14 +20,14 @@ namespace Convention.Symbolization.Internal
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Structure(string symbolName, Namespace parentNamespace) : base(symbolName)
|
private Structure(string symbolName, int lineIndex,int wordIndex, Namespace parentNamespace) : base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
this.ParentNamespace = parentNamespace;
|
this.ParentNamespace = parentNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Structure Create(string structureName, Namespace parent)
|
public static Structure Create(VariableSymbol symbol, Namespace parent)
|
||||||
{
|
{
|
||||||
Structure result = new(structureName, parent);
|
Structure result = new(symbol.SymbolName, symbol.LineIndex, symbol.WordIndex, parent);
|
||||||
parent.AddStructure(result);
|
parent.AddStructure(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,8 @@ namespace Convention.Symbolization.Internal
|
|||||||
{
|
{
|
||||||
public readonly Structure StructureType;
|
public readonly Structure StructureType;
|
||||||
private readonly Dictionary<string, Variable> MemberFields;
|
private readonly Dictionary<string, Variable> MemberFields;
|
||||||
public StructureInstance(string symbolName, Structure structureType)
|
public StructureInstance(string symbolName, int lineIndex, int wordIndex, Structure structureType)
|
||||||
: base(symbolName)
|
: base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
this.StructureType = structureType;
|
this.StructureType = structureType;
|
||||||
this.MemberFields = structureType.CloneMemberFields();
|
this.MemberFields = structureType.CloneMemberFields();
|
||||||
@@ -61,9 +61,9 @@ namespace Convention.Symbolization.Internal
|
|||||||
{
|
{
|
||||||
return this == other;
|
return this == other;
|
||||||
}
|
}
|
||||||
public override StructureInstance CloneVariable(string targetSymbolName)
|
public override StructureInstance CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
return new StructureInstance(targetSymbolName, this.StructureType);
|
return new StructureInstance(targetSymbolName, lineIndex, wordIndex, this.StructureType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable GetField(string memberName)
|
public Variable GetField(string memberName)
|
||||||
|
@@ -31,7 +31,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public abstract class Variable<T> : Variable, IEquatable<T>
|
public abstract class Variable<T> : Variable, IEquatable<T>
|
||||||
{
|
{
|
||||||
protected Variable(string symbolName) : base(new VariableSymbol(symbolName, typeof(T))) { }
|
protected Variable(string symbolName, int lineIndex, int wordIndex) : base(new VariableSymbol(symbolName, typeof(T), lineIndex, wordIndex)) { }
|
||||||
public abstract bool Equals(T other);
|
public abstract bool Equals(T other);
|
||||||
|
|
||||||
public override bool Equals(Variable other)
|
public override bool Equals(Variable other)
|
||||||
@@ -62,24 +62,24 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public abstract class CloneableVariable<T> : Variable<T>, ICloneable
|
public abstract class CloneableVariable<T> : Variable<T>, ICloneable
|
||||||
{
|
{
|
||||||
protected CloneableVariable(string symbolName) : base(symbolName)
|
protected CloneableVariable(string symbolName, int lineIndex, int wordIndex) : base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Clone() => CloneVariable(SymbolInfo.SymbolName);
|
public object Clone() => CloneVariable(SymbolInfo.SymbolName, 0, 0);
|
||||||
|
|
||||||
public abstract T CloneVariable(string targetSymbolName);
|
public abstract T CloneVariable(string targetSymbolName, int lineIndex, int wordIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class NullVariable : CloneableVariable<NullVariable>
|
public sealed class NullVariable : CloneableVariable<NullVariable>
|
||||||
{
|
{
|
||||||
public NullVariable(string symbolName) : base(symbolName)
|
public NullVariable(string symbolName, int lineIndex, int wordIndex) : base(symbolName, lineIndex, wordIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override NullVariable CloneVariable(string targetSymbolName)
|
public override NullVariable CloneVariable(string targetSymbolName, int lineIndex, int wordIndex)
|
||||||
{
|
{
|
||||||
return new(targetSymbolName);
|
return new(targetSymbolName, lineIndex, wordIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(NullVariable other)
|
public override bool Equals(NullVariable other)
|
||||||
@@ -90,13 +90,17 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public readonly struct VariableSymbol
|
public readonly struct VariableSymbol
|
||||||
{
|
{
|
||||||
|
public readonly int LineIndex;
|
||||||
|
public readonly int WordIndex;
|
||||||
public readonly string SymbolName;
|
public readonly string SymbolName;
|
||||||
public readonly Type VariableType;
|
public readonly Type VariableType;
|
||||||
|
|
||||||
public VariableSymbol(string symbolName, Type variableType)
|
public VariableSymbol(string symbolName, Type variableType, int lineIndex,int wordIndex)
|
||||||
{
|
{
|
||||||
this.SymbolName = symbolName;
|
this.SymbolName = symbolName;
|
||||||
this.VariableType = variableType;
|
this.VariableType = variableType;
|
||||||
|
this.LineIndex = lineIndex;
|
||||||
|
this.WordIndex = wordIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(VariableSymbol other)
|
public bool Equals(VariableSymbol other)
|
||||||
|
@@ -17,10 +17,15 @@ namespace Convention.Symbolization
|
|||||||
private readonly SymbolizationContext ParentContext;
|
private readonly SymbolizationContext ParentContext;
|
||||||
public readonly Internal.Namespace CurrentNamespace;
|
public readonly Internal.Namespace CurrentNamespace;
|
||||||
|
|
||||||
|
private void Compile(Internal.SymbolizationReader reader)
|
||||||
|
{
|
||||||
|
reader.CompleteScopeWord(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void Compile(Dictionary<int, Dictionary<int, Internal.Variable>> scriptWords)
|
public void Compile(Dictionary<int, Dictionary<int, Internal.Variable>> scriptWords)
|
||||||
{
|
{
|
||||||
new Internal.SymbolizationReader() { ScriptWords = scriptWords }.CompleteScopeWord(this);
|
// Turn the script words into scope words
|
||||||
|
Compile(new Internal.SymbolizationReader() { ScriptWords = scriptWords });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Compile(string allText)
|
public void Compile(string allText)
|
||||||
@@ -29,9 +34,8 @@ namespace Convention.Symbolization
|
|||||||
Internal.SymbolizationReader reader = new();
|
Internal.SymbolizationReader reader = new();
|
||||||
foreach (char ch in allText)
|
foreach (char ch in allText)
|
||||||
reader.ReadChar(ch);
|
reader.ReadChar(ch);
|
||||||
var scriptWords = reader.ScriptWords;
|
|
||||||
// Turn the script words into scope words
|
// Turn the script words into scope words
|
||||||
reader.CompleteScopeWord(this);
|
Compile(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Compile(ToolFile file)
|
public void Compile(ToolFile file)
|
||||||
|
@@ -106,7 +106,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
#region Read Scope Words
|
#region Read Scope Words
|
||||||
|
|
||||||
private class KeywordEntry
|
public class KeywordEntry
|
||||||
{
|
{
|
||||||
public int line = 1;
|
public int line = 1;
|
||||||
public int wordIndex = 1;
|
public int wordIndex = 1;
|
||||||
@@ -118,10 +118,9 @@ namespace Convention.Symbolization.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<Keyword, KeywordEntry> ScopeWords = new();
|
|
||||||
|
|
||||||
public void CompleteScopeWord(SymbolizationContext rootContext)
|
public void CompleteScopeWord(SymbolizationContext rootContext)
|
||||||
{
|
{
|
||||||
|
Dictionary<Keyword, KeywordEntry> ScopeWords = new();
|
||||||
Keyword currentKey = null;
|
Keyword currentKey = null;
|
||||||
bool isNextKeyword = true;
|
bool isNextKeyword = true;
|
||||||
foreach(var line in ScriptWords)
|
foreach(var line in ScriptWords)
|
||||||
@@ -139,7 +138,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidGrammarException($"Line {line.Key}, word {wordCounter}: Expected a keyword, but got {word.Value}");
|
throw new InvalidGrammarException($"Line {line.Key}, Word {wordCounter}: Expected a keyword, but got {word.Value}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user