Browse Source

added "Infer" keyword;

ordered keywords;

memberreferenceexpression vs. typereferenceexpression

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3380 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 18 years ago
parent
commit
ead3e0d612
  1. 65
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt
  2. 43
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs
  3. 342
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs
  4. 2736
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  5. 106
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  6. 44
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  7. 303
      src/Libraries/NRefactory/Test/Lexer/VBNet/LexerTests.cs
  8. 10
      src/Libraries/NRefactory/Test/Parser/Expressions/AddressOfExpressionTests.cs
  9. 45
      src/Libraries/NRefactory/Test/Parser/Expressions/MemberReferenceExpressionTests.cs

65
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt

@ -21,21 +21,20 @@ LiteralDecimal
LiteralDate LiteralDate
# SPECIAL_CHARACTERS # SPECIAL_CHARACTERS
Dot = "."
Assign = "=" Assign = "="
Comma = ","
Colon =":" Colon =":"
Plus = "+" Comma = ","
Minus = "-" ConcatString = "&"
Times = "*"
Div ="/" Div ="/"
DivInteger = "\\" DivInteger = "\\"
ConcatString = "&" Dot = "."
Power = "^"
# Question mark is not needed by VB8, but we use it inside the IDE
QuestionMark = "?"
# Exclamation mark = Dictionary access operator (not always a token, sometimes it's a type character) # Exclamation mark = Dictionary access operator (not always a token, sometimes it's a type character)
ExclamationMark = "!" ExclamationMark = "!"
Minus = "-"
Plus = "+"
Power = "^"
QuestionMark = "?"
Times = "*"
OpenCurlyBrace = "{" OpenCurlyBrace = "{"
CloseCurlyBrace = "}" CloseCurlyBrace = "}"
@ -95,10 +94,16 @@ ConcatStringAssign = "&="
"CObj" "CObj"
"Compare" "Compare"
"Const" "Const"
"Continue"
"CSByte"
"CShort" "CShort"
"CSng" "CSng"
"CStr" "CStr"
"CType" "CType"
"CUInt"
"CULng"
"CUShort"
"Custom"
"Date" "Date"
"Decimal" "Decimal"
"Declare" "Declare"
@ -126,6 +131,7 @@ ConcatStringAssign = "&="
"Function" "Function"
"Get" "Get"
"GetType" "GetType"
"Global"
"GoSub" "GoSub"
"GoTo" "GoTo"
"Handles" "Handles"
@ -133,10 +139,13 @@ ConcatStringAssign = "&="
"Implements" "Implements"
"Imports" "Imports"
"In" "In"
"Infer"
"Inherits" "Inherits"
"Integer" "Integer"
"Interface" "Interface"
"Is" "Is"
"IsNot"
# Note: IsTrue and IsFalse are 'NOT' keywords they're only valid in Operator declarations (like get/set/value are no C# 'keywords')
"Let" "Let"
"Lib" "Lib"
"Like" "Like"
@ -150,6 +159,7 @@ ConcatStringAssign = "&="
"MyBase" "MyBase"
"MyClass" "MyClass"
"Namespace" "Namespace"
"Narrowing"
"New" "New"
"Next" "Next"
"Not" "Not"
@ -157,8 +167,10 @@ ConcatStringAssign = "&="
"NotInheritable" "NotInheritable"
"NotOverridable" "NotOverridable"
"Object" "Object"
"Of"
"Off" "Off"
"On" "On"
"Operator"
"Option" "Option"
"Optional" "Optional"
"Or" "Or"
@ -167,6 +179,7 @@ ConcatStringAssign = "&="
"Overridable" "Overridable"
"Overrides" "Overrides"
"ParamArray" "ParamArray"
"Partial"
"Preserve" "Preserve"
"Private" "Private"
"Property" "Property"
@ -175,9 +188,12 @@ ConcatStringAssign = "&="
"RaiseEvent" "RaiseEvent"
"ReadOnly" "ReadOnly"
"ReDim" "ReDim"
# has to be in the keyword list for the output formatter
"Rem"
"RemoveHandler" "RemoveHandler"
"Resume" "Resume"
"Return" "Return"
"SByte"
"Select" "Select"
"Set" "Set"
"Shadows" "Shadows"
@ -198,42 +214,23 @@ ConcatStringAssign = "&="
"To" "To"
"True" "True"
"Try" "Try"
"TryCast"
"TypeOf" "TypeOf"
"UInteger"
"ULong"
"Unicode" "Unicode"
"Until" "Until"
"UShort"
"Using"
"Variant" "Variant"
"Wend" "Wend"
"When" "When"
"While" "While"
"Widening"
"With" "With"
"WithEvents" "WithEvents"
"WriteOnly" "WriteOnly"
"Xor" "Xor"
# Rem never gets passed to the parser because it is handled by the lexer, but it still
# has to be in the keyword list for the output formatter
"Rem"
# VB.NET 2.0 Keywords:
"Continue"
"Operator"
"Using"
"IsNot"
# Note: IsTrue and IsFalse are 'NOT' keywords they're only valid in Operator declarations (like get/set/value are no C# 'keywords')
"SByte"
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"
"Narrowing"
"Widening"
"Partial"
"Custom"
#Sets #Sets
Null("Nothing") Null("Nothing")

43
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs

