EP Symbolization 重构line-word-index

This commit is contained in:
ninemine
2025-07-05 16:57:59 +08:00
parent 8123ed4b15
commit 522010e7cd
9 changed files with 132 additions and 85 deletions

View File

@@ -17,10 +17,15 @@ namespace Convention.Symbolization
private readonly SymbolizationContext ParentContext;
public readonly Internal.Namespace CurrentNamespace;
private void Compile(Internal.SymbolizationReader reader)
{
reader.CompleteScopeWord(this);
}
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)
@@ -29,9 +34,8 @@ namespace Convention.Symbolization
Internal.SymbolizationReader reader = new();
foreach (char ch in allText)
reader.ReadChar(ch);
var scriptWords = reader.ScriptWords;
// Turn the script words into scope words
reader.CompleteScopeWord(this);
Compile(reader);
}
public void Compile(ToolFile file)

View File

@@ -106,7 +106,7 @@ namespace Convention.Symbolization.Internal
#region Read Scope Words
private class KeywordEntry
public class KeywordEntry
{
public int line = 1;
public int wordIndex = 1;
@@ -118,10 +118,9 @@ namespace Convention.Symbolization.Internal
}
}
private Dictionary<Keyword, KeywordEntry> ScopeWords = new();
public void CompleteScopeWord(SymbolizationContext rootContext)
{
Dictionary<Keyword, KeywordEntry> ScopeWords = new();
Keyword currentKey = null;
bool isNextKeyword = true;
foreach(var line in ScriptWords)
@@ -139,7 +138,7 @@ namespace Convention.Symbolization.Internal
}
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