EP 0.1.1 语句分界线尚未完成
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Convention.Symbolization.Internal
|
||||
namespace Convention.Symbolization.Keyword
|
||||
{
|
||||
/// <summary>
|
||||
/// <b><see langword="import"/> namespace-expression</b>
|
||||
/// <b><see langword="import"/> file</b>
|
||||
/// </summary>
|
||||
public sealed class Import : Internal.Keyword<Import>
|
||||
{
|
||||
|
@@ -8,5 +8,14 @@ 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))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public class SymbolizationReader
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@
|
||||
|
||||
public ScriptWordVariable(string word) : base("")
|
||||
{
|
||||
this.word = word;
|
||||
this.word = (string)word.Clone();
|
||||
}
|
||||
|
||||
public override ScriptWordVariable CloneVariable(string targetSymbolName)
|
||||
@@ -19,20 +19,9 @@
|
||||
return other is not null && word.Equals(other.word);
|
||||
}
|
||||
|
||||
public Keyword GetKeyword()
|
||||
public override string ToString()
|
||||
{
|
||||
if(Keyword.Keywords.TryGetValue(word, out var keyword))
|
||||
return keyword;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Variable GetVariable(SymbolizationContext context)
|
||||
{
|
||||
if (context.Variables.TryGetValue(word, out var variable))
|
||||
{
|
||||
return variable;
|
||||
}
|
||||
return null;
|
||||
return word;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
41
Convention/[Symbolization]/Runner/SymbolizationContext.cs
Normal file
41
Convention/[Symbolization]/Runner/SymbolizationContext.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Convention.Symbolization
|
||||
{
|
||||
public class SymbolizationContext
|
||||
{
|
||||
public SymbolizationContext() : this(null, Internal.Namespace.CreateRootNamespace()) { }
|
||||
public SymbolizationContext(SymbolizationContext parent) : this(parent, parent.CurrentNamespace) { }
|
||||
public SymbolizationContext(SymbolizationContext parent, Internal.Namespace newNamespace)
|
||||
{
|
||||
this.ParentContext = parent;
|
||||
this.CurrentNamespace = newNamespace;
|
||||
}
|
||||
|
||||
private readonly SymbolizationContext ParentContext;
|
||||
private Dictionary<int, List<Internal.Variable>> ScriptWords;
|
||||
public readonly Dictionary<int, List<Internal.Variable>> ScriptCommands = new();
|
||||
public readonly Internal.Namespace CurrentNamespace;
|
||||
|
||||
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);
|
||||
ScriptWords = reader.ScriptWords;
|
||||
// Turn the script words into commands
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void Compile(ToolFile file)
|
||||
{
|
||||
if (file.Exists() == false)
|
||||
throw new FileNotFoundException($"File not found: {file}", file);
|
||||
var text = file.LoadAsText();
|
||||
this.Compile(text);
|
||||
}
|
||||
}
|
||||
}
|
93
Convention/[Symbolization]/Runner/SymbolizationReader.cs
Normal file
93
Convention/[Symbolization]/Runner/SymbolizationReader.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.Symbolization.Internal
|
||||
{
|
||||
public class SymbolizationReader
|
||||
{
|
||||
private string buffer = "";
|
||||
private int lineContext = 0;
|
||||
private bool isOutOfStringline = true;
|
||||
public Dictionary<int, List<Variable>> ScriptWords = new() { { 0, new() } };
|
||||
|
||||
private static HashSet<char> ControllerCharSet = new()
|
||||
{
|
||||
'{','}','(',')','[',']',
|
||||
'+','-','*','/','%',
|
||||
'=',
|
||||
'!','<','>','&','|',
|
||||
'^',
|
||||
':',',','.','?',/*'\'','"',*/
|
||||
'@','#','$',
|
||||
};
|
||||
|
||||
public void ReadChar(char ch)
|
||||
{
|
||||
if (isOutOfStringline)
|
||||
{
|
||||
if (ControllerCharSet.Contains(ch))
|
||||
CompleteSingleSymbol(ch);
|
||||
else if (char.IsWhiteSpace(ch) || ch == '\n' || 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");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((buffer.Length > 0 && buffer.Last() == '\\') || ch != '"')
|
||||
PushChar(ch);
|
||||
else if (ch == '"')
|
||||
EndString();
|
||||
else
|
||||
throw new NotImplementedException($"{lineContext+1} line, \"{buffer}\" + \'{ch}\' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void CompleteSingleSymbol(char ch)
|
||||
{
|
||||
CompleteWord();
|
||||
buffer = ch.ToString();
|
||||
CompleteWord();
|
||||
}
|
||||
|
||||
void PushChar(char ch)
|
||||
{
|
||||
buffer += ch;
|
||||
}
|
||||
void CompleteWord()
|
||||
{
|
||||
if (buffer.Length > 0)
|
||||
{
|
||||
ScriptWords[lineContext].Add(new ScriptWordVariable(buffer));
|
||||
buffer = "";
|
||||
}
|
||||
}
|
||||
void CompleteLine()
|
||||
{
|
||||
CompleteWord();
|
||||
ScriptWords[lineContext].Add(new ScriptWordVariable(";"));
|
||||
lineContext++;
|
||||
ScriptWords.Add(lineContext, new());
|
||||
}
|
||||
void BeginString()
|
||||
{
|
||||
if (buffer.Length > 0)
|
||||
throw new InvalidGrammarException($"String must start with nothing: {buffer}");
|
||||
isOutOfStringline = false;
|
||||
}
|
||||
void EndString()
|
||||
{
|
||||
isOutOfStringline = true;
|
||||
CompleteWord();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,56 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Convention.Symbolization
|
||||
{
|
||||
public class SymbolizationContext
|
||||
{
|
||||
public SymbolizationContext() : this(null, Internal.Namespace.CreateRootNamespace()) { }
|
||||
public SymbolizationContext(SymbolizationContext parent) : this(parent, parent.CurrentNamespace) { }
|
||||
public SymbolizationContext(SymbolizationContext parent, Internal.Namespace newNamespace)
|
||||
{
|
||||
this.ParentContext = parent;
|
||||
this.CurrentNamespace = newNamespace;
|
||||
}
|
||||
|
||||
public readonly SymbolizationContext ParentContext;
|
||||
public readonly Dictionary<int, List<Internal.Variable>> ScriptWords = new();
|
||||
public readonly Dictionary<int, List<Internal.Variable>> ScriptCommands = new();
|
||||
public readonly Dictionary<string, Internal.Variable> Variables = new();
|
||||
public readonly Internal.Namespace CurrentNamespace;
|
||||
|
||||
public SymbolizationContext Compile()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class SymbolizationRunner
|
||||
{
|
||||
private readonly Internal.Namespace GlobalNamespace;
|
||||
private readonly SymbolizationContext Context;
|
||||
private SymbolizationContext Context;
|
||||
|
||||
public SymbolizationRunner(SymbolizationContext context)
|
||||
public void Compile(string path)
|
||||
{
|
||||
GlobalNamespace = Internal.Namespace.CreateRootNamespace();
|
||||
Context = context;
|
||||
}
|
||||
public SymbolizationRunner() :this(new()){ }
|
||||
|
||||
public Exception Compile()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex;
|
||||
}
|
||||
return null;
|
||||
Context = new();
|
||||
Context.Compile(new ToolFile(path));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user