Browse Source

Fix #3038: Fall back to string search if search term is not a single token.

pull/3058/head
Daniel Grunwald 2 years ago
parent
commit
911abd242d
  1. 34
      ICSharpCode.ILSpyX/Search/CSharpLexer.cs
  2. 8
      ICSharpCode.ILSpyX/Search/LiteralSearchStrategy.cs

34
ICSharpCode.ILSpyX/Search/CSharpLexer.cs

@ -70,6 +70,14 @@ namespace ICSharpCode.ILSpyX.Search
} }
} }
enum TokenKind : byte
{
EOF,
Literal,
Identifier,
Symbol,
}
enum LiteralFormat : byte enum LiteralFormat : byte
{ {
None, None,
@ -83,11 +91,16 @@ namespace ICSharpCode.ILSpyX.Search
class Literal class Literal
{ {
internal readonly TokenKind tokenKind;
internal readonly LiteralFormat literalFormat; internal readonly LiteralFormat literalFormat;
internal readonly object literalValue; internal readonly object literalValue;
internal readonly string val; internal readonly string val;
internal Literal next; internal Literal next;
public TokenKind TokenKind {
get { return tokenKind; }
}
public LiteralFormat LiteralFormat { public LiteralFormat LiteralFormat {
get { return literalFormat; } get { return literalFormat; }
} }
@ -100,11 +113,18 @@ namespace ICSharpCode.ILSpyX.Search
get { return val; } get { return val; }
} }
public Literal(string val, TokenKind tokenKind)
{
this.val = val;
this.tokenKind = tokenKind;
}
public Literal(string val, object literalValue, LiteralFormat literalFormat) public Literal(string val, object literalValue, LiteralFormat literalFormat)
{ {
this.val = val; this.val = val;
this.literalValue = literalValue; this.literalValue = literalValue;
this.literalFormat = literalFormat; this.literalFormat = literalFormat;
this.tokenKind = TokenKind.Literal;
} }
} }
@ -432,9 +452,8 @@ namespace ICSharpCode.ILSpyX.Search
} }
else if (Char.IsLetterOrDigit(ch) || ch == '_') else if (Char.IsLetterOrDigit(ch) || ch == '_')
{ {
bool canBeKeyword; string s = ReadIdent(ch, out _);
string s = ReadIdent(ch, out canBeKeyword); return new Literal(s, TokenKind.Identifier);
return new Literal(null, null, LiteralFormat.None);
} }
else else
{ {
@ -450,9 +469,8 @@ namespace ICSharpCode.ILSpyX.Search
{ {
int x = Col - 1; // Col was incremented above, but we want the start of the identifier int x = Col - 1; // Col was incremented above, but we want the start of the identifier
int y = Line; int y = Line;
bool canBeKeyword; string s = ReadIdent(ch, out _);
string s = ReadIdent(ch, out canBeKeyword); return new Literal(s, TokenKind.Identifier);
return new Literal(null, null, LiteralFormat.None);
} }
else if (Char.IsDigit(ch)) else if (Char.IsDigit(ch))
{ {
@ -468,7 +486,7 @@ namespace ICSharpCode.ILSpyX.Search
} }
} }
return new Literal(null, null, LiteralFormat.None); return new Literal(null, TokenKind.EOF);
} }
// The C# compiler has a fixed size length therefore we'll use a fixed size char array for identifiers // The C# compiler has a fixed size length therefore we'll use a fixed size char array for identifiers
@ -607,7 +625,7 @@ namespace ICSharpCode.ILSpyX.Search
peek = (char)ReaderPeek(); peek = (char)ReaderPeek();
if (!Char.IsDigit(peek)) if (!Char.IsDigit(peek))
{ {
nextToken = new Literal(null, null, LiteralFormat.None); nextToken = new Literal(".", TokenKind.Symbol);
peek = '.'; peek = '.';
} }
else else

8
ICSharpCode.ILSpyX/Search/LiteralSearchStrategy.cs

@ -48,8 +48,9 @@ namespace ICSharpCode.ILSpyX.Search
{ {
var lexer = new Lexer(new LATextReader(new System.IO.StringReader(terms[0]))); var lexer = new Lexer(new LATextReader(new System.IO.StringReader(terms[0])));
var value = lexer.NextToken(); var value = lexer.NextToken();
var following = lexer.NextToken();
if (value != null && value.LiteralValue != null) if (value != null && value.LiteralValue != null && following != null && following.TokenKind == TokenKind.EOF)
{ {
TypeCode valueType = Type.GetTypeCode(value.LiteralValue.GetType()); TypeCode valueType = Type.GetTypeCode(value.LiteralValue.GetType());
switch (valueType) switch (valueType)
@ -73,6 +74,11 @@ namespace ICSharpCode.ILSpyX.Search
break; break;
} }
} }
else
{
searchTermLiteralType = TypeCode.String;
searchTermLiteralValue = terms[0];
}
} }
} }

Loading…
Cancel
Save