// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ILSpy.Debugger.Services
{
///
/// Very naive parser.
///
static class ParserService
{
static HashSet mySet = new HashSet();
static ParserService()
{
mySet.AddRange((new [] {
".",
"{",
"}",
"(",
")",
"[",
"]",
" ",
"=",
"+",
"-",
"/",
"%",
"*",
"&",
Environment.NewLine,
";",
",",
"~",
"!",
"?",
@"\n",
@"\t",
@"\r",
"|"
}).AsReadOnly());
}
///
/// Returns the variable name
///
///
///
///
public static string SimpleParseAt(string fullText, int offset)
{
if (string.IsNullOrEmpty(fullText))
return string.Empty;
if (offset <= 0 || offset >= fullText.Length)
return string.Empty;
string currentValue = fullText[offset].ToString();
if (mySet.Contains(currentValue))
return string.Empty;
int left = offset, right = offset;
//search left
while((!mySet.Contains(currentValue) || currentValue == ".") && left > 0)
currentValue = fullText[--left].ToString();
currentValue = fullText[offset].ToString();
// searh right
while(!mySet.Contains(currentValue) && right < fullText.Length - 2)
currentValue = fullText[++right].ToString();
return fullText.Substring(left + 1, right - 1 - left).Trim();
}
}
}