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

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

@ -149,7 +149,7 @@ End Class
string program1 = @" string program1 = @"
Imports System Imports System
Imports System.Linq Imports System.Linq
| |
Class MainClass ' a comment Class MainClass ' a comment
Dim under_score_field As Integer Dim under_score_field As Integer
Sub SomeMethod() Sub SomeMethod()
@ -510,6 +510,86 @@ End Module", "<![CDATA[some text]]>", ExpressionContext.Default);
End Module", "5", 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 #region Old Tests
void OldTest(string expr, int offset) 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
if (ch == '"') if (ch == '"')
inString = !inString; 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); int eol = text.IndexOfAny(new[] { '\r', '\n' }, i);
if (eol > -1) { if (eol > -1) {

Loading…
Cancel
Save