Browse Source

Partially implemented Imports for XML Namespaces. See remarks in VBNET.ATG for details.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@5826 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
96488a9045
  1. 9
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs
  2. 47
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  3. 2824
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  4. 26
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  5. 42
      src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs

9
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs

@ -65,21 +65,28 @@ namespace NRefactoryASTGenerator.Ast @@ -65,21 +65,28 @@ namespace NRefactoryASTGenerator.Ast
}
[IncludeBoolProperty("IsAlias", "return !alias.IsNull;")]
[IncludeBoolProperty("IsXml", "return xmlPrefix != null;")]
class Using : AbstractNode
{
[QuestionMarkDefault]
string name;
TypeReference alias;
string xmlPrefix;
public Using(string name) {}
public Using(string name, TypeReference alias) {}
public Using(string name, string xmlPrefix) {}
}
[IncludeMember("public UsingDeclaration(string @namespace) : this(@namespace, null) {}")]
[IncludeMember("public UsingDeclaration(string @namespace) : this(@namespace, TypeReference.Null) {}")]
[IncludeMember("public UsingDeclaration(string @namespace, TypeReference alias) {" +
" usings = new List<Using>(1);" +
" usings.Add(new Using(@namespace, alias)); " +
"}")]
[IncludeMember("public UsingDeclaration(string xmlNamespace, string prefix) {" +
" usings = new List<Using>(1);" +
" usings.Add(new Using(xmlNamespace, prefix)); " +
"}")]
class UsingDeclaration : AbstractNode
{
List<Using> usings;

47
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -1665,15 +1665,15 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1665,15 +1665,15 @@ namespace ICSharpCode.NRefactory.Ast {
initializer = Expression.Null;
}
public bool HasAddRegion {
public bool HasRemoveRegion {
get {
return !addRegion.IsNull;
return !removeRegion.IsNull;
}
}
public bool HasRemoveRegion {
public bool HasAddRegion {
get {
return !removeRegion.IsNull;
return !addRegion.IsNull;
}
}
@ -3403,15 +3403,15 @@ public Location ExtendedEndLocation { get; set; } @@ -3403,15 +3403,15 @@ public Location ExtendedEndLocation { get; set; }
initializer = Expression.Null;
}
public bool HasGetRegion {
public bool HasSetRegion {
get {
return !getRegion.IsNull;
return !setRegion.IsNull;
}
}
public bool HasSetRegion {
public bool HasGetRegion {
get {
return !setRegion.IsNull;
return !getRegion.IsNull;
}
}
@ -5195,6 +5195,8 @@ public Location ExtendedEndLocation { get; set; } @@ -5195,6 +5195,8 @@ public Location ExtendedEndLocation { get; set; }
TypeReference alias;
string xmlPrefix;
public string Name {
get {
return name;
@ -5214,14 +5216,31 @@ public Location ExtendedEndLocation { get; set; } @@ -5214,14 +5216,31 @@ public Location ExtendedEndLocation { get; set; }
}
}
public string XmlPrefix {
get {
return xmlPrefix;
}
set {
xmlPrefix = value ?? "";
}
}
public Using(string name) {
Name = name;
alias = TypeReference.Null;
xmlPrefix = "";
}
public Using(string name, TypeReference alias) {
Name = name;
Alias = alias;
xmlPrefix = "";
}
public Using(string name, string xmlPrefix) {
Name = name;
XmlPrefix = xmlPrefix;
alias = TypeReference.Null;
}
public bool IsAlias {
@ -5230,12 +5249,18 @@ public Location ExtendedEndLocation { get; set; } @@ -5230,12 +5249,18 @@ public Location ExtendedEndLocation { get; set; }
}
}
public bool IsXml {
get {
return xmlPrefix != null;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitUsing(this, data);
}
public override string ToString() {
return string.Format("[Using Name={0} Alias={1}]", Name, Alias);
return string.Format("[Using Name={0} Alias={1} XmlPrefix={2}]", Name, Alias, XmlPrefix);
}
}
@ -5256,10 +5281,12 @@ public Location ExtendedEndLocation { get; set; } @@ -5256,10 +5281,12 @@ public Location ExtendedEndLocation { get; set; }
Usings = usings;
}
public UsingDeclaration(string @namespace) : this(@namespace, null) {}
public UsingDeclaration(string @namespace) : this(@namespace, TypeReference.Null) {}
public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List<Using>(1); usings.Add(new Using(@namespace, alias)); }
public UsingDeclaration(string xmlNamespace, string prefix) { usings = new List<Using>(1); usings.Add(new Using(xmlNamespace, prefix)); }
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitUsingDeclaration(this, data);
}

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

