private static CommentToken ResolveDelphiComment(LexerContext context) { var begin = context.GetIndex(); context.IncIndex(); context.IncIndex(); var inners = new List <CommentToken>(); while (!context.IsEnded() && !context.IsNewLineNow()) { if (CommentToken.IsOldStyleCommentBegin(context)) { inners.Add(ResolveOldStyleComment(context)); continue; } if (CommentToken.IsTurboPascalCommentBegin(context)) { inners.Add(ResolveTurboPascalComment(context)); continue; } context.IncIndex(); } var isSingleLine = inners.All(c => c.IsSingleLineComment); if (!isSingleLine) { throw new SyntaxErrorException(); } return(new CommentToken(true, inners, begin, context.GetIndex())); }
private static CommentToken ResolveComment(LexerContext context) { if (CommentToken.IsOldStyleCommentBegin(context)) { return(ResolveOldStyleComment(context)); } else if (CommentToken.IsTurboPascalCommentBegin(context)) { return(ResolveTurboPascalComment(context)); } else { return(ResolveDelphiComment(context)); } }
private static CommentToken ResolveOldStyleComment(LexerContext context) { var begin = context.GetIndex(); context.IncIndex(); context.IncIndex(); var inners = new List <CommentToken>(); var isOneLine = true; while (!context.IsEnded()) { if (CommentToken.IsTurboPascalCommentBegin(context)) { inners.Add(ResolveTurboPascalComment(context)); continue; } if (CommentToken.IsDelphiCommentBegin(context)) { inners.Add(ResolveDelphiComment(context)); continue; } if (context.IsNewLineNow()) { isOneLine = false; for (var i = 0; i < Environment.NewLine.Length; i++) { context.IncIndex(); } } if (CommentToken.IsOldStyleCommentEnd(context)) { context.IncIndex(); context.IncIndex(); break; } context.IncIndex(); } return(new CommentToken(isOneLine && inners.All(c => c.IsSingleLineComment), inners, begin, context.GetIndex())); }