// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; namespace ICSharpCode.SharpDevelop.Dom { public interface IExpressionFinder { /// /// Finds an expression before the current offset. /// ExpressionResult FindExpression(string text, int offset); /// /// Finds an expression around the current offset. /// ExpressionResult FindFullExpression(string text, int offset); /// /// Removed the last part of the expression. /// /// /// "arr[i]" => "arr" /// "obj.Field" => "obj" /// "obj.Method(args,...)" => "obj.Method" /// string RemoveLastPart(string expression); } /// /// Structure containing the result of a call to an expression finder. /// public struct ExpressionResult { public static readonly ExpressionResult Empty = new ExpressionResult(null); /// The expression that has been found at the specified offset. public string Expression; /// The exact source code location of the expression. public DomRegion Region; /// Specifies the context in which the expression was found. public ExpressionContext Context; /// An object carrying additional language-dependend data. public object Tag; public ExpressionResult(string expression) : this(expression, DomRegion.Empty, ExpressionContext.Default, null) {} public ExpressionResult(string expression, ExpressionContext context) : this(expression, DomRegion.Empty, context, null) {} public ExpressionResult(string expression, DomRegion region, ExpressionContext context, object tag) { this.Expression = expression; this.Region = region; this.Context = context; this.Tag = tag; } public override string ToString() { if (Context == ExpressionContext.Default) return "<" + Expression + ">"; else return "<" + Expression + "> (" + Context.ToString() + ")"; } } }