Browse Source

fixed VBExpressionFinder bug with VB Lambdas (it did not find a valid expression)

4.0
Siegfried Pammer 15 years ago
parent
commit
f447cb6918
  1. 1
      src/Libraries/NRefactory/Project/NRefactory.csproj
  2. 22
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg
  3. 16
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs
  4. 4162
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs
  5. 30
      src/Main/Base/Test/VBExpressionFinderTests.cs

1
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -155,6 +155,7 @@ @@ -155,6 +155,7 @@
<None Include="Src\Lexer\VBNet\ExpressionFinder.atg">
<Generator>CocoParserGenerator</Generator>
<CustomToolNamespace>ICSharpCode.NRefactory.Parser.VB</CustomToolNamespace>
<LastGenOutput>Parser.cs</LastGenOutput>
</None>
<None Include="Src\Lexer\VBNet\PushParser.frame">
<DependentUpon>ExpressionFinder.atg</DependentUpon>

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

@ -367,13 +367,13 @@ TypeOrMemberModifier = @@ -367,13 +367,13 @@ TypeOrMemberModifier =
InterfaceEvent =
"Event" (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
[ "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) | "(" [ ParameterList ] ")" ]
[ "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) | ParameterListInParenthesis ]
StatementTerminator
.
InterfaceProperty =
"Property" (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
[ "(" [ ParameterList ] ")" ] [ "As" (. PushContext(Context.Type, la, t); .) { AttributeBlock } TypeName (. PopContext(); .) ]
[ ParameterListInParenthesis ] [ "As" (. PushContext(Context.Type, la, t); .) { AttributeBlock } TypeName (. PopContext(); .) ]
StatementTerminator
.
@ -435,7 +435,7 @@ ExternalMemberDeclaration = @@ -435,7 +435,7 @@ ExternalMemberDeclaration =
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
"Lib" LiteralString
[ "Alias" LiteralString ]
[ "(" [ ParameterList ] ")" ]
[ ParameterListInParenthesis ]
[ "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) ]
StatementTerminator
.
@ -443,7 +443,7 @@ ExternalMemberDeclaration = @@ -443,7 +443,7 @@ ExternalMemberDeclaration =
EventMemberDeclaration =
"Event"
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
( "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) | [ "(" [ ParameterList ] ")" ] )
( "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) | [ ParameterListInParenthesis ] )
[ "Implements" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) /*"." IdentifierOrKeyword*/
{ "," (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) /*"." IdentifierOrKeyword*/ } ]
/* the TypeName production already allows the "." IdentifierOrKeyword syntax, so to avoid an ambiguous grammar we just leave that out */
@ -463,7 +463,7 @@ CustomEventMemberDeclaration = @@ -463,7 +463,7 @@ CustomEventMemberDeclaration =
PropertyDeclaration =
"Property"
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
[ "(" [ ParameterList ] ")" ]
[ ParameterListInParenthesis ]
[ "As" (. PushContext(Context.Type, la, t); .) { AttributeBlock } ( NewExpression | TypeName ) (. PopContext(); .) ]
[ "Implements" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) /*"." IdentifierOrKeyword*/
{ "," (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) /*"." IdentifierOrKeyword*/ } ]
@ -474,10 +474,10 @@ PropertyDeclaration = @@ -474,10 +474,10 @@ PropertyDeclaration =
// so we need to simulate it
(.OnEachPossiblePath: SetIdentifierExpected(la); .) }
[ (. PushContext(Context.Member, la, t); .)
( "Get" | "Set" ) [ "(" [ ParameterList ] ")" ]
( "Get" | "Set" ) [ ParameterListInParenthesis ]
StatementTerminatorAndBlock
"End" ( "Get" | "Set" ) StatementTerminator
[ { AttributeBlock } { AccessModifier } ( "Get" | "Set" ) [ "(" [ ParameterList ] ")" ]
[ { AttributeBlock } { AccessModifier } ( "Get" | "Set" ) [ ParameterListInParenthesis ]
StatementTerminatorAndBlock
"End" ( "Get" | "Set" ) StatementTerminator ]
@ -686,15 +686,19 @@ LambdaExpression = @@ -686,15 +686,19 @@ LambdaExpression =
.
SubLambdaExpression =
"Sub" "(" [ ParameterList ] ")"
"Sub" ParameterListInParenthesis
( GREEDY Statement | StatementTerminatorAndBlock "End" "Sub" )
.
FunctionLambdaExpression =
"Function" "(" [ ParameterList ] ")"
"Function" ParameterListInParenthesis
( GREEDY Expression | [ "As" (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) ] StatementTerminatorAndBlock "End" "Function" )
.
ParameterListInParenthesis =
"(" (. PushContext(Context.Default, la, t); .) [ ParameterList ] (. PopContext(); .) ")"
.
QueryExpression
(. PushContext(Context.Query, la, t); .)
=

16
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs

@ -25,14 +25,14 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -25,14 +25,14 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
}
void PushContext(Context context, Token la, Token t)
{
string indent = new string('\t', stack.Count);
Location l = la == null ? (t == null ? Location.Empty : t.EndLocation) : la.Location;
stack.Push(new Block() { context = context, lastExpressionStart = l });
Print(indent + "enter " + context);
}
void PushContext(Context context, Token la, Token t)
{
string indent = new string('\t', stack.Count);
Location l = la == null ? (t == null ? Location.Empty : t.EndLocation) : la.Location;
stack.Push(new Block() { context = context, lastExpressionStart = l });
Print(indent + "enter " + context);
}
public ExpressionFinder(ExpressionFinderState state)
{

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

File diff suppressed because it is too large Load Diff

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

@ -635,6 +635,36 @@ End Module", "FileReader()", ExpressionContext.ObjectCreation); @@ -635,6 +635,36 @@ End Module", "FileReader()", ExpressionContext.ObjectCreation);
End Module", "FileReader()", ExpressionContext.Default);
}
[Test]
public void FunctionLambda()
{
FindFull(@"Module Test
Sub Main()
Dim f = Fun|ction(x, y) x + y
End Sub
End Module", "Function(x, y) x + y", ExpressionContext.Default);
}
[Test]
public void SubLambda()
{
FindFull(@"Module Test
Sub Main()
Dim f = Su|b(x, y) Console.WriteLine(x + y)
End Sub
End Module", "Sub(x, y) Console.WriteLine(x + y)", ExpressionContext.Default);
}
[Test]
public void NewExpression()
{
FindFull(@"Module Test
Sub Main()
Dim list = N|ew List(Of Integer)
End Sub
End Module", "New List(Of Integer)", ExpressionContext.Default);
}
#region Old Tests
void OldTest(string expr, int offset)
{

Loading…
Cancel
Save