Skip to content

Commit

Permalink
[VB] Minor update API generating and preprocessor highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 12, 2024
1 parent e3e439d commit 988f66a
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 55 deletions.
24 changes: 11 additions & 13 deletions scintilla/lexers/LexVB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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")) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 1 addition & 2 deletions scintilla/lexlib/CharacterSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 20 additions & 15 deletions src/EditLexers/stlVB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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
Expand All @@ -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 "
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/EditLexers/stlVBS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static KEYWORDLIST Keywords_VBS = {{
, // 1 type keyword
nullptr

, // 2 vba keyword
, // 2 VBA keyword
nullptr

, // 3 preprocessor
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/KeywordCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion tools/lang/VB.NET.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions tools/lang/VBA.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -188,7 +189,7 @@ Dictionary {
Key(key)
}

Drive {
{ ' Drive
AvailableSpace
DriveLetter
DriveType
Expand All @@ -213,7 +214,7 @@ Err {
Source
}

File {
{ ' File
Copy()
Delete()
Move()
Expand Down Expand Up @@ -262,15 +263,15 @@ FileSystemObject {
Drives
}

Folder {
{ ' Folder
Add()

Files
IsRootFolder
SubFolders
}

TextStream {
{ ' TextStream
Close()
Read(characters)
ReadAll()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 21 additions & 13 deletions tools/lang/VBScript.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -170,7 +178,7 @@ FileSystemObject {
OpenTextFile(filename[, iomode[, create[, format]]])
}

TextStream {
{ ' TextStream
AtEndOfLine
AtEndOfStream
Column
Expand Down

0 comments on commit 988f66a

Please sign in to comment.