diff --git a/scintilla/lexers/LexVB.cxx b/scintilla/lexers/LexVB.cxx index e76e2569e5..5b92d8adf2 100644 --- a/scintilla/lexers/LexVB.cxx +++ b/scintilla/lexers/LexVB.cxx @@ -55,7 +55,7 @@ enum { enum { KeywordIndex_Keyword = 0, KeywordIndex_TypeKeyword = 1, - KeywordIndex_VbaKeyword = 2, + KeywordIndex_VBAKeyword = 2, KeywordIndex_Preprocessor = 3, KeywordIndex_Attribute = 4, KeywordIndex_Class = 5, @@ -88,15 +88,6 @@ constexpr bool IsVBNumberPrefix(int ch) noexcept { || ch == 'b';// Binary } -constexpr bool IsPreprocessorStart(int ch) noexcept { - ch = UnsafeLower(ch); - return ch == 'c' // Const - || ch == 'd' // Disable - || ch == 'e' // End - || ch == 'i' // If - || ch == 'r';// Region -} - constexpr bool PreferStringConcat(int chPrevNonWhite, int stylePrevNonWhite) noexcept { return chPrevNonWhite == '\"' || chPrevNonWhite == ')' || chPrevNonWhite == ']' || (stylePrevNonWhite != SCE_VB_KEYWORD && IsIdentifierChar(chPrevNonWhite)); @@ -119,6 +110,7 @@ inline bool IsInterpolatedStringEnd(const StyleContext &sc) noexcept { void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, LexerWordList keywordLists, Accessor &styler) { KeywordType kwType = KeywordType::None; + bool preprocessor = false; int lineState = 0; int parenCount = 0; int fileNbDigits = 0; @@ -178,8 +170,9 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl kwType = KeywordType::None; if (s[0] == '#') { if (keywordLists[KeywordIndex_Preprocessor].InList(s + 1)) { + preprocessor = true; sc.ChangeState(SCE_VB_PREPROCESSOR); - if (StrEqualsAny(s + 1, "if", "end", "elseif")) { + if (StrEqual(s + 1, "end")) { kwType = KeywordType::Preprocessor; } } else { @@ -199,6 +192,10 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl if (language == Language::VBNET && chNext == '(' && (parenCount != 0 || visibleChars > 2)) { sc.ChangeState(SCE_VB_KEYWORD3); // If operator } + } else if (StrEqual(s, "then")) { + if (preprocessor) { + sc.ChangeState(SCE_VB_PREPROCESSOR_WORD); + } } else if (StrEqual(s, "dim")) { lineState = VBLineType_DimLine; } else if (StrEqual(s, "const")) { @@ -217,7 +214,7 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl kwType = KeywordType::AccessModifier; } } - } else if (keywordLists[KeywordIndex_VbaKeyword].InList(s)) { + } else if (keywordLists[KeywordIndex_VBAKeyword].InList(s)) { sc.ChangeState(SCE_VB_KEYWORD3); if (language == Language::VBA && !skipType && chBefore != '.') { sc.ChangeState(SCE_VB_KEYWORD); @@ -363,7 +360,7 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl sc.SetState(SCE_VB_INTERPOLATED_STRING); sc.Forward(); } else if (sc.ch == '#') { - if (visibleChars == 0 && language != Language::VBScript && IsPreprocessorStart(sc.chNext)) { + if (visibleChars == 0 && language != Language::VBScript && IsUpperOrLowerCase(sc.chNext)) { sc.SetState(SCE_VB_IDENTIFIER); } else { fileNbDigits = 0; @@ -417,6 +414,7 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl lineState &= VBLineStateLineContinuation; visibleChars = 0; kwType = KeywordType::None; + preprocessor = false; } sc.Forward(); } diff --git a/scintilla/lexlib/CharacterSet.h b/scintilla/lexlib/CharacterSet.h index fb0eb60d20..101e34073d 100644 --- a/scintilla/lexlib/CharacterSet.h +++ b/scintilla/lexlib/CharacterSet.h @@ -303,8 +303,7 @@ constexpr bool IsUpperCase(int ch) noexcept { } constexpr bool IsUpperOrLowerCase(int ch) noexcept { - return (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z'); + return IsLowerCase(UnsafeLower(ch)); } constexpr bool IsAlpha(int ch) noexcept { diff --git a/src/EditLexers/stlVB.cpp b/src/EditLexers/stlVB.cpp index 92318125f2..ee9a6c6679 100644 --- a/src/EditLexers/stlVB.cpp +++ b/src/EditLexers/stlVB.cpp @@ -21,7 +21,7 @@ static KEYWORDLIST Keywords_VB = {{ "Any Boolean Byte Char Currency Date Decimal Double Integer Long LongLong LongPtr Object SByte Short Single String " "UInteger ULong UShort Variant " -, // 2 vba keyword +, // 2 VBA keyword "Access Attribute Base Begin BeginProperty Close " "Database DefBool DefByte DefCur DefDate DefDbl DefDec DefInt DefLng DefLngLng DefLngPtr DefObj DefSng DefStr DefVar " "Empty EndIf EndProperty Eqv GoSub Imp Line Load Name Null Open PtrSafe Put SavePicture SendKeys Type Unload Version " @@ -35,8 +35,8 @@ static KEYWORDLIST Keywords_VB = {{ "Serializable( StructLayout( VBFixedArray( VBFixedString( " , // 5 class -"Collection Console ControlChars Conversion DateAndTime Debug Dictionary Drive Err ErrObject " -"File FileSystem FileSystemObject Financial Folder Information Interaction Math Strings TextStream VBMath " +"Collection Console ControlChars Conversion DateAndTime Debug Dictionary Err ErrObject " +"FileSystem FileSystemObject Financial Information Interaction Math Strings VBMath " , // 6 interface nullptr @@ -56,7 +56,7 @@ nullptr "vbGeneralDate vbGet vbGreen vbHidden vbHide vbHiragana vbIgnore vbInformation vbInteger vbKatakana " "vbLet vbLf vbLinguisticCasing vbLong vbLongDate vbLongLong vbLongTime vbLowerCase vbMagenta vbMaximizedFocus vbMethod " "vbMinimizedFocus vbMinimizedNoFocus vbModal vbModeless vbMonday " -"vbMsgBoxHelp vbMsgBoxHelpButton vbMsgBoxRight vbMsgBoxRtlReading VbMsgBoxSetForeground " +"vbMsgBoxHelp vbMsgBoxHelpButton vbMsgBoxRight vbMsgBoxRtlReading vbMsgBoxSetForeground " "vbNarrow vbNewLine vbNo vbNormal vbNormalFocus vbNormalNoFocus vbNull vbNullChar vbNullString " "vbObject vbObjectError vbOK vbOKCancel vbOKOnly vbProperCase vbQuestion vbReadOnly vbRed vbRetry vbRetryCancel " "vbSaturday vbSet vbShortDate vbShortTime vbSimplifiedChinese vbSingle vbString vbSunday vbSystem vbSystemModal " @@ -86,16 +86,21 @@ nullptr "Val( VarType( VbTypeName( Weekday( WeekdayName( Write( WriteLine( Year( " , // 10 misc -"Add( Assert( AtEndOfLine AtEndOfStream Attributes AvailableSpace BuildPath( " -"Clear( Close( Column CompareMode Copy( CopyFile( CopyFolder( Count CreateFolder( CreateTextFile( " -"DateCreated DateLastAccessed DateLastModified Delete( DeleteFile( DeleteFolder( Description " -"DriveExists( DriveLetter DriveType Drives " -"Exists( FileExists( Files FolderExists( FreeSpace " -"GetAbsolutePathName( GetBaseName( GetDrive( GetDriveName( GetExtensionName( GetFile( GetFileName( GetFolder( " -"GetParentFolderName( GetSpecialFolder( GetTempName( " -"HelpContext HelpFile IsReady IsRootFolder Item( Items( Key( Keys( Move( MoveFile( MoveFolder( Number " -"OpenAsTextStream( OpenTextFile( ParentFolder Path Raise( Read( ReadAll( ReadLine( Remove( RemoveAll( RootFolder " -"SerialNumber ShareName ShortName ShortPath Size Skip( SkipLine( Source SubFolders TotalSize VolumeName WriteBlankLines( " +"Acos( Acosh( Add( Asin( Asinh( Assert( AtEndOfLine AtEndOfStream Atan( Atan2( Atanh( Attributes AvailableSpace " +"BigMul( BitDecrement( BitIncrement( BuildPath( " +"Calendar Cbrt( Ceiling( Clamp( Clear( Close( " +"Column CompareMode Contains( Copy( CopyFile( CopyFolder( CopySign( Cosh( Count CreateFolder( CreateTextFile( " +"DateCreated DateLastAccessed DateLastModified Delete( DeleteFile( DeleteFolder( Description DivRem( " +"Drive DriveExists( DriveLetter DriveType Drives " +"Exists( FileExists( Files Floor( FolderExists( FreeSpace FusedMultiplyAdd( " +"GetAbsolutePathName( GetBaseName( GetDrive( GetDriveName( GetEnumerator( GetException( GetExtensionName( " +"GetFile( GetFileName( GetFolder( GetParentFolderName( GetSpecialFolder( GetTempName( " +"HelpContext HelpFile Hide( IEEERemainder( ILogB( IsReady IsRootFolder Item( Items( Key( Keys( LastDllError Log10( Log2( " +"Max( MaxMagnitude( Min( MinMagnitude( Move( MoveFile( MoveFolder( Number OpenAsTextStream( OpenTextFile( " +"ParentFolder Path Pow( PrintForm( Raise( Read( ReadAll( ReadLine( Remove( RemoveAll( RightToLeft RootFolder " +"ScaleB( SerialNumber ShareName ShortName ShortPath Show( ShowModal Sign( Sinh( Size Skip( SkipLine( Source Sqrt( " +"StartUpPosition SubFolders " +"Tanh( TotalSize Truncate( VolumeName WriteBlankLines( " , nullptr, nullptr, nullptr, nullptr, nullptr //--Autogenerated -- end of section automatically generated @@ -136,7 +141,7 @@ EDITLEXER lexVisualBasic = { SCE_VB_OPERATOR, SCE_VB_OPERATOR2 , KeywordAttr32(0, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // keywords | KeywordAttr32(1, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // type keyword - | KeywordAttr32(2, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // vba keyword + | KeywordAttr32(2, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // VBA keyword | KeywordAttr32(3, KeywordAttr_MakeLower | KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // preprocessor | KeywordAttr32(4, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // attribute | KeywordAttr32(5, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // class diff --git a/src/EditLexers/stlVBS.cpp b/src/EditLexers/stlVBS.cpp index b79714a4b5..0fc4613158 100644 --- a/src/EditLexers/stlVBS.cpp +++ b/src/EditLexers/stlVBS.cpp @@ -15,7 +15,7 @@ static KEYWORDLIST Keywords_VBS = {{ , // 1 type keyword nullptr -, // 2 vba keyword +, // 2 VBA keyword nullptr , // 3 preprocessor @@ -25,7 +25,7 @@ nullptr nullptr , // 5 class -"ActiveXObject Debug Dictionary Err FileSystemObject RegExp TextStream WScript " +"ActiveXObject Debug Dictionary Err FileSystemObject RegExp WScript " , // 6 interface nullptr @@ -97,7 +97,7 @@ EDITLEXER lexVBScript = { SCE_VB_OPERATOR, SCE_VB_OPERATOR2 , KeywordAttr32(0, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // keywords | KeywordAttr32(1, KeywordAttr_MakeLower) // type keyword - | KeywordAttr32(2, KeywordAttr_MakeLower) // vba keyword + | KeywordAttr32(2, KeywordAttr_MakeLower) // VBA keyword | KeywordAttr32(3, KeywordAttr_MakeLower | KeywordAttr_NoAutoComp) // preprocessor | KeywordAttr32(4, KeywordAttr_MakeLower) // attribute | KeywordAttr32(5, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // class diff --git a/tools/KeywordCore.py b/tools/KeywordCore.py index b09f669e3c..5ad2bfbb3c 100644 --- a/tools/KeywordCore.py +++ b/tools/KeywordCore.py @@ -2571,7 +2571,7 @@ def parse_visual_basic_api_file(pathList): items = re.findall(r'#(\w+)', doc) elif key == 'objects': items = re.findall(r'^\s+(\w+\(?)', doc, re.MULTILINE) - keywordMap['misc'] = items + keywordMap['misc'].extend(items) items = re.findall(r'^(\w+)\s*\{', doc, re.MULTILINE) elif key == 'functions': items = re.findall(r'^(\w+\(?)', doc, re.MULTILINE) @@ -2600,7 +2600,7 @@ def parse_visual_basic_api_file(pathList): return [ ('keywords', keywordMap['keywords'], KeywordAttr.MakeLower), ('type keyword', keywordMap['types'], KeywordAttr.MakeLower), - ('vba keyword', keywordMap['vba keywords'], KeywordAttr.MakeLower), + ('VBA keyword', keywordMap['vba keywords'], KeywordAttr.MakeLower), ('preprocessor', keywordMap['directives'], KeywordAttr.MakeLower | KeywordAttr.NoAutoComp | KeywordAttr.Special), ('attribute', keywordMap['attributes'], KeywordAttr.MakeLower), ('class', keywordMap['objects'], KeywordAttr.MakeLower), diff --git a/tools/lang/VB.NET.vb b/tools/lang/VB.NET.vb index bd61ff69f3..bdfa0d1438 100644 --- a/tools/lang/VB.NET.vb +++ b/tools/lang/VB.NET.vb @@ -523,7 +523,7 @@ vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel vbCritical vbQuestion vbExclamation vbInformation vbDefaultButton1 vbDefaultButton2 vbDefaultButton3 vbApplicationModal vbSystemModal -VbMsgBoxSetForeground vbMsgBoxHelp vbMsgBoxRight vbMsgBoxRtlReading +vbMsgBoxSetForeground vbMsgBoxHelp vbMsgBoxRight vbMsgBoxRtlReading ' MsgBoxResult vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo ' TriState diff --git a/tools/lang/VBA.bas b/tools/lang/VBA.bas index 0dd7cc0b57..7f28921986 100644 --- a/tools/lang/VBA.bas +++ b/tools/lang/VBA.bas @@ -131,7 +131,7 @@ False True AddressOf And Eqv Imp Is Like Mod Not Or Xor ' VB6 -Attribute Version +Class Attribute Version Begin BeginProperty EndProperty @@ -162,6 +162,7 @@ Any #EndIf '! objects ======================================================= +' https://learn.microsoft.com/en-us/office/vba/language/reference/objects-visual-basic-for-applications Collection { Add() Item(index) @@ -188,7 +189,7 @@ Dictionary { Key(key) } -Drive { +{ ' Drive AvailableSpace DriveLetter DriveType @@ -213,7 +214,7 @@ Err { Source } -File { +{ ' File Copy() Delete() Move() @@ -262,7 +263,7 @@ FileSystemObject { Drives } -Folder { +{ ' Folder Add() Files @@ -270,7 +271,7 @@ Folder { SubFolders } -TextStream { +{ ' TextStream Close() Read(characters) ReadAll() @@ -287,6 +288,17 @@ TextStream { Line } +{ ' UserForm + Hide() + PrintForm() + Show() + + Calendar + RightToLeft + ShowModal + StartUpPosition +} + '! functions ======================================================= ' https://learn.microsoft.com/en-us/office/vba/language/reference/functions-visual-basic-for-applications ' https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/returning-strings-from-functions @@ -483,7 +495,7 @@ vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel vbCritical vbQuestion vbExclamation vbInformation vbDefaultButton1 vbDefaultButton2 vbDefaultButton3 vbDefaultButton4 vbApplicationModal vbSystemModal -vbMsgBoxHelpButton VbMsgBoxSetForeground vbMsgBoxRight vbMsgBoxRtlReading +vbMsgBoxHelpButton vbMsgBoxSetForeground vbMsgBoxRight vbMsgBoxRtlReading vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo ' QueryClose constants vbFormControlMenu vbFormCode vbAppWindows vbAppTaskManager diff --git a/tools/lang/VBScript.vbs b/tools/lang/VBScript.vbs index 5c09f7d898..2200bfd3ef 100644 --- a/tools/lang/VBScript.vbs +++ b/tools/lang/VBScript.vbs @@ -71,24 +71,32 @@ Not And Or Xor Eqv Imp Is Mod ' Keywords https://learn.microsoft.com/en-us/previous-versions/f8tbc79x(v=vs.85) Empty False Nothing Null True -' types -Boolean Byte Char Currency Date Decimal Double Integer Long LongLong LongPtr Object Single String Variant - -' others -Alias As Attribute Begin -Compare Continue -Declare +' reserved types +Boolean Byte Currency Date Double Integer Long Single String Variant +' other types +Char Decimal LongLong LongPtr Object + +' reserved words https://flylib.com/books/en/2.442.1/vbscript_basics.html +' https://isvbscriptdead.com/reserved-keywords/ +As EndIf Enum Event -Friend -Global GoSub Implements -Lib Like Load LSet -Me Module +Like LSet +Me Optional ParamArray -RaiseEvent Return RSet +RaiseEvent RSet Shared Static Type TypeOf +' other words +Alias Attribute Begin +Compare Continue +Declare +Friend +Global GoSub +Lib Load +Module +Return Unload WithEvents @@ -170,7 +178,7 @@ FileSystemObject { OpenTextFile(filename[, iomode[, create[, format]]]) } -TextStream { +{ ' TextStream AtEndOfLine AtEndOfStream Column