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. 1941
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 28
      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

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

File diff suppressed because it is too large Load Diff

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

@ -957,7 +957,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
Statement stmt = null; Statement stmt = null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>(); List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
List<TemplateDefinition> templates = new List<TemplateDefinition>(); List<TemplateDefinition> templates = new List<TemplateDefinition>();
.)= .)
=
NonModuleDeclaration<m, attributes> NonModuleDeclaration<m, attributes>
| /* 9.2.1 */ | /* 9.2.1 */
"Sub" "Sub"
@ -1183,7 +1184,8 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos); fd.StartLocation = m.GetDeclarationLocation(startPos);
.) .)
VariableDeclarator<variableDeclarators> IdentifierForFieldDeclaration (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<variableDeclarators, name>
{ "," VariableDeclarator<variableDeclarators> } { "," VariableDeclarator<variableDeclarators> }
EOL EOL
(. (.
@ -1536,13 +1538,18 @@ ConstantDeclarator<List<VariableDeclaration> constantDeclaration>
/* 9.6 */ /* 9.6 */
VariableDeclarator<List<VariableDeclaration> fieldDeclaration> VariableDeclarator<List<VariableDeclaration> fieldDeclaration>
=
Identifier (. string name = t.val; .)
VariableDeclaratorPartAfterIdentifier<fieldDeclaration, name>
.
VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration, string name>
(. (.
Expression expr = null; Expression expr = null;
TypeReference type = null; TypeReference type = null;
ArrayList rank = null; ArrayList rank = null;
List<Expression> dimension = null; List<Expression> dimension = null;
.) = .) =
Identifier (. string name = t.val; .)
[ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ] [ IF(IsSize() && !IsDims()) ArrayInitializationModifier<out dimension> ]
[ IF(IsDims()) ArrayNameModifier<out rank> ] [ IF(IsDims()) ArrayNameModifier<out rank> ]
( (
@ -2911,6 +2918,21 @@ Identifier =
| "Text" | "Text"
| "Binary" | "Binary"
| "Compare" | "Compare"
| "Custom"
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
.
IdentifierForFieldDeclaration =
ident
| "Text"
| "Binary"
| "Compare"
/*| "Custom" Custom is not valid for field declaration */
| "Assembly" | "Assembly"
| "Ansi" | "Ansi"
| "Auto" | "Auto"

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

@ -184,7 +184,8 @@ End Using");
public void SpecialIdentifiers() public void SpecialIdentifiers()
{ {
// Assembly, Ansi and Until are contextual keywords // 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] [Test]

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

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

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

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

Loading…
Cancel
Save