/// <summary> /// 技術効果リストに項目を挿入する /// </summary> /// <param name="command">挿入対象の項目</param> /// <param name="index">挿入する位置</param> public void InsertCommand(Command command, int index) { Effects.Insert(index, command); }
/// <summary> /// コピーコンストラクタ /// </summary> /// <param name="original">複製元のイベントコマンド</param> public Command(Command original) { Type = original.Type; // 参照型のオブジェクトを格納する場合はここをdeep copyに変える Which = original.Which; Value = original.Value; When = original.When; Where = original.Where; foreach (Trigger trigger in original.Triggers) { Triggers.Add(new Trigger(trigger)); } }
/// <summary> /// 技術効果リストに項目を追加する /// </summary> /// <param name="command">追加対象の項目</param> public void AddCommand(Command command) { Effects.Add(command); }
/// <summary> /// commandセクションを構文解析する /// </summary> /// <param name="lexer">字句解析器</param> /// <returns>コマンド</returns> public static Command Parse(TextLexer lexer) { // = Token token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); return null; } // { token = lexer.GetToken(); if (token.Type != TokenType.OpenBrace) { Log.InvalidToken(LogCategory, token, lexer); return null; } Command command = new Command(); int lastLineNo = lexer.LineNo; while (true) { token = lexer.GetToken(); // ファイルの終端 if (token == null) { break; } // } (セクション終端) if (token.Type == TokenType.CloseBrace) { break; } // 無効なトークン if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); if (lexer.LineNo != lastLineNo) { // 現在行が最終解釈行と異なる場合、閉じ括弧が不足しているものと見なす lexer.ReserveToken(token); break; } continue; } string keyword = token.Value as string; if (string.IsNullOrEmpty(keyword)) { continue; } keyword = keyword.ToLower(); // type if (keyword.Equals("type")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なコマンド種類文字列 string s = token.Value as string; if (string.IsNullOrEmpty(s)) { continue; } s = s.ToLower(); if (!Commands.StringMap.ContainsKey(s)) { Log.InvalidToken(LogCategory, token, lexer); continue; } // コマンド種類 command.Type = Commands.StringMap[s]; // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // which if (keyword.Equals("which")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Number && token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); continue; } // パラメータ - which command.Which = token.Value; // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // value if (keyword.Equals("value")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Number && token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); continue; } // パラメータ - value command.Value = token.Value; // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // when if (keyword.Equals("when")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Number && token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); continue; } // パラメータ - when command.When = token.Value; // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // where if (keyword.Equals("where")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Number && token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); continue; } // パラメータ - where command.Where = token.Value; // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // trigger if (keyword.Equals("trigger")) { List<Trigger> triggers = TriggerParser.Parse(lexer); if (triggers == null) { continue; } // トリガー command.Triggers.AddRange(triggers); // 最終解釈行を覚えておく lastLineNo = lexer.LineNo; continue; } // 無効なトークン Log.InvalidToken(LogCategory, token, lexer); if (lexer.LineNo != lastLineNo) { // 現在行が最終解釈行と異なる場合、閉じ括弧が不足しているものと見なす lexer.ReserveToken(token); break; } } return command; }