Browse Source

NRefactory C# parser: fixed parse error for unknown attribute targets - the C# compiler only emits a warning for those

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5003 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
93c1198fd4
  1. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  2. 2245
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  3. 7
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  4. 22
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs

@ -503,9 +503,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -503,9 +503,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
string val = la.val;
return (cur == Tokens.Event || cur == Tokens.Return ||
(Tokens.IdentifierTokens[cur] &&
(val == "field" || val == "method" || val == "module" ||
val == "param" || val == "property" || val == "type"))) &&
Tokens.IdentifierTokens[cur]) &&
Peek(1).kind == Tokens.Colon;
}

2245
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

7
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -297,12 +297,7 @@ AttributeSection<out AttributeSection section> @@ -297,12 +297,7 @@ AttributeSection<out AttributeSection section>
[ IF (IsLocalAttrTarget())
( "event" (. attributeTarget = "event";.)
| "return" (. attributeTarget = "return";.)
| Identifier (. if (t.val != "field" && t.val != "method" &&
t.val != "param" &&
t.val != "property" && t.val != "type")
Error("attribute target specifier (field, event, method, param, property, return or type) expected");
attributeTarget = t.val;
.)
| Identifier (. attributeTarget = t.val; .)
) ":"
]
/*--- attribute list: */

22
src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

@ -179,6 +179,28 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -179,6 +179,28 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(ClassType.Enum, td.Type);
Assert.AreEqual("MyEnum", td.Name);
}
[Test]
public void ContextSensitiveKeywordTest()
{
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class partial<[partial: where] where> where where : partial<where> { }");
Assert.AreEqual(Modifiers.Partial, td.Modifier);
Assert.AreEqual("partial", td.Name);
Assert.AreEqual(1, td.Templates.Count);
TemplateDefinition tp = td.Templates[0];
Assert.AreEqual("where", tp.Name);
Assert.AreEqual(1, tp.Attributes.Count);
Assert.AreEqual("partial", tp.Attributes[0].AttributeTarget);
Assert.AreEqual(1, tp.Attributes[0].Attributes.Count);
Assert.AreEqual("where", tp.Attributes[0].Attributes[0].Name);
Assert.AreEqual(1, tp.Bases.Count);
Assert.AreEqual("partial", tp.Bases[0].Type);
Assert.AreEqual("where", tp.Bases[0].GenericTypes[0].Type);
}
#endregion
#region VB.NET

Loading…
Cancel
Save