From 8671ab60c2958b203c0b01bde5956cf32a1c8206 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 8 Jul 2010 08:28:33 +0000 Subject: [PATCH] - added keywords to CC - added some snippets git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@6068 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Snippets/SnippetManager.cs | 39 ++++++++++++++++++- .../Src/Lexer/VBNet/ExpressionFinder.atg | 2 +- .../Project/Src/Lexer/VBNet/KeywordList.txt | 7 +++- .../Project/Src/Lexer/VBNet/Parser.cs | 12 +++--- .../Project/Src/Lexer/VBNet/Tokens.cs | 7 +++- .../NRefactoryResolver/NRefactoryResolver.cs | 2 + .../Src/VBNet/VBNetExpressionFinder.cs | 2 + 7 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs index b60b3fd3ff..e903c9250d 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs @@ -84,8 +84,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets Description = "Switch statement", // dynamic switch snippet (inserts switch body dependent on condition) Text = "switch (${condition}) {\n\t${refactoring:switchbody}\n}" - // static switch snippet (always inserts the same, independent of condition) - //Text = "switch (${condition}) {\n\tcase ${firstcase=0}:\n\t\t${Caret}\n\t\tbreak;\n\tdefault:\n\t\t${Selection}\n\t\tbreak;\n}" + // static switch snippet (always inserts the same, independent of condition) + //Text = "switch (${condition}) {\n\tcase ${firstcase=0}:\n\t\t${Caret}\n\t\tbreak;\n\tdefault:\n\t\t${Selection}\n\t\tbreak;\n}" }, new CodeSnippet { Name = "try", @@ -103,6 +103,41 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets Text = "try {\n\t${Selection}\n} finally {\n\t${Caret}\n}" }, } + }, + new CodeSnippetGroup { + Extensions = ".vb", + Snippets = { + new CodeSnippet { + Name = "If", + Description = "If statement", + Text = "If ${condition} Then\n" + + "\t${Selection}\n" + + "End If" + }, + new CodeSnippet { + Name = "IfElse", + Description = "If-Else statement", + Text = "If ${condition} Then\n" + + "\t${Selection}\n" + + "Else\n" + + "\t${Caret}\n" + + "End If" + }, + new CodeSnippet { + Name = "For", + Description = "For loop", + Text = "For ${counter=i} As ${type=Integer} = ${start=0} To ${end}\n" + + "\t${Selection}\n" + + "Next ${counter}" + }, + new CodeSnippet { + Name = "ForStep", + Description = "For loop with Step", + Text = "For ${counter=i} As ${type=Integer} = ${start=0} To ${end} Step ${step=1}\n" + + "\t${Selection}\n" + + "Next ${counter}" + } + } } }; diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg index c318dff539..c44fe8ed51 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg +++ b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg @@ -296,7 +296,7 @@ NamespaceMemberDeclaration = . NamespaceDeclaration = - "Namespace" { ANY } StatementTerminator + "Namespace" (. PushContext(Context.IdentifierExpected, la, t); .) { ANY } (. PopContext(); .) StatementTerminator { NamespaceMemberDeclaration } "End" "Namespace" StatementTerminator . diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt index 07f399e4ab..dee2aab408 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt +++ b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt @@ -274,6 +274,11 @@ TypeLevel("Sub", "Function", "Property") # List of keywords that are valid identifiers, must be the same as the "Identifier" production in VBNET.ATG IdentifierTokens("Text", "Binary", "Compare", "Assembly", "Ansi", "Auto", "Preserve", "Unicode", "Until", "Off", "Out", "Key", "Explicit", "Infer", "From", "Join", "Equals", "Distinct", "Where", "Take", "Skip", "Order", "By", "Ascending", "Descending", "Group", "Into", "Aggregate") -ExpressionStart("Me", "MyBase", "MyClass", "False", "New", "Nothing", "True", "GetType") +ExpressionStart("Me", "MyBase", "MyClass", @BooleanExpressions, @OperatorsAtStart, "New", @Null, "AddressOf", "GetType", "TypeOf", "GetXmlNamespace", "Global", @TypeKW, @LambdaStart, @CastExpressions) +StatementStart(@Null, @ExpressionStart, "Dim", "Const", "Static", "For", "While", "Do", "Select") SimpleTypeName(@TypeKW, @IdentifierTokens) +CastExpressions("DirectCast", "TryCast", "CType", "CBool", "CByte", "CChar", "CDate", "CDec", "CDbl", "CInt", "CLng", "CObj", "CSByte", "CShort", "CSng", "CStr", "CUInt", "CULng", "CUShort") +BooleanExpressions("True", "False") +LambdaStart("Sub", "Function") +OperatorsAtStart("Not", "From", "Aggregate") TypeKW("Boolean", "Date", "Char", "String", "Decimal", "Byte", "Short", "Integer", "Long", "Single", "Double", "UInteger", "ULong", "UShort", "SByte") \ No newline at end of file diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs index 7139b28764..d168da0a64 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs @@ -104,7 +104,8 @@ partial class ExpressionFinder { case 5: { if (la == null) { currentState = 5; break; } if (la.kind == 160) { - goto case 446; + currentState = 446; + break; } else { if (set[1, la.kind]) { goto case 7; @@ -3475,15 +3476,16 @@ partial class ExpressionFinder { } } case 446: { - if (la == null) { currentState = 446; break; } - currentState = 447; - break; + PushContext(Context.IdentifierExpected, la, t); + goto case 447; } case 447: { if (la == null) { currentState = 447; break; } if (set[26, la.kind]) { - goto case 446; + currentState = 447; + break; } else { + PopContext(); stateStack.Push(448); goto case 15; } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs index 3ab479863e..9b49a86213 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs @@ -264,8 +264,13 @@ namespace ICSharpCode.NRefactory.Parser.VB public static BitArray GlobalLevel = NewSet(Namespace, Module, Class, Structure, Imports, Option); public static BitArray TypeLevel = NewSet(Sub, Function, Property); public static BitArray IdentifierTokens = NewSet(Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Off, Out, Key, Explicit, Infer, From, Join, Equals, Distinct, Where, Take, Skip, Order, By, Ascending, Descending, Group, Into, Aggregate); - public static BitArray ExpressionStart = NewSet(Me, MyBase, MyClass, False, New, Nothing, True, GetType); + public static BitArray ExpressionStart = NewSet(Me, MyBase, MyClass, True, False, Not, From, Aggregate, New, Nothing, AddressOf, GetType, TypeOf, GetXmlNamespace, Global, Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Sub, Function, DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort); + public static BitArray StatementStart = NewSet(Nothing, Me, MyBase, MyClass, True, False, Not, From, Aggregate, New, Nothing, AddressOf, GetType, TypeOf, GetXmlNamespace, Global, Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Sub, Function, DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort, Dim, Const, Static, For, While, Do, Select); public static BitArray SimpleTypeName = NewSet(Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Off, Out, Key, Explicit, Infer, From, Join, Equals, Distinct, Where, Take, Skip, Order, By, Ascending, Descending, Group, Into, Aggregate); + public static BitArray CastExpressions = NewSet(DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort); + public static BitArray BooleanExpressions = NewSet(True, False); + public static BitArray LambdaStart = NewSet(Sub, Function); + public static BitArray OperatorsAtStart = NewSet(Not, From, Aggregate); public static BitArray TypeKW = NewSet(Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte); static string[] tokenList = new string[] { diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs index 36d0ef4881..854049cb7a 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs @@ -1153,6 +1153,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver AddVBNetKeywords(result, NR.Parser.VB.Tokens.TypeLevel); } else if (context == ExpressionContext.Global) { AddVBNetKeywords(result, NR.Parser.VB.Tokens.GlobalLevel); + } else if (context == ExpressionContext.MethodBody) { + AddVBNetKeywords(result, NR.Parser.VB.Tokens.StatementStart); } else { AddVBNetPrimitiveTypes(result); CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs index e14cd7b952..380f25fe4e 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs @@ -129,6 +129,8 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet return ExpressionContext.IdentifierExpected; case Context.Type: return ExpressionContext.TypeDeclaration; + case Context.Body: + return ExpressionContext.MethodBody; } return ExpressionContext.Default;