@ -36,10 +36,16 @@ namespace ICSharpCode.NRefactory.Parser.VB
"COBJ", "COBJ",
"COMPARE", "COMPARE",
"CONST", "CONST",
"CONTINUE",
"CSBYTE",
"CSHORT", "CSHORT",
"CSNG", "CSNG",
"CSTR", "CSTR",
"CTYPE", "CTYPE",
"CUINT",
"CULNG",
"CUSHORT",
"CUSTOM",
"DATE", "DATE",
"DECIMAL", "DECIMAL",
"DECLARE", "DECLARE",
@ -67,6 +73,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"FUNCTION", "FUNCTION",
"GET", "GET",
"GETTYPE", "GETTYPE",
"GLOBAL",
"GOSUB", "GOSUB",
"GOTO", "GOTO",
"HANDLES", "HANDLES",
@ -74,10 +81,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
"IMPLEMENTS", "IMPLEMENTS",
"IMPORTS", "IMPORTS",
"IN", "IN",
"INFER",
"INHERITS", "INHERITS",
"INTEGER", "INTEGER",
"INTERFACE", "INTERFACE",
"IS", "IS",
"ISNOT",
"LET", "LET",
"LIB", "LIB",
"LIKE", "LIKE",
@ -91,6 +100,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"MYBASE", "MYBASE",
"MYCLASS", "MYCLASS",
"NAMESPACE", "NAMESPACE",
"NARROWING",
"NEW", "NEW",
"NEXT", "NEXT",
"NOT", "NOT",
@ -98,8 +108,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
"NOTINHERITABLE", "NOTINHERITABLE",
"NOTOVERRIDABLE", "NOTOVERRIDABLE",
"OBJECT", "OBJECT",
"OF",
"OFF", "OFF",
"ON", "ON",
"OPERATOR",
"OPTION", "OPTION",
"OPTIONAL", "OPTIONAL",
"OR", "OR",
@ -108,6 +120,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"OVERRIDABLE", "OVERRIDABLE",
"OVERRIDES", "OVERRIDES",
"PARAMARRAY", "PARAMARRAY",
"PARTIAL",
"PRESERVE", "PRESERVE",
"PRIVATE", "PRIVATE",
"PROPERTY", "PROPERTY",
@ -116,9 +129,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
"RAISEEVENT", "RAISEEVENT",
"READONLY", "READONLY",
"REDIM", "REDIM",
"REM",
"REMOVEHANDLER", "REMOVEHANDLER",
"RESUME", "RESUME",
"RETURN", "RETURN",
"SBYTE",
"SELECT", "SELECT",
"SET", "SET",
"SHADOWS", "SHADOWS",
@ -139,37 +154,23 @@ namespace ICSharpCode.NRefactory.Parser.VB
"TO", "TO",
"TRUE", "TRUE",
"TRY", "TRY",
"TRYCAST",
"TYPEOF", "TYPEOF",
"UINTEGER",
"ULONG",
"UNICODE", "UNICODE",
"UNTIL", "UNTIL",
"USHORT",
"USING",
"VARIANT", "VARIANT",
"WEND", "WEND",
"WHEN", "WHEN",
"WHILE", "WHILE",
"WIDENING",
"WITH", "WITH",
"WITHEVENTS", "WITHEVENTS",
"WRITEONLY", "WRITEONLY",
"XOR", "XOR"
"REM",
"CONTINUE",
"OPERATOR",
"USING",
"ISNOT",
"SBYTE",
"UINTEGER",
"ULONG",
"USHORT",
"CSBYTE",
"CUSHORT",
"CUINT",
"CULNG",
"GLOBAL",
"TRYCAST",
"OF",
"NARROWING",
"WIDENING",
"PARTIAL",
"CUSTOM"
}; };
static LookupTable keywords = new LookupTable(false); static LookupTable keywords = new LookupTable(false);

342
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs

