EP Symboliztion +Namespace
This commit is contained in:
@@ -18,7 +18,14 @@ namespace Convention.Symbolization.Internal
|
||||
return this.GetType() == other.GetType();
|
||||
}
|
||||
|
||||
public abstract Keyword ControlContext(SymbolizationContext context, ScriptWordVariable next);
|
||||
public virtual Keyword ControlContext(SymbolizationContext context, int line, int wordIndex, Variable next)
|
||||
{
|
||||
return ControlContext(context, next);
|
||||
}
|
||||
protected virtual Keyword ControlContext(SymbolizationContext context, Variable next)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Keyword<T> : Keyword where T : Keyword<T>, new()
|
||||
@@ -56,15 +63,19 @@ namespace Convention.Symbolization.Keyword
|
||||
private ToolFile ImportFile = new("./");
|
||||
private string buffer = "";
|
||||
|
||||
public override Internal.Keyword ControlContext(SymbolizationContext context, Internal.ScriptWordVariable next)
|
||||
protected override Internal.Keyword ControlContext(SymbolizationContext context, Internal.Variable next)
|
||||
{
|
||||
if (next.word == ";")
|
||||
if (next is not Internal.ScriptWordVariable swv)
|
||||
{
|
||||
throw new InvalidGrammarException($"Not expected a key word: {next}");
|
||||
}
|
||||
if (swv.word == ";")
|
||||
{
|
||||
var importContext = new SymbolizationContext(context);
|
||||
importContext.Compile(ImportFile);
|
||||
return null;
|
||||
}
|
||||
else if(next.word==".")
|
||||
else if (swv.word == ".")
|
||||
{
|
||||
ImportFile = ImportFile | buffer;
|
||||
buffer = "";
|
||||
@@ -73,7 +84,7 @@ namespace Convention.Symbolization.Keyword
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer += next.word;
|
||||
buffer += swv.word;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -87,6 +98,57 @@ namespace Convention.Symbolization.Keyword
|
||||
public Namespace() : base("namespace")
|
||||
{
|
||||
}
|
||||
|
||||
public override Internal.Keyword CloneVariable(string targetSymbolName)
|
||||
{
|
||||
return new Namespace();
|
||||
}
|
||||
|
||||
private enum Pause
|
||||
{
|
||||
Name, Body
|
||||
}
|
||||
|
||||
private Pause pause = Pause.Name;
|
||||
private int layer = 0;
|
||||
private SymbolizationContext bulidingContext = null;
|
||||
private Dictionary<int, Dictionary<int, Internal.Variable>> subScriptWords = new();
|
||||
|
||||
public override Internal.Keyword ControlContext(SymbolizationContext context,int line,int wordIndex, Internal.Variable next)
|
||||
{
|
||||
if (next is not Internal.ScriptWordVariable swv)
|
||||
{
|
||||
throw new InvalidGrammarException($"Not expected a key word: {next}");
|
||||
}
|
||||
if (pause == Pause.Name)
|
||||
{
|
||||
bulidingContext = new(context, context.CurrentNamespace.CreateOrGetSubNamespace(swv.word));
|
||||
bulidingContext.CurrentNamespace.BeginUpdate();
|
||||
pause = Pause.Body;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (swv.word == "{")
|
||||
layer++;
|
||||
else if (swv.word == "}")
|
||||
layer--;
|
||||
if (layer == 0)
|
||||
{
|
||||
bulidingContext.Compile(subScriptWords);
|
||||
bulidingContext.CurrentNamespace.EndAndTryApplyUpdate();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (subScriptWords.TryGetValue(line, out var rline) == false)
|
||||
{
|
||||
subScriptWords.Add(line, rline = new());
|
||||
}
|
||||
rline.Add(wordIndex, next);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -45,7 +45,7 @@ namespace Convention.Symbolization.Internal
|
||||
Structures.Add(structure.SymbolInfo.SymbolName, structure);
|
||||
}
|
||||
|
||||
public bool EndAndTApplyUpdate()
|
||||
public bool EndAndTryApplyUpdate()
|
||||
{
|
||||
Updateable--;
|
||||
if (Updateable == 0)
|
||||
|
@@ -17,15 +17,21 @@ namespace Convention.Symbolization
|
||||
private readonly SymbolizationContext ParentContext;
|
||||
public readonly Internal.Namespace CurrentNamespace;
|
||||
|
||||
|
||||
public void Compile(Dictionary<int, Dictionary<int, Internal.Variable>> scriptWords)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void Compile(string allText)
|
||||
{
|
||||
// Create a new reader to parse the script words
|
||||
Internal.SymbolizationReader reader = new();
|
||||
foreach (char ch in allText)
|
||||
reader.ReadChar(ch);
|
||||
var ScriptWords = reader.ScriptWords;
|
||||
var scriptWords = reader.ScriptWords;
|
||||
// Turn the script words into scope words
|
||||
reader.CompleteScopeWord(this);
|
||||
this.Compile(scriptWords);
|
||||
}
|
||||
|
||||
public void Compile(ToolFile file)
|
||||
|
@@ -13,7 +13,7 @@ namespace Convention.Symbolization.Internal
|
||||
private string buffer = "";
|
||||
private int lineContext = 1;
|
||||
private bool isOutOfStringline = true;
|
||||
public Dictionary<int, List<Variable>> ScriptWords = new() { { 1, new() } };
|
||||
public Dictionary<int, Dictionary<int, Variable>> ScriptWords = new() { { 1, new() } };
|
||||
|
||||
private static HashSet<char> ControllerCharSet = new()
|
||||
{
|
||||
@@ -76,11 +76,11 @@ namespace Convention.Symbolization.Internal
|
||||
}
|
||||
if (Internal.Keyword.Keywords.TryGetValue(buffer, out var keyword))
|
||||
{
|
||||
line.Add(keyword.Clone() as Internal.Variable);
|
||||
line.Add(line.Count + 1, keyword.Clone() as Internal.Variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
line.Add(new ScriptWordVariable(buffer));
|
||||
line.Add(line.Count + 1, new ScriptWordVariable(buffer));
|
||||
}
|
||||
buffer = "";
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace Convention.Symbolization.Internal
|
||||
}
|
||||
else
|
||||
{
|
||||
currentKey = currentKey.ControlContext(rootContext, word);
|
||||
currentKey = currentKey.ControlContext(rootContext, line.Key, word.Key, word.Value);
|
||||
}
|
||||
wordCounter++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user