Browse Source

add XmlLiteralString

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
13a8348d4a
  1. 16
      ICSharpCode.NRefactory.VB/Ast/AstNode.cs
  2. 11
      ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs
  3. 69
      ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs
  4. 12
      ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs
  5. 1
      ICSharpCode.NRefactory.VB/IAstVisitor.cs
  6. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  7. 5
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  8. 169
      ICSharpCode.NRefactory.VB/Parser/vb.atg

16
ICSharpCode.NRefactory.VB/Ast/AstNode.cs

@ -602,6 +602,11 @@ namespace ICSharpCode.NRefactory.VB @@ -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 @@ -669,6 +674,7 @@ namespace ICSharpCode.NRefactory.VB
// some pre defined constants for common roles
public static readonly Role<Identifier> Identifier = new Role<Identifier>("Identifier", Ast.Identifier.Null);
public static readonly Role<XmlIdentifier> XmlIdentifier = new Role<XmlIdentifier>("XmlIdentifier", Ast.XmlIdentifier.Null);
public static readonly Role<XmlLiteralString> XmlLiteralString = new Role<XmlLiteralString>("XmlLiteralString", Ast.XmlLiteralString.Null);
// public static readonly Role<BlockStatement> Body = new Role<BlockStatement>("Body", CSharp.BlockStatement.Null);
// public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration>("Parameter");
@ -703,6 +709,16 @@ namespace ICSharpCode.NRefactory.VB @@ -703,6 +709,16 @@ namespace ICSharpCode.NRefactory.VB
public static readonly Role<VBTokenNode> Colon = new Role<VBTokenNode>("Colon", VBTokenNode.Null);
public static readonly Role<VBTokenNode> StatementTerminator = new Role<VBTokenNode>("StatementTerminator", VBTokenNode.Null);
// XML
/// <summary>
/// Text: &lt;
/// </summary>
public static readonly Role<VBTokenNode> XmlOpenTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null);
/// <summary>
/// Text: &gt;
/// </summary>
public static readonly Role<VBTokenNode> XmlCloseTag = new Role<VBTokenNode>("XmlOpenTag", VBTokenNode.Null);
public static readonly Role<Comment> Comment = new Role<Comment>("Comment");
}

11
ICSharpCode.NRefactory.VB/Ast/Expressions/XmlIdentifier.cs

@ -38,8 +38,9 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -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 @@ -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<T, S>(IAstVisitor<T, S> visitor, T data)

69
ICSharpCode.NRefactory.VB/Ast/Expressions/XmlLiteralString.cs

@ -0,0 +1,69 @@ @@ -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<T, S> (IAstVisitor<T, S> 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<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitXmlLiteralString(this, data);
}
}
}

12
ICSharpCode.NRefactory.VB/Ast/GlobalScope/ImportsClause.cs

@ -89,17 +89,15 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -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<T, S>(IAstVisitor<T, S> visitor, T data)
@ -109,7 +107,7 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -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);
}
}
}

1
ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -24,6 +24,7 @@ namespace ICSharpCode.NRefactory.VB { @@ -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);

1
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
<Compile Include="Ast\Expressions\SimpleNameExpression.cs" />
<Compile Include="Ast\Expressions\PrimitiveExpression.cs" />
<Compile Include="Ast\Expressions\XmlIdentifier.cs" />
<Compile Include="Ast\Expressions\XmlLiteralString.cs" />
<Compile Include="Ast\General\Attribute.cs" />
<Compile Include="Ast\General\AttributeBlock.cs" />
<Compile Include="Ast\General\CompilationUnit.cs" />

5
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -169,5 +169,10 @@ namespace ICSharpCode.NRefactory.VB @@ -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();
}
}
}

169
ICSharpCode.NRefactory.VB/Parser/vb.atg

@ -11,7 +11,7 @@ using Roles = ICSharpCode.NRefactory.VB.AstNode.Roles; @@ -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 @@ -24,16 +24,16 @@ TOKENS
LiteralSingle
LiteralDecimal
LiteralDate
XmlOpenTag
XmlCloseTag
XmlStartInlineVB
XmlEndInlineVB
XmlCloseTagEmptyElement
XmlOpenEndTag
XmlContent
XmlComment
XmlCData
XmlProcessingInstruction
XmlOpenTag // <
XmlCloseTag // >
XmlStartInlineVB // <%=
XmlEndInlineVB // %>
XmlCloseTagEmptyElement // />
XmlOpenEndTag // </
XmlContent // ...
XmlComment // <!-- ... -->
XmlCData // <![CDATA[...]]>
XmlProcessingInstruction
/* ----- special character ----- */
"="
@ -256,7 +256,7 @@ TOKENS @@ -256,7 +256,7 @@ TOKENS
"WriteOnly"
"Xor"
"GetXmlNamespace"
/* END AUTOGENERATED TOKENS SECTION */
#endregion
PRODUCTIONS
@ -269,14 +269,129 @@ VB = @@ -269,14 +269,129 @@ VB =
Get();
.)
{ StatementTerminator }
{ OptionStatement<CompilationUnit.MemberRole> { StatementTerminator } }
/* { ImportsStmt { StatementTerminator } }
{ OptionStatement<CompilationUnit.MemberRole> { StatementTerminator } }
/* { ImportsStatement<CompilationUnit.MemberRole> { StatementTerminator } }
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection { StatementTerminator } }
{ NamespaceMemberDecl { StatementTerminator } } */
.
StatementTerminator = SYNC ( EOL<Roles.StatementTerminator> | ":"<Roles.StatementTerminator> ) .
/* IdentifierOrKeyword<out string identifier> = 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<out AstType type> =
(. type = null; .)
.
PrimitiveTypeName<out string type>
(. 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<ParamModifierList m> =
"ByVal" (. m.Add(ParameterModifiers.In); .)
| "ByRef" (. m.Add(ParameterModifiers.Ref); .)
| "Optional" (. m.Add(ParameterModifiers.Optional); .)
| "ParamArray" (. m.Add(ParameterModifiers.Params); .)
.
TypeModifier<ModifierList m> =
"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<ModifierList m> =
"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<out Modifiers m> =
(. 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<OptionStatement os> = @@ -304,6 +419,32 @@ BinaryText<OptionStatement os> =
#endregion
#region ImportsStatement
/*
ImportsStatement<auto> =
"Imports"<Roles.Keyword> ImportsClause { "," ImportsClause } StatementTerminator
.
ImportsClause =
AliasImportsClause<Ast.ImportsStatement.ImportsClauseRole> |
MemberImportsClause<Ast.ImportsStatement.ImportsClauseRole> |
XmlNamespaceImportsClause<Ast.ImportsStatement.ImportsClauseRole> .
AliasImportsClause<auto> =
// Type characters are not allowed in identifiers here
Identifier (. result.Name = t.val; .) "=" TypeName<out alias> (. result.Alias = alias; .)
.
MemberImportsClause<auto> =
TypeName<out member> (. result.Member = member; .)
.
XmlNamespaceImportsClause<auto> =
XmlOpenTag<Roles.XmlOpenTag> ident<Roles.XmlIdentifier> "="<Roles.Assign> LiteralString<Roles.XmlLiteralString> XmlCloseTag<Roles.XmlCloseTag>
.
*/
#endregion
#endregion
END VB .

Loading…
Cancel
Save