/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("GroupExpression.Interpret(): " + Name + ", " + Expressions.Count); // 戻り値の準備 Result result = new Result(Name); //Matches = new TokenMatches(Name); //IsMatch = false; foreach (GeneratedExpression exp in Expressions) { exp.Interpret(context); Result itemResult = context.PopResult(); result.Matches.ConcatTokens(itemResult.Matches); if (itemResult.IsMatch == false) { if (exp.Type == ExpressionType.Option) { continue; } result.IsMatch = false; //throw new InterpreterException("FieldExpression.Interpret() Error"); break; } else { result.IsMatch = true; } } context.PushResult(result); }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("NonterminalExpression.Interpret(): " + Name); // 戻り値の準備 Result result = new Result(Name); //Matches = new TokenMatches(Name); //IsMatch = false; if (context.Fields.ContainsKey(Name) == false) { throw new InterpreterException("NonterminalExpression.Interpret() Error"); } GeneratedExpression exp = context.Fields[Name]; exp.Interpret(context); Result itemResult = context.PopResult(); result.IsMatch = itemResult.IsMatch; result.Matches.ConcatTokens(itemResult.Matches); context.PushResult(result); }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { // 一番深い要素を探す GeneratedExpression exp = GetDeepestExpression(context, this); if (exp == null) { ThrowParseException( ErrorMessages.ExpressionNotFound ); } // 見つかった要素を実行する DebugLog("RootExpression: (" + exp.Name + ")"); exp.Interpret(context); Result itemResult = context.PopResult(); // 最後のトークンをチェックする Token <TokenType> token = context.Current; if (itemResult.IsMatch == false || token != null) { ThrowParseException( ErrorMessages.UnexpectedToken, token ); } }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("OrExpression.Interpret(): " + Name + ", " + Expressions.Count); // 戻り値の準備 Result result = new Result(Name); //Matches = new TokenMatches(Name); //IsMatch = false; foreach (GeneratedExpression exp in Expressions) { //Console.WriteLine("*** OrExpression.Interpret(): " + exp.Name); exp.Interpret(context); //Console.WriteLine("*** OrExpression.Interpret(): " + exp.IsMatch); Result itemResult = context.PopResult(); if (itemResult.IsMatch) { result.IsMatch = true; result.Matches.ConcatTokens(itemResult.Matches); break; } } context.PushResult(result); }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("OptionExpression.Interpret(): " + Name); // 戻り値の準備 Result result = new Result(Name); //Matches = new TokenMatches(Name); //IsMatch = false; foreach (GeneratedExpression exp in Expressions) { exp.Interpret(context); Result itemResult = context.PopResult(); if (itemResult.IsMatch) { result.IsMatch = true; result.Matches.ConcatTokens(itemResult.Matches); //Matches.ConcatTokens(exp.Matches); //break; } else { result.Matches.ConcatTokens(itemResult.Matches); //Matches.ConcatTokens(exp.Matches); break; } } context.PushResult(result); }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("FieldExpression.Interpret(): " + Name); // 戻り値の準備 Result result = new Result(Name); // 子要素を巡回する foreach (GeneratedExpression exp in Expressions) { DebugLog("-\tFieldExpression.Expressions : (" + exp.Name + ")"); exp.Interpret(context); Result itemResult = context.PopResult(); result.Matches.ConcatTokens(itemResult.Matches); if (itemResult.IsMatch == false) { DebugLog("-\texp.IsMatch == false : (" + exp.Name + ")"); if (exp.Type == ExpressionType.Option) { continue; } result.IsMatch = false; //throw new InterpreterException("FieldExpression.Interpret() Error"); break; } else { result.IsMatch = true; } } // マッチしたらイベントを発生させる if (result.IsMatch) { context.OnMatchField(Name, result.Matches); } context.PushResult(result); }
/// <summary> /// 評価用メソッド. /// </summary> /// <param name="context">コンテキストオブジェクト.</param> public override void Interpret(GeneratorContext context) { DebugLog("LoopExpression.Interpret(): " + Name + ", " + Expressions.Count); // 戻り値の準備 Result result = new Result(Name); int maxCount = 0; foreach (GeneratedExpression exp in Expressions) { if (exp.Type != ExpressionType.Option) { maxCount++; } } bool loop = true; while (loop) { int count = 0; GeneratedExpression exp2 = null; foreach (GeneratedExpression exp in Expressions) { exp2 = exp; DebugLog("LoopExpression.Expressions : (" + exp.Name + ")"); exp.Interpret(context); Result itemResult = context.PopResult(); result.IsMatch = itemResult.IsMatch; if (itemResult.IsMatch == false) { if (exp.Type == ExpressionType.Option) { continue; } DebugLog("-\texp.IsMatch == false : (" + exp.Name + ")"); break; } result.Matches.ConcatTokens(itemResult.Matches); //Matches.ConcatTokens(exp.Matches); count++; } if (count == 0) { //Console.WriteLine("LoopExpression: count == 0: " + exp2.Type + ", " + exp2.Name); break; } if (count == maxCount) { } if (count != maxCount) { ThrowParseException( ErrorMessages.UnexpectedToken, context.Current ); } Token <TokenType> token = context.Current; if (token == null) { loop = false; break; } } context.PushResult(result); //Matches = matches; }