コード例 #1
0
ファイル: Lexer.cs プロジェクト: chernokoz/python-lexer
        private static CommentToken ResolveTurboPascalComment(LexerContext context)
        {
            var begin = context.GetIndex();

            context.IncIndex();
            var inners    = new List <CommentToken>();
            var isOneLine = true;

            while (!context.IsEnded())
            {
                if (CommentToken.IsOldStyleCommentBegin(context))
                {
                    inners.Add(ResolveOldStyleComment(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 (context.IsNewLineNow())
                {
                    isOneLine = false;
                    for (var i = 0; i < Environment.NewLine.Length; i++)
                    {
                        context.IncIndex();
                    }
                }

                if (CommentToken.IsTurboPascalCommentEnd(context))
                {
                    context.IncIndex();
                    break;
                }
                context.IncIndex();
            }

            return(new CommentToken(isOneLine && inners.All(c => c.IsSingleLineComment), inners,
                                    begin, context.GetIndex()));
        }
コード例 #2
0
ファイル: Lexer.cs プロジェクト: chernokoz/python-lexer
        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()));
        }