Browse Source

Fixed parsing of the VB "Custom" keyword (it is valid variable identifier but not valid field identifier)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1486 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
80d967e240
  1. 1943
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 52
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 3
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  4. 5
      src/Libraries/NRefactory/Test/Parser/Expressions/IdentifierExpressionTests.cs
  5. 2
      src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs
  6. 3
      src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs

1943
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

52
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -957,9 +957,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -957,9 +957,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
Statement stmt = null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
List<TemplateDefinition> templates = new List<TemplateDefinition>();
.)=
.)
=
NonModuleDeclaration<m, attributes>
| /* 9.2.1 */
| /* 9.2.1 */
"Sub"
(.
Point startPos = t.Location;
@ -1038,7 +1039,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1038,7 +1039,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(cd);
.)
)
|
|
/* 9.2.1 */
"Function"
(.
@ -1112,7 +1113,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1112,7 +1113,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
EOL
)
|
|
/* 9.2.2. */
"Declare"
(.
@ -1152,7 +1153,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1152,7 +1153,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(declareDeclaration);
.)
)
|
|
/* 9. 4 */
"Event"
(.
@ -1176,14 +1177,15 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1176,14 +1177,15 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(eventDeclaration);
.)
EOL
| /* 9.6 */
| /* 9.6 */
(. Point startPos = t.Location; .)
(.
m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
VariableDeclarator<variableDeclarators>
IdentifierForFieldDeclaration (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<variableDeclarators, name>
{ "," VariableDeclarator<variableDeclarators> }
EOL
(.
@ -1210,7 +1212,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1210,7 +1212,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
fd.EndLocation = t.EndLocation;
compilationUnit.AddChild(fd);
.)
| /* 9.7 */
| /* 9.7 */
"Property"
(.
m.Check(Modifier.VBProperties);
@ -1261,7 +1263,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1261,7 +1263,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(pDecl);
.)
)
|
|
"Custom" (. Point startPos = t.Location; .) "Event"
(.
m.Check(Modifier.VBCustomEvents);
@ -1317,9 +1319,9 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1317,9 +1319,9 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
decl.RaiseRegion = raiseEventAccessorDeclaration;
compilationUnit.AddChild(decl);
.)
| (. ConversionType opConversionType = ConversionType.None; .)
[ "Widening" (. opConversionType = ConversionType.Implicit; .)
| "Narrowing" (. opConversionType = ConversionType.Explicit;.) ]
| (. ConversionType opConversionType = ConversionType.None; .)
[ "Widening" (. opConversionType = ConversionType.Implicit; .)
| "Narrowing" (. opConversionType = ConversionType.Explicit;.) ]
"Operator"
(.
m.Check(Modifier.VBOperators);
@ -1363,7 +1365,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1363,7 +1365,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
operatorDeclaration.Body.EndLocation = t.Location;
compilationUnit.AddChild(operatorDeclaration);
.)
.
.
OverloadableOperator<out OverloadableOperatorType operatorType>
(. operatorType = OverloadableOperatorType.None; .)
@ -1536,13 +1538,18 @@ ConstantDeclarator<List<VariableDeclaration> constantDeclaration> @@ -1536,13 +1538,18 @@ ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
/* 9.6 */
VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
=
Identifier (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<fieldDeclaration, name>
.
VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration, string name>
(.
Expression expr = null;
TypeReference type = null;
ArrayList rank = null;
List<Expression> dimension = null;
.) =
Identifier (. string name = t.val; .)
[ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
[ IF(IsDims()) ArrayNameModifier<out rank> ]
(
@ -2911,13 +2918,28 @@ Identifier = @@ -2911,13 +2918,28 @@ Identifier =
| "Text"
| "Binary"
| "Compare"
| "Custom"
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
.
.
IdentifierForFieldDeclaration =
ident
| "Text"
| "Binary"
| "Compare"
/*| "Custom" Custom is not valid for field declaration */
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
.
/* 2.2 */

3
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -184,7 +184,8 @@ End Using"); @@ -184,7 +184,8 @@ End Using");
public void SpecialIdentifiers()
{
// Assembly, Ansi and Until are contextual keywords
TestExpression("Assembly = Ansi * [For] + Until");
// Custom is valid inside methods, but not valid for field names
TestExpression("Assembly = Ansi * [For] + Until - [Custom]");
}
[Test]

5
src/Libraries/NRefactory/Test/Parser/Expressions/IdentifierExpressionTests.cs

@ -50,10 +50,9 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -50,10 +50,9 @@ namespace ICSharpCode.NRefactory.Tests.AST
[Test]
public void VBNetAssemblyIdentifierExpressionTest()
{
IdentifierExpression ie = ParseUtilVBNet.ParseExpression<IdentifierExpression>("Assembly");
Assert.AreEqual("Assembly", ie.Identifier);
Assert.AreEqual("Assembly", ParseUtilVBNet.ParseExpression<IdentifierExpression>("Assembly").Identifier);
Assert.AreEqual("Custom", ParseUtilVBNet.ParseExpression<IdentifierExpression>("Custom").Identifier);
}
#endregion
}
}

2
src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -36,7 +36,7 @@ namespace ICSharpCode.SharpDevelop.Commands
p.Parse();
if (p.Errors.count > 0) {
MessageService.ShowError("Correct source code errors first (only correct source code would convert).");
MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
return;
}
ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor output = new ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor();

3
src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs

@ -36,8 +36,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -36,8 +36,7 @@ namespace ICSharpCode.SharpDevelop.Commands
ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(((IEditable)window.ViewContent).Text));
p.Parse();
if (p.Errors.count > 0) {
MessageService.ShowError("Correct source code errors first (only correct source code would convert).");
MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
return;
}

Loading…
Cancel
Save