示例#1
0
        public static string ReadBackwardsTo(this CodeNinja.AmbientParser.IUnoCodeReader r, string token)
        {
            var offset = r.Offset;

            while (true)
            {
                var tt = r.PeekTokenReverse();
                if (tt == TokenType.EndOfFile)
                {
                    return(r.ReadText(offset - r.Offset));
                }
                if (tt == TokenType.Identifier)
                {
                    var text = r.ReadText(offset - r.Offset);
                    if (text.StartsWith(token))
                    {
                        return(text);
                    }
                }
                var k = r.ReadTokenReverse();
                if (k == TokenType.EndOfFile)
                {
                    return(null);
                }
            }
        }
示例#2
0
        public static string ReadBackwardsTo(this CodeNinja.AmbientParser.IUnoCodeReader r, params TokenType[] tokenTypes)
        {
            var offset = r.Offset;

            while (true)
            {
                var tt = r.PeekTokenReverse();
                if (tt == TokenType.EndOfFile)
                {
                    return(r.ReadText(offset - r.Offset));
                }
                if (tokenTypes.Contains(tt))
                {
                    return(r.ReadText(offset - r.Offset));
                }
                var k = r.ReadTokenReverse();
                if (k == TokenType.EndOfFile)
                {
                    return(null);
                }
            }
        }