From 5fa89f6df20dbb6d4ffd1833a43042faa25b3d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fa=E9=B8=BD?= <1207247008@qq.com> Date: Mon, 1 Mar 2021 18:46:34 +0800 Subject: [PATCH] metadata --- UniGal.Compiler.Frontend/Response/rtenv.cs | 1 - UniGal.Compiler.Frontend/Response/toplevel.cs | 58 ++++++++++++++++++- UniGal.Compiler.IR/BasicElement.cs | 2 +- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/UniGal.Compiler.Frontend/Response/rtenv.cs b/UniGal.Compiler.Frontend/Response/rtenv.cs index 4ed5fd5..ea7de4c 100644 --- a/UniGal.Compiler.Frontend/Response/rtenv.cs +++ b/UniGal.Compiler.Frontend/Response/rtenv.cs @@ -47,7 +47,6 @@ internal static EnvironmentInfo.Display on_display(XmlReader r, List errors) { Metadata ret = new(); - - // r. + while (r.Read()) + { + if(r.NodeType == XmlNodeType.Element) + { + while (r.Read() && r.NodeType != XmlNodeType.EndElement) + { + if (r.NodeType == XmlNodeType.Element) + { + try + { + switch (r.Name) + { + case "src": + ret.Source = r.Value; + break; + case "dst": + ret.Target = r.Value; + break; + case "src_engine": + ret.SourceEngine = r.Value; + break; + case "dst_engine": + ret.TargetEngine = r.Value; + break; + case "src_characterset": + ret.SourceEncoding = Encoding.GetEncoding(r.Value); + break; + case "dst_characterset": + ret.TargetEncoding = Encoding.GetEncoding(r.Value); + break; + case "src_language": + ret.SourceCulture = CultureInfo.GetCultureInfo(r.Value); + break; + case "dst_language": + ret.SourceCulture = CultureInfo.GetCultureInfo(r.Value); + break; + case "comment": + ret.Comment = on_comment(r); + break; + default: + break; + } + } + catch (CultureNotFoundException e) + { + errors.Add(new parser_error(9002, ErrorServiety.Warning, new string[] { e.Message, e.InvalidCultureName! }, "出现脚本编译器不支持的语言")); + } + catch (ArgumentException e) + { + errors.Add(new parser_error(9002, ErrorServiety.Warning, new string[] { e.Message, e.ParamName! }, "出现脚本编译器不支持的编码")); + } + } + } + } + } return ret; } diff --git a/UniGal.Compiler.IR/BasicElement.cs b/UniGal.Compiler.IR/BasicElement.cs index 2169a37..57fa3e5 100644 --- a/UniGal.Compiler.IR/BasicElement.cs +++ b/UniGal.Compiler.IR/BasicElement.cs @@ -8,7 +8,7 @@ namespace UniGal.Compiler.IR public class BasicElement { /// 直观编辑器所使用的注释 - public StringView Comment = new StringView(); + public string Comment = ""; /// /// 原始表示 ///