@ -19,19 +19,19 @@ namespace ICSharpCode.NRefactory.Parser.VB
public const int LiteralDate = 9; public const int LiteralDate = 9;
// ----- special character ----- // ----- special character -----
public const int Dot = 10; public const int Assign = 10;
public const int Assign = 11; public const int Colon = 11;
public const int Comma = 12; public const int Comma = 12;
public const int Colon = 13; public const int ConcatString = 13;
public const int Plus = 14; public const int Div = 14;
public const int Minus = 15; public const int DivInteger = 15;
public const int Times = 16; public const int Dot = 16;
public const int Div = 17; public const int ExclamationMark = 17;
public const int DivInteger = 18; public const int Minus = 18;
public const int ConcatString = 19; public const int Plus = 19;
public const int Power = 20; public const int Power = 20;
public const int QuestionMark = 21; public const int QuestionMark = 21;
public const int ExclamationMark = 22; public const int Times = 22;
public const int OpenCurlyBrace = 23; public const int OpenCurlyBrace = 23;
public const int CloseCurlyBrace = 24; public const int CloseCurlyBrace = 24;
public const int OpenParenthesis = 25; public const int OpenParenthesis = 25;
@ -84,142 +84,143 @@ namespace ICSharpCode.NRefactory.Parser.VB
public const int CObj = 70; public const int CObj = 70;
public const int Compare = 71; public const int Compare = 71;
public const int Const = 72; public const int Const = 72;
public const int CShort = 73; public const int Continue = 73;
public const int CSng = 74; public const int CSByte = 74;
public const int CStr = 75; public const int CShort = 75;
public const int CType = 76; public const int CSng = 76;
public const int Date = 77; public const int CStr = 77;
public const int Decimal = 78; public const int CType = 78;
public const int Declare = 79; public const int CUInt = 79;
public const int Default = 80; public const int CULng = 80;
public const int Delegate = 81; public const int CUShort = 81;
public const int Dim = 82; public const int Custom = 82;
public const int DirectCast = 83; public const int Date = 83;
public const int Do = 84; public const int Decimal = 84;
public const int Double = 85; public const int Declare = 85;
public const int Each = 86; public const int Default = 86;
public const int Else = 87; public const int Delegate = 87;
public const int ElseIf = 88; public const int Dim = 88;
public const int End = 89; public const int DirectCast = 89;
public const int EndIf = 90; public const int Do = 90;
public const int Enum = 91; public const int Double = 91;
public const int Erase = 92; public const int Each = 92;
public const int Error = 93; public const int Else = 93;
public const int Event = 94; public const int ElseIf = 94;
public const int Exit = 95; public const int End = 95;
public const int Explicit = 96; public const int EndIf = 96;
public const int False = 97; public const int Enum = 97;
public const int Finally = 98; public const int Erase = 98;
public const int For = 99; public const int Error = 99;
public const int Friend = 100; public const int Event = 100;
public const int Function = 101; public const int Exit = 101;
public const int Get = 102; public const int Explicit = 102;
new public const int GetType = 103; public const int False = 103;
public const int GoSub = 104; public const int Finally = 104;
public const int GoTo = 105; public const int For = 105;
public const int Handles = 106; public const int Friend = 106;
public const int If = 107; public const int Function = 107;
public const int Implements = 108; public const int Get = 108;
public const int Imports = 109; new public const int GetType = 109;
public const int In = 110; public const int Global = 110;
public const int Inherits = 111; public const int GoSub = 111;
public const int Integer = 112; public const int GoTo = 112;
public const int Interface = 113; public const int Handles = 113;
public const int Is = 114; public const int If = 114;
public const int Let = 115; public const int Implements = 115;
public const int Lib = 116; public const int Imports = 116;
public const int Like = 117; public const int In = 117;
public const int Long = 118; public const int Infer = 118;
public const int Loop = 119; public const int Inherits = 119;
public const int Me = 120; public const int Integer = 120;
public const int Mod = 121; public const int Interface = 121;
public const int Module = 122; public const int Is = 122;
public const int MustInherit = 123; public const int IsNot = 123;
public const int MustOverride = 124; public const int Let = 124;
public const int MyBase = 125; public const int Lib = 125;
public const int MyClass = 126; public const int Like = 126;
public const int Namespace = 127; public const int Long = 127;
public const int New = 128; public const int Loop = 128;
public const int Next = 129; public const int Me = 129;
public const int Not = 130; public const int Mod = 130;
public const int Nothing = 131; public const int Module = 131;
public const int NotInheritable = 132; public const int MustInherit = 132;
public const int NotOverridable = 133; public const int MustOverride = 133;
public const int Object = 134; public const int MyBase = 134;
public const int Off = 135; public const int MyClass = 135;
public const int On = 136; public const int Namespace = 136;
public const int Option = 137; public const int Narrowing = 137;
public const int Optional = 138; public const int New = 138;
public const int Or = 139; public const int Next = 139;
public const int OrElse = 140; public const int Not = 140;
public const int Overloads = 141; public const int Nothing = 141;
public const int Overridable = 142; public const int NotInheritable = 142;
public const int Overrides = 143; public const int NotOverridable = 143;
public const int ParamArray = 144; public const int Object = 144;
public const int Preserve = 145; public const int Of = 145;
public const int Private = 146; public const int Off = 146;
public const int Property = 147; public const int On = 147;
public const int Protected = 148; public const int Operator = 148;
public const int Public = 149; public const int Option = 149;
public const int RaiseEvent = 150; public const int Optional = 150;
public const int ReadOnly = 151; public const int Or = 151;
public const int ReDim = 152; public const int OrElse = 152;
public const int RemoveHandler = 153; public const int Overloads = 153;
public const int Resume = 154; public const int Overridable = 154;
public const int Return = 155; public const int Overrides = 155;
public const int Select = 156; public const int ParamArray = 156;
public const int Set = 157; public const int Partial = 157;
public const int Shadows = 158; public const int Preserve = 158;
public const int Shared = 159; public const int Private = 159;
public const int Short = 160; public const int Property = 160;
public const int Single = 161; public const int Protected = 161;
public const int Static = 162; public const int Public = 162;
public const int Step = 163; public const int RaiseEvent = 163;
public const int Stop = 164; public const int ReadOnly = 164;
public const int Strict = 165; public const int ReDim = 165;
public const int String = 166; public const int Rem = 166;
public const int Structure = 167; public const int RemoveHandler = 167;
public const int Sub = 168; public const int Resume = 168;
public const int SyncLock = 169; public const int Return = 169;
public const int Text = 170; public const int SByte = 170;
public const int Then = 171; public const int Select = 171;
public const int Throw = 172; public const int Set = 172;
public const int To = 173; public const int Shadows = 173;
public const int True = 174; public const int Shared = 174;
public const int Try = 175; public const int Short = 175;
public const int TypeOf = 176; public const int Single = 176;
public const int Unicode = 177; public const int Static = 177;
public const int Until = 178; public const int Step = 178;
public const int Variant = 179; public const int Stop = 179;
public const int Wend = 180; public const int Strict = 180;
public const int When = 181; public const int String = 181;
public const int While = 182; public const int Structure = 182;
public const int With = 183; public const int Sub = 183;
public const int WithEvents = 184; public const int SyncLock = 184;
public const int WriteOnly = 185; public const int Text = 185;
public const int Xor = 186; public const int Then = 186;
public const int Rem = 187; public const int Throw = 187;
public const int Continue = 188; public const int To = 188;
public const int Operator = 189; public const int True = 189;
public const int Using = 190; public const int Try = 190;
public const int IsNot = 191; public const int TryCast = 191;
public const int SByte = 192; public const int TypeOf = 192;
public const int UInteger = 193; public const int UInteger = 193;
public const int ULong = 194; public const int ULong = 194;
public const int UShort = 195; public const int Unicode = 195;
public const int CSByte = 196; public const int Until = 196;
public const int CUShort = 197; public const int UShort = 197;
public const int CUInt = 198; public const int Using = 198;
public const int CULng = 199; public const int Variant = 199;
public const int Global = 200; public const int Wend = 200;
public const int TryCast = 201; public const int When = 201;
public const int Of = 202; public const int While = 202;
public const int Narrowing = 203; public const int Widening = 203;
public const int Widening = 204; public const int With = 204;
public const int Partial = 205; public const int WithEvents = 205;
public const int Custom = 206; public const int WriteOnly = 206;
public const int Xor = 207;
public const int MaxToken = 207; public const int MaxToken = 208;
static BitArray NewSet(params int[] values) static BitArray NewSet(params int[] values)
{ {
BitArray bitArray = new BitArray(MaxToken); BitArray bitArray = new BitArray(MaxToken);
@ -245,19 +246,19 @@ namespace ICSharpCode.NRefactory.Parser.VB
"<LiteralDecimal>", "<LiteralDecimal>",
"<LiteralDate>", "<LiteralDate>",
// ----- special character ----- // ----- special character -----
".",
"=", "=",
",",
":", ":",
"+", ",",
"-", "&",
"*",
"/", "/",
"\\", "\\",
"&", ".",
"!",
"-",
"+",
"^", "^",
"?", "?",
"!", "*",
"{", "{",
"}", "}",
"(", "(",
@ -309,10 +310,16 @@ namespace ICSharpCode.NRefactory.Parser.VB
"CObj", "CObj",
"Compare", "Compare",
"Const", "Const",
"Continue",
"CSByte",
"CShort", "CShort",
"CSng", "CSng",
"CStr", "CStr",
"CType", "CType",
"CUInt",
"CULng",
"CUShort",
"Custom",
"Date", "Date",
"Decimal", "Decimal",
"Declare", "Declare",
@ -340,6 +347,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"Function", "Function",
"Get", "Get",
"GetType", "GetType",
"Global",
"GoSub", "GoSub",
"GoTo", "GoTo",
"Handles", "Handles",
@ -347,10 +355,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
"Implements", "Implements",
"Imports", "Imports",
"In", "In",
"Infer",
"Inherits", "Inherits",
"Integer", "Integer",
"Interface", "Interface",
"Is", "Is",
"IsNot",
"Let", "Let",
"Lib", "Lib",
"Like", "Like",
@ -364,6 +374,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"MyBase", "MyBase",
"MyClass", "MyClass",
"Namespace", "Namespace",
"Narrowing",
"New", "New",
"Next", "Next",
"Not", "Not",
@ -371,8 +382,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
"NotInheritable", "NotInheritable",
"NotOverridable", "NotOverridable",
"Object", "Object",
"Of",
"Off", "Off",
"On", "On",
"Operator",
"Option", "Option",
"Optional", "Optional",
"Or", "Or",
@ -381,6 +394,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"Overridable", "Overridable",
"Overrides", "Overrides",
"ParamArray", "ParamArray",
"Partial",
"Preserve", "Preserve",
"Private", "Private",
"Property", "Property",
@ -389,9 +403,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
"RaiseEvent", "RaiseEvent",
"ReadOnly", "ReadOnly",
"ReDim", "ReDim",
"Rem",
"RemoveHandler", "RemoveHandler",
"Resume", "Resume",
"Return", "Return",
"SByte",
"Select", "Select",
"Set", "Set",
"Shadows", "Shadows",
@ -412,37 +428,23 @@ namespace ICSharpCode.NRefactory.Parser.VB
"To", "To",
"True", "True",
"Try", "Try",
"TryCast",
"TypeOf", "TypeOf",
"UInteger",
"ULong",
"Unicode", "Unicode",
"Until", "Until",
"UShort",
"Using",
"Variant", "Variant",
"Wend", "Wend",
"When", "When",
"While", "While",
"Widening",
"With", "With",
"WithEvents", "WithEvents",
"WriteOnly", "WriteOnly",
"Xor", "Xor",
"Rem",
"Continue",
"Operator",
"Using",
"IsNot",
"SByte",
"UInteger",
"ULong",
"UShort",
"CSByte",
"CUShort",
"CUInt",
"CULng",
"Global",
"TryCast",
"Of",
"Narrowing",
"Widening",
"Partial",
"Custom",
}; };
public static string GetTokenString(int token) public static string GetTokenString(int token)
{ {

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

File diff suppressed because it is too large Load Diff

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

@ -23,19 +23,19 @@ TOKENS
LiteralDate LiteralDate
/* ----- special character ----- */ /* ----- special character ----- */
"."
"=" "="
","
":" ":"
"+" ","
"-" "&"
"*"
"/" "/"
"\\" "\\"
"&" "."
"!"
"-"
"+"
"^" "^"
"?" "?"
"!" "*"
"{" "{"
"}" "}"
"(" "("
@ -88,10 +88,16 @@ TOKENS
"CObj" "CObj"
"Compare" "Compare"
"Const" "Const"
"Continue"
"CSByte"
"CShort" "CShort"
"CSng" "CSng"
"CStr" "CStr"
"CType" "CType"
"CUInt"
"CULng"
"CUShort"
"Custom"
"Date" "Date"
"Decimal" "Decimal"
"Declare" "Declare"
@ -119,6 +125,7 @@ TOKENS
"Function" "Function"
"Get" "Get"
"GetType" "GetType"
"Global"
"GoSub" "GoSub"
"GoTo" "GoTo"
"Handles" "Handles"
@ -126,10 +133,12 @@ TOKENS
"Implements" "Implements"
"Imports" "Imports"
"In" "In"
"Infer"
"Inherits" "Inherits"
"Integer" "Integer"
"Interface" "Interface"
"Is" "Is"
"IsNot"
"Let" "Let"
"Lib" "Lib"
"Like" "Like"
@ -143,6 +152,7 @@ TOKENS
"MyBase" "MyBase"
"MyClass" "MyClass"
"Namespace" "Namespace"
"Narrowing"
"New" "New"
"Next" "Next"
"Not" "Not"
@ -150,8 +160,10 @@ TOKENS
"NotInheritable" "NotInheritable"
"NotOverridable" "NotOverridable"
"Object" "Object"
"Of"
"Off" "Off"
"On" "On"
"Operator"
"Option" "Option"
"Optional" "Optional"
"Or" "Or"
@ -160,6 +172,7 @@ TOKENS
"Overridable" "Overridable"
"Overrides" "Overrides"
"ParamArray" "ParamArray"
"Partial"
"Preserve" "Preserve"
"Private" "Private"
"Property" "Property"
@ -168,9 +181,11 @@ TOKENS
"RaiseEvent" "RaiseEvent"
"ReadOnly" "ReadOnly"
"ReDim" "ReDim"
"Rem"
"RemoveHandler" "RemoveHandler"
"Resume" "Resume"
"Return" "Return"
"SByte"
"Select" "Select"
"Set" "Set"
"Shadows" "Shadows"
@ -191,40 +206,25 @@ TOKENS
"To" "To"
"True" "True"
"Try" "Try"
"TryCast"
"TypeOf" "TypeOf"
"UInteger"
"ULong"
"Unicode" "Unicode"
"Until" "Until"
"UShort"
"Using"
"Variant" "Variant"
"Wend" "Wend"
"When" "When"
"While" "While"
"Widening"
"With" "With"
"WithEvents" "WithEvents"
"WriteOnly" "WriteOnly"
"Xor" "Xor"
"Rem"
"Continue"
"Operator"
"Using"
"IsNot"
"SByte"
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
"Of"
"Narrowing"
"Widening"
"Partial"
"Custom"
/* END AUTOGENERATED TOKENS SECTION */ /* END AUTOGENERATED TOKENS SECTION */
PRODUCTIONS PRODUCTIONS
VBNET VBNET
@ -1615,9 +1615,13 @@ SimpleExpr<out Expression pexpr>
= =
SimpleNonInvocationExpression<out pexpr> SimpleNonInvocationExpression<out pexpr>
{ {
"." IdentifierOrKeyword<out name> (. pexpr = new MemberReferenceExpression(pexpr, name); .) "." IdentifierOrKeyword<out name>
| "!" IdentifierOrKeyword<out name> (. pexpr = new BinaryOperatorExpression(pexpr, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name)); .) (. pexpr = new MemberReferenceExpression(pexpr, name); .)
| InvocationExpression<ref pexpr> [ IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeArgumentList<((MemberReferenceExpression)pexpr).TypeArguments> ")"
]
| "!" IdentifierOrKeyword<out name> (. pexpr = new BinaryOperatorExpression(pexpr, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name)); .)
| InvocationExpression<ref pexpr>
} }
. .
@ -1644,8 +1648,9 @@ SimpleNonInvocationExpression<out Expression pexpr>
| "Nothing" (.pexpr = new PrimitiveExpression(null, "null"); .) | "Nothing" (.pexpr = new PrimitiveExpression(null, "null"); .)
| /* 11.4.2 */ "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .) | /* 11.4.2 */ "(" Expr<out expr> ")" (. pexpr = new ParenthesizedExpression(expr); .)
| /* 11.4.4 */ Identifier | /* 11.4.4 */ Identifier
(. pexpr = new IdentifierExpression(t.val); .) (. pexpr = new IdentifierExpression(t.val);
(. pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; .) pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;
.)
[ IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) [ IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeArgumentList<((IdentifierExpression)pexpr).TypeArguments> ")" "(" "Of" TypeArgumentList<((IdentifierExpression)pexpr).TypeArguments> ")"
] ]
@ -1719,36 +1724,15 @@ ConditionalExpression<out Expression expr>
. .
InvocationExpression<ref Expression pexpr> InvocationExpression<ref Expression pexpr>
(. List<TypeReference> typeParameters = new List<TypeReference>(); (. List<Expression> parameters = null; .)
List<Expression> parameters = null;
TypeReference type; .)
= =
"(" (. Location start = t.Location; .) "(" (. Location start = t.Location; .)
( "Of" ArgumentList<out parameters>
TypeName<out type> (. if (type != null) typeParameters.Add(type); .) ")"
{ (.
"," pexpr = new InvocationExpression(pexpr, parameters);
TypeName<out type> (. if (type != null) typeParameters.Add(type); .) SetParent(parameters, pexpr);
} .)
")"
(
"." Identifier
(. pexpr = new MemberReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); .)
| "("
ArgumentList<out parameters>
")"
(.
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
SetParent(parameters, pexpr);
.)
)
| ArgumentList<out parameters>
")"
(.
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
SetParent(parameters, pexpr);
.)
)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .) (. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
. .

44
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -209,34 +209,6 @@ namespace ICSharpCode.NRefactory.Parser.VB
return m.Contains(Modifiers.Abstract); return m.Contains(Modifiers.Abstract);
} }
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is MemberReferenceExpression) {
expr = ((MemberReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */ /* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */ /* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */ /* There was an unknown expression (e.g. TypeReferenceExpression) in it */
@ -271,21 +243,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0") if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
Error("lower bound of array must be zero"); Error("lower bound of array must be zero");
} }
InvocationExpression CreateInvocationExpression(Expression target, List<Expression> parameters, List<TypeReference> typeArguments)
{
if (typeArguments != null && typeArguments.Count > 0) {
if (target is IdentifierExpression) {
((IdentifierExpression)target).TypeArguments = typeArguments;
} else if (target is MemberReferenceExpression) {
((MemberReferenceExpression)target).TypeArguments = typeArguments;
} else {
Error("Type arguments only allowed on IdentifierExpression and MemberReferenceExpression");
}
}
return new InvocationExpression(target, parameters);
}
/// <summary> /// <summary>
/// Adds a child item to a collection stored in the parent node. /// Adds a child item to a collection stored in the parent node.
/// Also set's the item's parent to <paramref name="parent"/>. /// Also set's the item's parent to <paramref name="parent"/>.

303
src/Libraries/NRefactory/Test/Lexer/VBNet/LexerTests.cs

@ -1,13 +1,7 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System; using System;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.VB; using ICSharpCode.NRefactory.Parser.VB;
using ICSharpCode.NRefactory.PrettyPrinter; using ICSharpCode.NRefactory.PrettyPrinter;
@ -23,17 +17,17 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
} }
[Test] [Test]
public void TestDot() public void TestAssign()
{ {
ILexer lexer = GenerateLexer(new StringReader(".")); ILexer lexer = GenerateLexer(new StringReader("="));
Assert.AreEqual(Tokens.Dot, lexer.NextToken().kind); Assert.AreEqual(Tokens.Assign, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestAssign() public void TestColon()
{ {
ILexer lexer = GenerateLexer(new StringReader("=")); ILexer lexer = GenerateLexer(new StringReader(":"));
Assert.AreEqual(Tokens.Assign, lexer.NextToken().kind); Assert.AreEqual(Tokens.Colon, lexer.NextToken().kind);
} }
[Test] [Test]
@ -44,52 +38,52 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
} }
[Test] [Test]
public void TestColon() public void TestConcatString()
{ {
ILexer lexer = GenerateLexer(new StringReader(":")); ILexer lexer = GenerateLexer(new StringReader("&"));
Assert.AreEqual(Tokens.Colon, lexer.NextToken().kind); Assert.AreEqual(Tokens.ConcatString, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestPlus() public void TestDiv()
{ {
ILexer lexer = GenerateLexer(new StringReader("+")); ILexer lexer = GenerateLexer(new StringReader("/"));
Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind); Assert.AreEqual(Tokens.Div, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestMinus() public void TestDivInteger()
{ {
ILexer lexer = GenerateLexer(new StringReader("-")); ILexer lexer = GenerateLexer(new StringReader("\\"));
Assert.AreEqual(Tokens.Minus, lexer.NextToken().kind); Assert.AreEqual(Tokens.DivInteger, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestTimes() public void TestDot()
{ {
ILexer lexer = GenerateLexer(new StringReader("*")); ILexer lexer = GenerateLexer(new StringReader("."));
Assert.AreEqual(Tokens.Times, lexer.NextToken().kind); Assert.AreEqual(Tokens.Dot, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestDiv() public void TestExclamationMark()
{ {
ILexer lexer = GenerateLexer(new StringReader("/")); ILexer lexer = GenerateLexer(new StringReader("!"));
Assert.AreEqual(Tokens.Div, lexer.NextToken().kind); Assert.AreEqual(Tokens.ExclamationMark, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestDivInteger() public void TestMinus()
{ {
ILexer lexer = GenerateLexer(new StringReader("\\")); ILexer lexer = GenerateLexer(new StringReader("-"));
Assert.AreEqual(Tokens.DivInteger, lexer.NextToken().kind); Assert.AreEqual(Tokens.Minus, lexer.NextToken().kind);
} }
[Test] [Test]
public void TestConcatString() public void TestPlus()
{ {
ILexer lexer = GenerateLexer(new StringReader("&")); ILexer lexer = GenerateLexer(new StringReader("+"));
Assert.AreEqual(Tokens.ConcatString, lexer.NextToken().kind); Assert.AreEqual(Tokens.Plus, lexer.NextToken().kind);
} }
[Test] [Test]
@ -107,10 +101,10 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
} }
[Test] [Test]
public void TestExclamationMark() public void TestTimes()
{ {
ILexer lexer = GenerateLexer(new StringReader("!")); ILexer lexer = GenerateLexer(new StringReader("*"));
Assert.AreEqual(Tokens.ExclamationMark, lexer.NextToken().kind); Assert.AreEqual(Tokens.Times, lexer.NextToken().kind);
} }
[Test] [Test]
@ -434,6 +428,18 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Const, lexer.NextToken().kind); Assert.AreEqual(Tokens.Const, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestContinue()
{
ILexer lexer = GenerateLexer(new StringReader("Continue"));
Assert.AreEqual(Tokens.Continue, lexer.NextToken().kind);
}
[Test()]
public void TestCSByte()
{
ILexer lexer = GenerateLexer(new StringReader("CSByte"));
Assert.AreEqual(Tokens.CSByte, lexer.NextToken().kind);
}
[Test()]
public void TestCShort() public void TestCShort()
{ {
ILexer lexer = GenerateLexer(new StringReader("CShort")); ILexer lexer = GenerateLexer(new StringReader("CShort"));
@ -458,6 +464,30 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.CType, lexer.NextToken().kind); Assert.AreEqual(Tokens.CType, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestCUInt()
{
ILexer lexer = GenerateLexer(new StringReader("CUInt"));
Assert.AreEqual(Tokens.CUInt, lexer.NextToken().kind);
}
[Test()]
public void TestCULng()
{
ILexer lexer = GenerateLexer(new StringReader("CULng"));
Assert.AreEqual(Tokens.CULng, lexer.NextToken().kind);
}
[Test()]
public void TestCUShort()
{
ILexer lexer = GenerateLexer(new StringReader("CUShort"));
Assert.AreEqual(Tokens.CUShort, lexer.NextToken().kind);
}
[Test()]
public void TestCustom()
{
ILexer lexer = GenerateLexer(new StringReader("Custom"));
Assert.AreEqual(Tokens.Custom, lexer.NextToken().kind);
}
[Test()]
public void TestDate() public void TestDate()
{ {
ILexer lexer = GenerateLexer(new StringReader("Date")); ILexer lexer = GenerateLexer(new StringReader("Date"));
@ -620,6 +650,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.GetType, lexer.NextToken().kind); Assert.AreEqual(Tokens.GetType, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestGlobal()
{
ILexer lexer = GenerateLexer(new StringReader("Global"));
Assert.AreEqual(Tokens.Global, lexer.NextToken().kind);
}
[Test()]
public void TestGoSub() public void TestGoSub()
{ {
ILexer lexer = GenerateLexer(new StringReader("GoSub")); ILexer lexer = GenerateLexer(new StringReader("GoSub"));
@ -662,6 +698,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.In, lexer.NextToken().kind); Assert.AreEqual(Tokens.In, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestInfer()
{
ILexer lexer = GenerateLexer(new StringReader("Infer"));
Assert.AreEqual(Tokens.Infer, lexer.NextToken().kind);
}
[Test()]
public void TestInherits() public void TestInherits()
{ {
ILexer lexer = GenerateLexer(new StringReader("Inherits")); ILexer lexer = GenerateLexer(new StringReader("Inherits"));
@ -686,6 +728,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Is, lexer.NextToken().kind); Assert.AreEqual(Tokens.Is, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestIsNot()
{
ILexer lexer = GenerateLexer(new StringReader("IsNot"));
Assert.AreEqual(Tokens.IsNot, lexer.NextToken().kind);
}
[Test()]
public void TestLet() public void TestLet()
{ {
ILexer lexer = GenerateLexer(new StringReader("Let")); ILexer lexer = GenerateLexer(new StringReader("Let"));
@ -764,6 +812,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Namespace, lexer.NextToken().kind); Assert.AreEqual(Tokens.Namespace, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestNarrowing()
{
ILexer lexer = GenerateLexer(new StringReader("Narrowing"));
Assert.AreEqual(Tokens.Narrowing, lexer.NextToken().kind);
}
[Test()]
public void TestNew() public void TestNew()
{ {
ILexer lexer = GenerateLexer(new StringReader("New")); ILexer lexer = GenerateLexer(new StringReader("New"));
@ -806,6 +860,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Object, lexer.NextToken().kind); Assert.AreEqual(Tokens.Object, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestOf()
{
ILexer lexer = GenerateLexer(new StringReader("Of"));
Assert.AreEqual(Tokens.Of, lexer.NextToken().kind);
}
[Test()]
public void TestOff() public void TestOff()
{ {
ILexer lexer = GenerateLexer(new StringReader("Off")); ILexer lexer = GenerateLexer(new StringReader("Off"));
@ -818,6 +878,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.On, lexer.NextToken().kind); Assert.AreEqual(Tokens.On, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestOperator()
{
ILexer lexer = GenerateLexer(new StringReader("Operator"));
Assert.AreEqual(Tokens.Operator, lexer.NextToken().kind);
}
[Test()]
public void TestOption() public void TestOption()
{ {
ILexer lexer = GenerateLexer(new StringReader("Option")); ILexer lexer = GenerateLexer(new StringReader("Option"));
@ -866,6 +932,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.ParamArray, lexer.NextToken().kind); Assert.AreEqual(Tokens.ParamArray, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestPartial()
{
ILexer lexer = GenerateLexer(new StringReader("Partial"));
Assert.AreEqual(Tokens.Partial, lexer.NextToken().kind);
}
[Test()]
public void TestPreserve() public void TestPreserve()
{ {
ILexer lexer = GenerateLexer(new StringReader("Preserve")); ILexer lexer = GenerateLexer(new StringReader("Preserve"));
@ -913,6 +985,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
ILexer lexer = GenerateLexer(new StringReader("ReDim")); ILexer lexer = GenerateLexer(new StringReader("ReDim"));
Assert.AreEqual(Tokens.ReDim, lexer.NextToken().kind); Assert.AreEqual(Tokens.ReDim, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestRemoveHandler() public void TestRemoveHandler()
{ {
@ -932,6 +1005,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Return, lexer.NextToken().kind); Assert.AreEqual(Tokens.Return, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestSByte()
{
ILexer lexer = GenerateLexer(new StringReader("SByte"));
Assert.AreEqual(Tokens.SByte, lexer.NextToken().kind);
}
[Test()]
public void TestSelect() public void TestSelect()
{ {
ILexer lexer = GenerateLexer(new StringReader("Select")); ILexer lexer = GenerateLexer(new StringReader("Select"));
@ -1052,12 +1131,30 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Try, lexer.NextToken().kind); Assert.AreEqual(Tokens.Try, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestTryCast()
{
ILexer lexer = GenerateLexer(new StringReader("TryCast"));
Assert.AreEqual(Tokens.TryCast, lexer.NextToken().kind);
}
[Test()]
public void TestTypeOf() public void TestTypeOf()
{ {
ILexer lexer = GenerateLexer(new StringReader("TypeOf")); ILexer lexer = GenerateLexer(new StringReader("TypeOf"));
Assert.AreEqual(Tokens.TypeOf, lexer.NextToken().kind); Assert.AreEqual(Tokens.TypeOf, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestUInteger()
{
ILexer lexer = GenerateLexer(new StringReader("UInteger"));
Assert.AreEqual(Tokens.UInteger, lexer.NextToken().kind);
}
[Test()]
public void TestULong()
{
ILexer lexer = GenerateLexer(new StringReader("ULong"));
Assert.AreEqual(Tokens.ULong, lexer.NextToken().kind);
}
[Test()]
public void TestUnicode() public void TestUnicode()
{ {
ILexer lexer = GenerateLexer(new StringReader("Unicode")); ILexer lexer = GenerateLexer(new StringReader("Unicode"));
@ -1070,6 +1167,18 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.Until, lexer.NextToken().kind); Assert.AreEqual(Tokens.Until, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestUShort()
{
ILexer lexer = GenerateLexer(new StringReader("UShort"));
Assert.AreEqual(Tokens.UShort, lexer.NextToken().kind);
}
[Test()]
public void TestUsing()
{
ILexer lexer = GenerateLexer(new StringReader("Using"));
Assert.AreEqual(Tokens.Using, lexer.NextToken().kind);
}
[Test()]
public void TestVariant() public void TestVariant()
{ {
ILexer lexer = GenerateLexer(new StringReader("Variant")); ILexer lexer = GenerateLexer(new StringReader("Variant"));
@ -1094,6 +1203,12 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Assert.AreEqual(Tokens.While, lexer.NextToken().kind); Assert.AreEqual(Tokens.While, lexer.NextToken().kind);
} }
[Test()] [Test()]
public void TestWidening()
{
ILexer lexer = GenerateLexer(new StringReader("Widening"));
Assert.AreEqual(Tokens.Widening, lexer.NextToken().kind);
}
[Test()]
public void TestWith() public void TestWith()
{ {
ILexer lexer = GenerateLexer(new StringReader("With")); ILexer lexer = GenerateLexer(new StringReader("With"));
@ -1117,119 +1232,5 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
ILexer lexer = GenerateLexer(new StringReader("Xor")); ILexer lexer = GenerateLexer(new StringReader("Xor"));
Assert.AreEqual(Tokens.Xor, lexer.NextToken().kind); Assert.AreEqual(Tokens.Xor, lexer.NextToken().kind);
} }
[Test()]
public void TestContinue()
{
ILexer lexer = GenerateLexer(new StringReader("Continue"));
Assert.AreEqual(Tokens.Continue, lexer.NextToken().kind);
}
[Test()]
public void TestOperator()
{
ILexer lexer = GenerateLexer(new StringReader("Operator"));
Assert.AreEqual(Tokens.Operator, lexer.NextToken().kind);
}
[Test()]
public void TestUsing()
{
ILexer lexer = GenerateLexer(new StringReader("Using"));
Assert.AreEqual(Tokens.Using, lexer.NextToken().kind);
}
[Test()]
public void TestIsNot()
{
ILexer lexer = GenerateLexer(new StringReader("IsNot"));
Assert.AreEqual(Tokens.IsNot, lexer.NextToken().kind);
}
[Test()]
public void TestSByte()
{
ILexer lexer = GenerateLexer(new StringReader("SByte"));
Assert.AreEqual(Tokens.SByte, lexer.NextToken().kind);
}
[Test()]
public void TestUInteger()
{
ILexer lexer = GenerateLexer(new StringReader("UInteger"));
Assert.AreEqual(Tokens.UInteger, lexer.NextToken().kind);
}
[Test()]
public void TestULong()
{
ILexer lexer = GenerateLexer(new StringReader("ULong"));
Assert.AreEqual(Tokens.ULong, lexer.NextToken().kind);
}
[Test()]
public void TestUShort()
{
ILexer lexer = GenerateLexer(new StringReader("UShort"));
Assert.AreEqual(Tokens.UShort, lexer.NextToken().kind);
}
[Test()]
public void TestCSByte()
{
ILexer lexer = GenerateLexer(new StringReader("CSByte"));
Assert.AreEqual(Tokens.CSByte, lexer.NextToken().kind);
}
[Test()]
public void TestCUShort()
{
ILexer lexer = GenerateLexer(new StringReader("CUShort"));
Assert.AreEqual(Tokens.CUShort, lexer.NextToken().kind);
}
[Test()]
public void TestCUInt()
{
ILexer lexer = GenerateLexer(new StringReader("CUInt"));
Assert.AreEqual(Tokens.CUInt, lexer.NextToken().kind);
}
[Test()]
public void TestCULng()
{
ILexer lexer = GenerateLexer(new StringReader("CULng"));
Assert.AreEqual(Tokens.CULng, lexer.NextToken().kind);
}
[Test()]
public void TestGlobal()
{
ILexer lexer = GenerateLexer(new StringReader("Global"));
Assert.AreEqual(Tokens.Global, lexer.NextToken().kind);
}
[Test()]
public void TestTryCast()
{
ILexer lexer = GenerateLexer(new StringReader("TryCast"));
Assert.AreEqual(Tokens.TryCast, lexer.NextToken().kind);
}
[Test()]
public void TestOf()
{
ILexer lexer = GenerateLexer(new StringReader("Of"));
Assert.AreEqual(Tokens.Of, lexer.NextToken().kind);
}
[Test()]
public void TestNarrowing()
{
ILexer lexer = GenerateLexer(new StringReader("Narrowing"));
Assert.AreEqual(Tokens.Narrowing, lexer.NextToken().kind);
}
[Test()]
public void TestWidening()
{
ILexer lexer = GenerateLexer(new StringReader("Widening"));
Assert.AreEqual(Tokens.Widening, lexer.NextToken().kind);
}
[Test()]
public void TestPartial()
{
ILexer lexer = GenerateLexer(new StringReader("Partial"));
Assert.AreEqual(Tokens.Partial, lexer.NextToken().kind);
}
[Test()]
public void TestCustom()
{
ILexer lexer = GenerateLexer(new StringReader("Custom"));
Assert.AreEqual(Tokens.Custom, lexer.NextToken().kind);
}
} }
} }

10
src/Libraries/NRefactory/Test/Parser/Expressions/AddressOfExpressionTests.cs

@ -38,6 +38,16 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("X", ((IdentifierExpression)ae.Expression).TypeArguments[0].Type); Assert.AreEqual("X", ((IdentifierExpression)ae.Expression).TypeArguments[0].Type);
} }
[Test]
public void MemberReferenceAddressOfExpressionTest()
{
AddressOfExpression ae = ParseUtilVBNet.ParseExpression<AddressOfExpression>("AddressOf Me.t(Of X)");
Assert.IsNotNull(ae);
Assert.IsInstanceOfType(typeof(MemberReferenceExpression), ae.Expression);
Assert.AreEqual("t", ((MemberReferenceExpression)ae.Expression).MemberName, "t");
Assert.IsInstanceOfType(typeof(ThisReferenceExpression), ((MemberReferenceExpression)ae.Expression).TargetObject);
}
#endregion #endregion
#region C# #region C#

45
src/Libraries/NRefactory/Test/Parser/Expressions/MemberReferenceExpressionTests.cs

@ -103,11 +103,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("SomeClass(of string).myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("SomeClass(of string).myField");
Assert.AreEqual("myField", fre.MemberName); Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsInstanceOfType(typeof(IdentifierExpression), fre.TargetObject);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; TypeReference tr = ((IdentifierExpression)fre.TargetObject).TypeArguments[0];
Assert.AreEqual("SomeClass", tr.Type); Assert.AreEqual("String", tr.Type);
Assert.AreEqual(1, tr.GenericTypes.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].SystemType);
} }
[Test] [Test]
@ -115,11 +113,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("System.Subnamespace.SomeClass(of string).myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("System.Subnamespace.SomeClass(of string).myField");
Assert.AreEqual("myField", fre.MemberName); Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsInstanceOfType(typeof(MemberReferenceExpression), fre.TargetObject);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("System.Subnamespace.SomeClass", tr.Type); MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject;
Assert.AreEqual(1, tr.GenericTypes.Count); Assert.AreEqual("SomeClass", inner.MemberName);
Assert.AreEqual("System.String", tr.GenericTypes[0].SystemType); Assert.AreEqual(1, inner.TypeArguments.Count);
Assert.AreEqual("System.String", inner.TypeArguments[0].SystemType);
} }
[Test] [Test]
@ -127,13 +126,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("Global.System.Subnamespace.SomeClass(of string).myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("Global.System.Subnamespace.SomeClass(of string).myField");
Assert.AreEqual("myField", fre.MemberName); Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsInstanceOfType(typeof(MemberReferenceExpression), fre.TargetObject);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference; MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject;
Assert.IsFalse(tr is InnerClassTypeReference);
Assert.AreEqual("System.Subnamespace.SomeClass", tr.Type); Assert.AreEqual("SomeClass", inner.MemberName);
Assert.AreEqual(1, tr.GenericTypes.Count); Assert.AreEqual(1, inner.TypeArguments.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].SystemType); Assert.AreEqual("System.String", inner.TypeArguments[0].SystemType);
Assert.IsTrue(tr.IsGlobal);
} }
[Test] [Test]
@ -141,15 +139,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("MyType(of string).InnerClass(of integer).myField"); MemberReferenceExpression fre = ParseUtilVBNet.ParseExpression<MemberReferenceExpression>("MyType(of string).InnerClass(of integer).myField");
Assert.AreEqual("myField", fre.MemberName); Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression); Assert.IsInstanceOfType(typeof(MemberReferenceExpression), fre.TargetObject);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("InnerClass", ic.Type); MemberReferenceExpression inner = (MemberReferenceExpression)fre.TargetObject;
Assert.AreEqual(1, ic.GenericTypes.Count); Assert.AreEqual("InnerClass", inner.MemberName);
Assert.AreEqual("System.Int32", ic.GenericTypes[0].SystemType);
Assert.AreEqual("MyType", ic.BaseType.Type);
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count);
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].SystemType);
} }
#endregion #endregion
} }
} }

Loading…
Cancel
Save