From 296d5bb615cc008acea4e4692b864a8678f62f5b Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 11 Nov 2022 00:34:30 +0800 Subject: [PATCH] Reads score operation as structure. --- Assets/Cryville/Common/Identifier.cs | 2 +- Assets/Cryville/Crtr/Judge.cs | 10 +++++++--- Assets/Cryville/Crtr/Ruleset.cs | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Assets/Cryville/Common/Identifier.cs b/Assets/Cryville/Common/Identifier.cs index 156fe68..e659cd6 100644 --- a/Assets/Cryville/Common/Identifier.cs +++ b/Assets/Cryville/Common/Identifier.cs @@ -11,7 +11,6 @@ namespace Cryville.Common { Key = IdentifierManager.SharedInstance.Request(name); } public override bool Equals(object obj) { - if (obj == null && Key == 0) return true; if (obj == null || !(obj is Identifier)) return false; return Equals((Identifier)obj); } @@ -22,6 +21,7 @@ namespace Cryville.Common { return Key; } public override string ToString() { + if (Key == 0) return ""; return Name.ToString(); } public static implicit operator Identifier(string identifier) { diff --git a/Assets/Cryville/Crtr/Judge.cs b/Assets/Cryville/Crtr/Judge.cs index e474132..488bb64 100644 --- a/Assets/Cryville/Crtr/Judge.cs +++ b/Assets/Cryville/Crtr/Judge.cs @@ -53,11 +53,15 @@ namespace Cryville.Crtr { public PdtExpression hit; public Identifier[] pass; public Identifier miss; - public Dictionary scores; + public Dictionary scores; } public class ScoreOperation { - public int name; - public PdtOperator op; + public Identifier name; + public Identifier op; + public override string ToString() { + if (op == default(Identifier)) return name.ToString(); + else return string.Format("{0} {1}", name, op); + } } public class ScoreDefinition { public PdtExpression value; diff --git a/Assets/Cryville/Crtr/Ruleset.cs b/Assets/Cryville/Crtr/Ruleset.cs index 4bd95f1..401311b 100644 --- a/Assets/Cryville/Crtr/Ruleset.cs +++ b/Assets/Cryville/Crtr/Ruleset.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; +using System.Text.RegularExpressions; using SIdentifier = Cryville.Common.Identifier; namespace Cryville.Crtr { @@ -163,6 +164,13 @@ namespace Cryville.Crtr { if (type.Equals(typeof(Identifier))) { return (Identifier)exp; } + else if (type == typeof(ScoreOperation)) { + var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$"); + var name = new Identifier(m.Groups[1].Value); + if (!m.Groups[2].Success) return new ScoreOperation { name = name }; + var op = new Identifier(m.Groups[2].Value); + return new ScoreOperation { name = name, op = op }; + } } return base.ChangeType(value, type, culture); }