using System; using System.IO; using System.Collections.Generic; namespace Convention.Symbolization.Internal { public abstract class Keyword : CloneableVariable { protected Keyword(string keyword) : base(keyword) { Keywords.TryAdd(keyword, this); } public static readonly Dictionary Keywords = new(); public override bool Equals(Keyword other) { return this.GetType() == other.GetType(); } public abstract Keyword ControlContext(SymbolizationContext context, ScriptWordVariable next); } public abstract class Keyword : Keyword where T : Keyword, new() { private static T MyInstance = new(); protected Keyword(string keyword) : base(keyword) { } public override bool Equals(Variable other) { return MyInstance == other; } } } namespace Convention.Symbolization.Keyword { /// /// file /// public sealed class Import : Internal.Keyword { public Import() : base("import") { } public override Internal.Keyword CloneVariable(string targetSymbolName) { return new Import(); } private ToolFile ImportFile = new("./"); private string buffer = ""; public override Internal.Keyword ControlContext(SymbolizationContext context, Internal.ScriptWordVariable next) { if (next.word == ";") { var importContext = new SymbolizationContext(context); importContext.Compile(ImportFile); return null; } else if(next.word==".") { ImportFile = ImportFile | buffer; buffer = ""; if (ImportFile.Exists() == false) throw new FileNotFoundException($"File path not found: {ImportFile}", ImportFile); } else { buffer += next.word; } return this; } } /// /// name { ... } /// public sealed class Namespace : Internal.Keyword { public Namespace() : base("namespace") { } } /// /// FunctionName(parameter-list) return-type { ... return return-type-instance; } /// public sealed class FunctionDef : Internal.Keyword { public FunctionDef() : base("def") { } } /// /// symbol; /// public sealed class Return : Internal.Keyword { public Return() : base("return") { } } /// /// (bool-expression) expression /// public sealed class If : Internal.Keyword { public If() : base("if") { } } /// /// expression expression /// public sealed class Else : Internal.Keyword { public Else() : base("else") { } } /// /// (bool-expression) expression /// public sealed class While : Internal.Keyword { public While() : base("while") { } } /// /// ; /// public sealed class Break : Internal.Keyword { public Break() : base("break") { } } /// /// ; /// public sealed class Continue : Internal.Keyword { public Continue() : base("continue") { } } /// /// structureName { ... } /// public sealed class Structure : Internal.Keyword { public Structure() : base("struct") { } } }