EP 0.1.1 转换
This commit is contained in:
@@ -8,10 +8,12 @@ namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public class SymbolizationReader
|
||||
{
|
||||
#region Read Script Words
|
||||
|
||||
private string buffer = "";
|
||||
private int lineContext = 0;
|
||||
private int lineContext = 1;
|
||||
private bool isOutOfStringline = true;
|
||||
public Dictionary<int, List<Variable>> ScriptWords = new() { { 0, new() } };
|
||||
public Dictionary<int, List<Variable>> ScriptWords = new() { { 1, new() } };
|
||||
|
||||
private static HashSet<char> ControllerCharSet = new()
|
||||
{
|
||||
@@ -22,6 +24,7 @@ namespace Convention.Symbolization.Internal
|
||||
'^',
|
||||
':',',','.','?',/*'\'','"',*/
|
||||
'@','#','$',
|
||||
';'
|
||||
};
|
||||
|
||||
public void ReadChar(char ch)
|
||||
@@ -30,16 +33,16 @@ namespace Convention.Symbolization.Internal
|
||||
{
|
||||
if (ControllerCharSet.Contains(ch))
|
||||
CompleteSingleSymbol(ch);
|
||||
else if (char.IsWhiteSpace(ch) || ch == '\n' || ch == '\r' || ch == '\t')
|
||||
else if (ch == '\n')
|
||||
CompleteLine();
|
||||
else if (char.IsWhiteSpace(ch) || ch == '\r' || ch == '\t')
|
||||
CompleteWord();
|
||||
else if (buffer.Length == 0 && ch == '"')
|
||||
BeginString();
|
||||
else if (ch == ';')
|
||||
CompleteLine();
|
||||
else if (char.IsLetter(ch) || char.IsDigit(ch))
|
||||
PushChar(ch);
|
||||
else
|
||||
throw new NotImplementedException($"{lineContext+1} line, {buffer} + <{ch}> not implemented");
|
||||
throw new NotImplementedException($"{lineContext + 1} line, {buffer} + <{ch}> not implemented");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,7 +51,7 @@ namespace Convention.Symbolization.Internal
|
||||
else if (ch == '"')
|
||||
EndString();
|
||||
else
|
||||
throw new NotImplementedException($"{lineContext+1} line, \"{buffer}\" + \'{ch}\' not implemented");
|
||||
throw new NotImplementedException($"{lineContext + 1} line, \"{buffer}\" + \'{ch}\' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,16 +70,25 @@ namespace Convention.Symbolization.Internal
|
||||
{
|
||||
if (buffer.Length > 0)
|
||||
{
|
||||
ScriptWords[lineContext].Add(new ScriptWordVariable(buffer));
|
||||
if (ScriptWords.TryGetValue(lineContext, out var line) == false)
|
||||
{
|
||||
ScriptWords.Add(lineContext, line = new());
|
||||
}
|
||||
if (Internal.Keyword.Keywords.TryGetValue(buffer, out var keyword))
|
||||
{
|
||||
line.Add(keyword.Clone() as Internal.Variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
line.Add(new ScriptWordVariable(buffer));
|
||||
}
|
||||
buffer = "";
|
||||
}
|
||||
}
|
||||
void CompleteLine()
|
||||
{
|
||||
CompleteWord();
|
||||
ScriptWords[lineContext].Add(new ScriptWordVariable(";"));
|
||||
lineContext++;
|
||||
ScriptWords.Add(lineContext, new());
|
||||
lineContext++; ;
|
||||
}
|
||||
void BeginString()
|
||||
{
|
||||
@@ -89,5 +101,39 @@ namespace Convention.Symbolization.Internal
|
||||
isOutOfStringline = true;
|
||||
CompleteWord();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read Scope Words
|
||||
|
||||
public void CompleteScopeWord(SymbolizationContext rootContext)
|
||||
{
|
||||
int wordCounter = 1;
|
||||
Internal.Keyword currentKey = null;
|
||||
foreach(var line in ScriptWords)
|
||||
{
|
||||
foreach (var word in line.Value)
|
||||
{
|
||||
if (currentKey == null)
|
||||
{
|
||||
if(currentKey is Internal.Keyword cky)
|
||||
{
|
||||
currentKey = cky;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidGrammarException($"Line {line.Key}, word {wordCounter}: Expected a keyword, but got {word}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentKey = currentKey.ControlContext(rootContext, word);
|
||||
}
|
||||
wordCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user