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. 48
      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

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

@ -957,9 +957,10 @@ 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"
(. (.
Point startPos = t.Location; Point startPos = t.Location;
@ -1038,7 +1039,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(cd); compilationUnit.AddChild(cd);
.) .)
) )
| |
/* 9.2.1 */ /* 9.2.1 */
"Function" "Function"
(. (.
@ -1112,7 +1113,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
.) .)
EOL EOL
) )
| |
/* 9.2.2. */ /* 9.2.2. */
"Declare" "Declare"
(. (.
@ -1152,7 +1153,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(declareDeclaration); compilationUnit.AddChild(declareDeclaration);
.) .)
) )
| |
/* 9. 4 */ /* 9. 4 */
"Event" "Event"
(. (.
@ -1176,14 +1177,15 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(eventDeclaration); compilationUnit.AddChild(eventDeclaration);
.) .)
EOL EOL
| /* 9.6 */ | /* 9.6 */
(. Point startPos = t.Location; .) (. Point startPos = t.Location; .)
(. (.
m.Check(Modifier.Fields); m.Check(Modifier.Fields);
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
(. (.
@ -1210,7 +1212,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
fd.EndLocation = t.EndLocation; fd.EndLocation = t.EndLocation;
compilationUnit.AddChild(fd); compilationUnit.AddChild(fd);
.) .)
| /* 9.7 */ | /* 9.7 */
"Property" "Property"
(. (.
m.Check(Modifier.VBProperties); m.Check(Modifier.VBProperties);
@ -1261,7 +1263,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(pDecl); compilationUnit.AddChild(pDecl);
.) .)
) )
| |
"Custom" (. Point startPos = t.Location; .) "Event" "Custom" (. Point startPos = t.Location; .) "Event"
(. (.
m.Check(Modifier.VBCustomEvents); m.Check(Modifier.VBCustomEvents);
@ -1317,7 +1319,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
decl.RaiseRegion = raiseEventAccessorDeclaration; decl.RaiseRegion = raiseEventAccessorDeclaration;
compilationUnit.AddChild(decl); compilationUnit.AddChild(decl);
.) .)
| (. ConversionType opConversionType = ConversionType.None; .) | (. ConversionType opConversionType = ConversionType.None; .)
[ "Widening" (. opConversionType = ConversionType.Implicit; .) [ "Widening" (. opConversionType = ConversionType.Implicit; .)
| "Narrowing" (. opConversionType = ConversionType.Explicit;.) ] | "Narrowing" (. opConversionType = ConversionType.Explicit;.) ]
"Operator" "Operator"
@ -1363,7 +1365,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
operatorDeclaration.Body.EndLocation = t.Location; operatorDeclaration.Body.EndLocation = t.Location;
compilationUnit.AddChild(operatorDeclaration); compilationUnit.AddChild(operatorDeclaration);
.) .)
. .
OverloadableOperator<out OverloadableOperatorType operatorType> OverloadableOperator<out OverloadableOperatorType operatorType>
(. operatorType = OverloadableOperatorType.None; .) (. operatorType = OverloadableOperatorType.None; .)
@ -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,13 +2918,28 @@ Identifier =
| "Text" | "Text"
| "Binary" | "Binary"
| "Compare" | "Compare"
| "Custom"
| "Assembly" | "Assembly"
| "Ansi" | "Ansi"
| "Auto" | "Auto"
| "Preserve" | "Preserve"
| "Unicode" | "Unicode"
| "Until" | "Until"
. .
IdentifierForFieldDeclaration =
ident
| "Text"
| "Binary"
| "Compare"
/*| "Custom" Custom is not valid for field declaration */
| "Assembly"
| "Ansi"
| "Auto"
| "Preserve"
| "Unicode"
| "Until"
.
/* 2.2 */ /* 2.2 */

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