File diff suppressed because it is too large Load Diff

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

@ -322,17 +322,21 @@ ImportClause<out Using u> @@ -322,17 +322,21 @@ ImportClause<out Using u>
TypeReference aliasedType = null;
u = null;
.) =
Qualident<out qualident>
[ "=" TypeName<out aliasedType> ]
(.
if (qualident != null && qualident.Length > 0) {
if (aliasedType != null) {
u = new Using(qualident, aliasedType);
} else {
u = new Using(qualident);
(
Qualident<out qualident>
[ "=" TypeName<out aliasedType> ]
(.
if (qualident != null && qualident.Length > 0) {
if (aliasedType != null) {
u = new Using(qualident, aliasedType);
} else {
u = new Using(qualident);
}
}
}
.)
.)
) | ( (. string prefix = null; .)
"<" Identifier /* TODO this is "xmlns" */ [ ":" Identifier (. prefix = t.val; .) ] "=" LiteralString /* TODO support single-quote xml strings */ (. u = new Using(t.literalValue as string, prefix); .) ">"
)
.
/* 6.4.2 */
@ -1902,7 +1906,7 @@ AdditiveExpr<out Expression outExpr> @@ -1902,7 +1906,7 @@ AdditiveExpr<out Expression outExpr>
ModuloExpr<out Expression outExpr>
(. Expression expr; .)
=
=
IntegerDivisionExpr<out outExpr> { "Mod" IntegerDivisionExpr<out expr> (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr); .) }
.

42
src/Libraries/NRefactory/Test/Parser/GlobalScope/UsingDeclarationTests.cs

@ -158,6 +158,48 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -158,6 +158,48 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("", parser.Errors.ErrorOutput);
// TODO : Extend test ...
}
[Test]
public void VBNetXmlNamespaceUsingTest()
{
string program = "Imports <xmlns=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CompilationUnit unit = parser.CompilationUnit;
Assert.AreEqual(1, unit.Children.Count);
Assert.IsTrue(unit.Children[0] is UsingDeclaration);
UsingDeclaration ud = (UsingDeclaration)unit.Children[0];
Assert.AreEqual(1, ud.Usings.Count);
Assert.IsFalse(ud.Usings[0].IsAlias);
Assert.IsTrue(ud.Usings[0].IsXml);
Assert.AreEqual("", ud.Usings[0].XmlPrefix);
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name);
}
[Test]
public void VBNetXmlNamespaceWithPrefixUsingTest()
{
string program = "Imports <xmlns:avalonedit=\"http://icsharpcode.net/sharpdevelop/avalonedit\">";
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CompilationUnit unit = parser.CompilationUnit;
Assert.AreEqual(1, unit.Children.Count);
Assert.IsTrue(unit.Children[0] is UsingDeclaration);
UsingDeclaration ud = (UsingDeclaration)unit.Children[0];
Assert.AreEqual(1, ud.Usings.Count);
Assert.IsFalse(ud.Usings[0].IsAlias);
Assert.IsTrue(ud.Usings[0].IsXml);
Assert.AreEqual("avalonedit", ud.Usings[0].XmlPrefix);
Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name);
}
#endregion
}
}

Loading…
Cancel
Save