public override Expression Scan(ParseEngine engine) { var start = engine.Pointer; var kw = new WhileKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query); var index = engine.Advance(Token.Length).Skip().Pointer; var chars = engine.Characters; if (index == chars.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); return(kw); } if (chars[index] == '(') { var ln = engine.CurrentLine; var col = engine.CurrentColumn; kw.Condition = engine.Advance().ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col)); if (kw.Condition.Container == null || !kw.Condition.Container.HasContent) { engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); } SetMarker(engine); kw.Body = engine.ParseStatement(); UnsetMarker(engine); if (engine.LastStatement != null && engine.LastStatement.IsKeyword <DoKeyword>()) { if (kw.Body.IsEmpty) { IsDoWhile = true; engine.LastStatement.GetKeyword <DoKeyword>().While = kw; } else { engine.AddError(new YAMPDoWhileNotEmptyError(engine), kw); } } } else { engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); } kw.Length = engine.Pointer - start; return(kw); }
public override Expression Scan(ParseEngine engine) { var start = engine.Pointer; var kw = new WhileKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query); var index = engine.Advance(Token.Length).Skip().Pointer; var chars = engine.Characters; if (index == chars.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); return kw; } if (chars[index] == '(') { var ln = engine.CurrentLine; var col = engine.CurrentColumn; kw.Condition = engine.Advance().ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col)); if (kw.Condition.Container == null || !kw.Condition.Container.HasContent) { engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); } SetMarker(engine); kw.Body = engine.ParseStatement(); UnsetMarker(engine); if (engine.LastStatement != null && engine.LastStatement.IsKeyword<DoKeyword>()) { if (kw.Body.IsEmpty) { IsDoWhile = true; engine.LastStatement.GetKeyword<DoKeyword>().While = kw; } else { engine.AddError(new YAMPDoWhileNotEmptyError(engine), kw); } } } else { engine.AddError(new YAMPWhileArgumentsMissing(engine), kw); } kw.Length = engine.Pointer - start; return kw; }