From 13a8348d4ab517a83ac1648f4ae0e2ce3381e00c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 Apr 2011 10:17:30 +0200 Subject: [PATCH] add XmlLiteralString --- ICSharpCode.NRefactory.VB/Ast/AstNode.cs | 16 ++ .../Ast/Expressions/XmlIdentifier.cs | 11 +- .../Ast/Expressions/XmlLiteralString.cs | 69 +++++++ .../Ast/GlobalScope/ImportsClause.cs | 12 +- ICSharpCode.NRefactory.VB/IAstVisitor.cs | 1 + .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 5 + ICSharpCode.NRefactory.VB/Parser/vb.atg | 169 ++++++++++++++++-- 8 files changed, 259 insertions(+), 25 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 21c9b96837..8adca8fe18 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -602,6 +602,11 @@ namespace ICSharpCode.NRefactory.VB return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase); } + protected static bool MatchStringXml(string name1, string name2) + { + return string.IsNullOrEmpty(name1) || string.Equals(name1, name2, StringComparison.Ordinal); + } + protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match); bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match) @@ -669,6 +674,7 @@ namespace ICSharpCode.NRefactory.VB // some pre defined constants for common roles public static readonly Role Identifier = new Role("Identifier", Ast.Identifier.Null); public static readonly Role XmlIdentifier = new Role("XmlIdentifier", Ast.XmlIdentifier.Null); + public static readonly Role XmlLiteralString = new Role("XmlLiteralString", Ast.XmlLiteralString.Null); // public static readonly Role Body = new Role("Body", CSharp.BlockStatement.Null); // public static readonly Role Parameter = new Role("Parameter"); @@ -703,6 +709,16 @@ namespace ICSharpCode.NRefactory.VB public static readonly Role Colon = new Role("Colon", VBTokenNode.Null); public static readonly Role StatementTerminator = new Role("StatementTerminator", VBTokenNode.Null); + // XML + /// + /// Text: < + /// + public static readonly Role XmlOpenTag = new Role("XmlOpenTag", VBTokenNode.Null); + /// + /// Text: > + /// + public static readonly Role XmlCloseTag = new Role("XmlOpenTag", VBTokenNode.Null); + public static readonly Role Comment = new Role("Comment"); } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs index 84816ed853..7d3a6ca0b9 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs @@ -38,8 +38,9 @@ namespace ICSharpCode.NRefactory.VB.Ast get { return startLocation; } } + AstLocation endLocation; public override AstLocation EndLocation { - get { return new AstLocation(startLocation.Line, startLocation.Column + Name.Length); } + get { return endLocation; } } private XmlIdentifier() @@ -47,18 +48,20 @@ namespace ICSharpCode.NRefactory.VB.Ast this.Name = string.Empty; } - public XmlIdentifier(string name, AstLocation startLocation) + public XmlIdentifier(string name, AstLocation startLocation, AstLocation endLocation) { this.Name = name; this.startLocation = startLocation; + this.endLocation = endLocation; } protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var ident = other as XmlIdentifier; return ident != null - && MatchString(Name, ident.Name) - && ident.startLocation == startLocation; + && MatchStringXml(Name, ident.Name) + && ident.startLocation == startLocation + && ident.endLocation == endLocation; } public override S AcceptVisitor(IAstVisitor visitor, T data) diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs new file mode 100644 index 0000000000..3195bcd69a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs @@ -0,0 +1,69 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.NRefactory.VB.Ast +{ + public class XmlLiteralString : AstNode + { + public static readonly new XmlLiteralString Null = new XmlLiteralString(); + + class NullXmlLiteralString : XmlLiteralString + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default(S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + + public string Value { get; set; } + + AstLocation startLocation; + public override AstLocation StartLocation { + get { return startLocation; } + } + + AstLocation endLocation; + public override AstLocation EndLocation { + get { return endLocation; } + } + + private XmlLiteralString() + { + this.Value = string.Empty; + } + + public XmlLiteralString(string value, AstLocation startLocation, AstLocation endLocation) + { + this.Value = value; + this.startLocation = startLocation; + this.endLocation = endLocation; + } + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + var ident = other as XmlLiteralString; + return ident != null + && MatchStringXml(Value, ident.Value) + && ident.startLocation == startLocation + && ident.endLocation == endLocation; + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitXmlLiteralString(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs index 3eaaeefc5e..15730eab03 100644 --- a/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs +++ b/ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs @@ -89,17 +89,15 @@ namespace ICSharpCode.NRefactory.VB.Ast set { SetChildByRole(Roles.XmlIdentifier, value); } } - string xmlNamespace; - - public string XmlNamespace { - get { return xmlNamespace; } - set { xmlNamespace = value ?? ""; } + public XmlLiteralString Namespace { + get { return GetChildByRole(Roles.XmlLiteralString); } + set { SetChildByRole(Roles.XmlLiteralString, value); } } protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var clause = other as XmlNamespaceImportsClause; - return clause != null && clause.xmlNamespace == xmlNamespace && Prefix.DoMatch(clause.Prefix, match); + return clause != null && Namespace.DoMatch(clause.Namespace, match) && Prefix.DoMatch(clause.Prefix, match); } public override S AcceptVisitor(IAstVisitor visitor, T data) @@ -109,7 +107,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public override string ToString() { - return string.Format("[XmlNamespaceImportsClause Prefix={0}, XmlNamespace={1}]", Prefix, xmlNamespace); + return string.Format("[XmlNamespaceImportsClause Prefix={0}, Namespace={1}]", Prefix, Namespace); } } } diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 560db9f8ff..b2058e02b1 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.VB { // Expression scope S VisitIdentifier(Identifier identifier, T data); S VisitXmlIdentifier(XmlIdentifier xmlIdentifier, T data); + S VisitXmlLiteralString(XmlLiteralString xmlLiteralString, T data); S VisitSimpleNameExpression(SimpleNameExpression identifierExpression, T data); S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 6e4b2eae6d..5ad3bb9758 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -51,6 +51,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 32e306d46b..34bfb7c6dc 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -169,5 +169,10 @@ namespace ICSharpCode.NRefactory.VB { throw new NotImplementedException(); } + + public object VisitXmlLiteralString(ICSharpCode.NRefactory.VB.Ast.XmlLiteralString xmlLiteralString, object data) + { + throw new NotImplementedException(); + } } } diff --git a/ICSharpCode.NRefactory.VB/Parser/vb.atg b/ICSharpCode.NRefactory.VB/Parser/vb.atg index 377d8f43ba..d4a51d1323 100644 --- a/ICSharpCode.NRefactory.VB/Parser/vb.atg +++ b/ICSharpCode.NRefactory.VB/Parser/vb.atg @@ -11,7 +11,7 @@ using Roles = ICSharpCode.NRefactory.VB.AstNode.Roles; COMPILER VB -/* START AUTOGENERATED TOKENS SECTION */ +#region AUTOGENERATED TOKENS SECTION TOKENS /* ----- terminal classes ----- */ /* EOF is 0 */ @@ -24,16 +24,16 @@ TOKENS LiteralSingle LiteralDecimal LiteralDate - XmlOpenTag - XmlCloseTag - XmlStartInlineVB - XmlEndInlineVB - XmlCloseTagEmptyElement - XmlOpenEndTag - XmlContent - XmlComment - XmlCData - XmlProcessingInstruction + XmlOpenTag // < + XmlCloseTag // > + XmlStartInlineVB // <%= + XmlEndInlineVB // %> + XmlCloseTagEmptyElement // /> + XmlOpenEndTag // + XmlCData // + XmlProcessingInstruction /* ----- special character ----- */ "=" @@ -256,7 +256,7 @@ TOKENS "WriteOnly" "Xor" "GetXmlNamespace" -/* END AUTOGENERATED TOKENS SECTION */ +#endregion PRODUCTIONS @@ -269,14 +269,129 @@ VB = Get(); .) { StatementTerminator } - { OptionStatement { StatementTerminator } } -/* { ImportsStmt { StatementTerminator } } + { OptionStatement { StatementTerminator } } +/* { ImportsStatement { StatementTerminator } } { IF (IsGlobalAttrTarget()) GlobalAttributeSection { StatementTerminator } } { NamespaceMemberDecl { StatementTerminator } } */ . StatementTerminator = SYNC ( EOL | ":" ) . +/* IdentifierOrKeyword = ANY (. identifier = t.val; .) . + +// This production handles pseudo keywords that are needed in the grammar +Identifier = + IdentifierForFieldDeclaration + | "Custom" +. + +IdentifierForFieldDeclaration = + ident + | "Aggregate" + | "Ansi" + | "Ascending" + | "Assembly" + | "Auto" + | "Binary" + | "By" + | "Compare" + | "Descending" + | "Distinct" + | "Equals" + | "Explicit" + | "From" + | "Group" + | "Infer" + | "Into" + | "Join" + | "Key" + | "Off" + | "Order" + | "Out" + | "Preserve" + | "Skip" + | "Take" + | "Text" + | "Unicode" + | "Until" + | "Where" +. + +TypeName = + (. type = null; .) +. + +PrimitiveTypeName + (. type = String.Empty; .) = + "Boolean" (. type = "System.Boolean"; .) + | "Date" (. type = "System.DateTime"; .) + | "Char" (. type = "System.Char"; .) + | "String" (. type = "System.String"; .) + | "Decimal" (. type = "System.Decimal"; .) + | "Byte" (. type = "System.Byte"; .) + | "Short" (. type = "System.Int16"; .) + | "Integer" (. type = "System.Int32"; .) + | "Long" (. type = "System.Int64"; .) + | "Single" (. type = "System.Single"; .) + | "Double" (. type = "System.Double"; .) + | "UInteger" (. type = "System.UInt32"; .) + | "ULong" (. type = "System.UInt64"; .) + | "UShort" (. type = "System.UInt16"; .) + | "SByte" (. type = "System.SByte"; .) + . + +ParameterModifier = + "ByVal" (. m.Add(ParameterModifiers.In); .) + | "ByRef" (. m.Add(ParameterModifiers.Ref); .) + | "Optional" (. m.Add(ParameterModifiers.Optional); .) + | "ParamArray" (. m.Add(ParameterModifiers.Params); .) +. + +TypeModifier = + "Public" (. m.Add(Modifiers.Public, t.Location); .) + | "Protected" (. m.Add(Modifiers.Protected, t.Location); .) + | "Friend" (. m.Add(Modifiers.Internal, t.Location); .) + | "Private" (. m.Add(Modifiers.Private, t.Location); .) + | "Shared" (. m.Add(Modifiers.Static, t.Location); .) + | "Shadows" (. m.Add(Modifiers.New, t.Location); .) + | "MustInherit" (. m.Add(Modifiers.Abstract, t.Location); .) + | "NotInheritable" (. m.Add(Modifiers.Sealed, t.Location); .) + | "Partial" (. m.Add(Modifiers.Partial, t.Location); .) +. + +MemberModifier = + "MustInherit" (.m.Add(Modifiers.Abstract, t.Location);.) + | "Default" (.m.Add(Modifiers.Default, t.Location);.) + | "Friend" (.m.Add(Modifiers.Internal, t.Location);.) + | "Shadows" (.m.Add(Modifiers.New, t.Location);.) + | "Overrides" (.m.Add(Modifiers.Override, t.Location);.) + | "MustOverride" (.m.Add(Modifiers.Abstract, t.Location);.) + | "Private" (.m.Add(Modifiers.Private, t.Location);.) + | "Protected" (.m.Add(Modifiers.Protected, t.Location);.) + | "Public" (.m.Add(Modifiers.Public, t.Location);.) + | "NotInheritable" (.m.Add(Modifiers.Sealed, t.Location);.) + | "NotOverridable" (.m.Add(Modifiers.Sealed, t.Location);.) + | "Shared" (.m.Add(Modifiers.Static, t.Location);.) + | "Overridable" (.m.Add(Modifiers.Virtual, t.Location);.) + | "Overloads" (.m.Add(Modifiers.Overloads, t.Location);.) + | "ReadOnly" (.m.Add(Modifiers.ReadOnly, t.Location);.) + | "WriteOnly" (.m.Add(Modifiers.WriteOnly, t.Location);.) + | "WithEvents" (.m.Add(Modifiers.WithEvents, t.Location);.) + | "Dim" (.m.Add(Modifiers.Dim, t.Location);.) + | "Partial" (.m.Add(Modifiers.Partial, t.Location);.) +. + +PropertyAccessorAccessModifier = + (. m = Modifiers.None; .) + { + "Public" (. m |= Modifiers.Public; .) + | "Protected" (. m |= Modifiers.Protected; .) + | "Friend" (. m |= Modifiers.Internal; .) + | "Private" (. m |= Modifiers.Private; .) + } +. +*/ + #endregion #region Global @@ -304,6 +419,32 @@ BinaryText = #endregion +#region ImportsStatement +/* +ImportsStatement = + "Imports" ImportsClause { "," ImportsClause } StatementTerminator +. + +ImportsClause = + AliasImportsClause | + MemberImportsClause | + XmlNamespaceImportsClause . + +AliasImportsClause = + // Type characters are not allowed in identifiers here + Identifier (. result.Name = t.val; .) "=" TypeName (. result.Alias = alias; .) +. + +MemberImportsClause = + TypeName (. result.Member = member; .) +. + +XmlNamespaceImportsClause = + XmlOpenTag ident "=" LiteralString XmlCloseTag +. +*/ +#endregion + #endregion END VB .