Browse Source

fixed some bugs in VBNetExpressionFinder:

- _ at end of expression
- could not find expression in ExpressionRangeVariable without variable declaration
and added unit tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6405 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 15 years ago
parent
commit
930702e9af
  1. 14
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg
  2. 4581
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs
  3. 1
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame
  4. 82
      src/Main/Base/Test/VBExpressionFinderTests.cs
  5. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

14
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg

@ -576,9 +576,9 @@ SimpleExpressionWithSuffix = @@ -576,9 +576,9 @@ SimpleExpressionWithSuffix =
SimpleExpression =
(. PushContext(Context.Expression, la, t); .)
( Literal
| ( "(" Expression // HACK in ExpressionRangeVariable Identifier is consumed before start
// of Expression so this can be an argument list too
{ "," Expression } ")" )
| ( "(" (. activeArgument = 0; .) Expression // HACK in ExpressionRangeVariable Identifier is consumed before start
// of Expression so this can be an argument list too
{ "," (. activeArgument++; .) Expression } ")" )
| IdentifierForExpressionStart
| PrimitiveTypeName
| ( "." | "!" | ".@" | "..." ) (. nextTokenIsStartOfImportsOrAccessExpression = true; wasQualifierTokenAtStart = true; .) [ XmlOpenTag ] IdentifierOrKeyword [ XmlCloseTag ]
@ -777,10 +777,10 @@ ExpressionRangeVariable = @@ -777,10 +777,10 @@ ExpressionRangeVariable =
"Explicit", "Equals", "Distinct", "Descending", "Compare", "By",
"Binary", "Auto", "Assembly", "Ascending", "Ansi", "Aggregate", ident)
(
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier
// HACK: needs to be optional because Expression can start with Identifier too
[
"As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) "="
[ (. PopContext(); isAlreadyInExpr = true; .)
( "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) "="
| "="
| (.
currentState = endOfStatementTerminatorAndBlock; /* leave this block */
@ -790,10 +790,12 @@ ExpressionRangeVariable = @@ -790,10 +790,12 @@ ExpressionRangeVariable =
.)
ANY /* never reached due to goto above: */
/* this ANY is just so that Coco knows this branch isn't empty */
)
]
)
]
Expression
(. if (!isAlreadyInExpr) PopContext(); isAlreadyInExpr = false; .)
.
CollectionRangeVariable =

4581
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

1
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame

@ -40,6 +40,7 @@ partial class ExpressionFinder { @@ -40,6 +40,7 @@ partial class ExpressionFinder {
bool identifierExpected = false;
bool nextTokenIsStartOfImportsOrAccessExpression = false;
bool isMissingModifier = false;
bool isAlreadyInExpr = false;
int activeArgument = 0;
List<Token> errors = new List<Token>();

82
src/Main/Base/Test/VBExpressionFinderTests.cs

@ -149,7 +149,7 @@ End Class @@ -149,7 +149,7 @@ End Class
string program1 = @"
Imports System
Imports System.Linq
|
|
Class MainClass ' a comment
Dim under_score_field As Integer
Sub SomeMethod()
@ -510,6 +510,86 @@ End Module", "<![CDATA[some text]]>", ExpressionContext.Default); @@ -510,6 +510,86 @@ End Module", "<![CDATA[some text]]>", ExpressionContext.Default);
End Module", "5", ExpressionContext.Default);
}
[Test]
public void Linq1()
{
FindFull(@"Module Test
Sub Main()
Dim x = From kv|p As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "kvp", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValueP|air(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "KeyValuePair(Of String, DataGridViewCellStyle)", ExpressionContext.Type);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCac|he.CellStyleCache _
Select includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "styleCache", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellSty|leCache _
Select includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "styleCache.CellStyleCache", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select includ|eStyle(kvp.Key, kvp.Value)
End Sub
End Module", "includeStyle(kvp.Key, kvp.Value)", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select includeStyle(kv|p.Key, kvp.Value)
End Sub
End Module", "kvp", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select includeStyle(kvp.Key, kvp.Val|ue)
End Sub
End Module", "kvp.Value", ExpressionContext.Default);
}
[Test]
public void Linq2()
{
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select da|ta As DataGridViewCellStyle = includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "data", ExpressionContext.Default);
FindFull(@"Module Test
Sub Main()
Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) _
In styleCache.CellStyleCache _
Select data As DataG|ridViewCellStyle = includeStyle(kvp.Key, kvp.Value)
End Sub
End Module", "DataGridViewCellStyle", ExpressionContext.Type);
}
#region Old Tests
void OldTest(string expr, int offset)
{

6
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

@ -127,7 +127,11 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet @@ -127,7 +127,11 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
if (ch == '"')
inString = !inString;
if (ch == '\'' && !inString) {
bool isInWord = (i > 0 && char.IsLetterOrDigit(text[i - 1]))
|| (i + 1 < text.Length && char.IsLetterOrDigit(text[i + 1]));
if ((ch == '\'' || ch == '_') && !inString && !isInWord) {
int eol = text.IndexOfAny(new[] { '\r', '\n' }, i);
if (eol > -1) {

Loading…
Cancel
Save