Skip to content

Commit

Permalink
Add script to generate API for VB.NET, VBA and VBScript, issue #735.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 11, 2024
1 parent 97b091b commit e3e439d
Show file tree
Hide file tree
Showing 10 changed files with 1,649 additions and 154 deletions.
51 changes: 35 additions & 16 deletions scintilla/lexers/LexVB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,24 @@ enum {
VBLineType_VB6TypeLine = 4,
VBLineStateLineContinuation = 1 << 3,
VBLineStateStringInterpolation = 1 << 4,
MaxKeywordSize = 64,
};

//KeywordIndex++Autogenerated -- start of section automatically generated
enum {
KeywordIndex_Keyword = 0,
KeywordIndex_TypeKeyword = 1,
KeywordIndex_VbaKeyword = 2,
KeywordIndex_Preprocessor = 3,
KeywordIndex_Attribute = 4,
KeywordIndex_Class = 5,
KeywordIndex_Interface = 6,
KeywordIndex_Enumeration = 7,
KeywordIndex_Constant = 8,
KeywordIndex_BasicFunction = 9,
MaxKeywordSize = 32,
};
//KeywordIndex--Autogenerated -- end of section automatically generated

#define LexCharAt(pos) styler.SafeGetCharAt(pos)

// https://learn.microsoft.com/en-us/dotnet/visual-basic/reference/language-specification/lexical-grammar#type-characters
Expand Down Expand Up @@ -103,13 +118,6 @@ inline bool IsInterpolatedStringEnd(const StyleContext &sc) noexcept {
}

void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, LexerWordList keywordLists, Accessor &styler) {
const WordList &keywords = keywordLists[0];
const WordList &keywords2 = keywordLists[1];
const WordList &keywords3 = keywordLists[2];
const WordList &keywords4 = keywordLists[3];
const WordList &keywords5 = keywordLists[4];
const WordList &keywords6 = keywordLists[5];

KeywordType kwType = KeywordType::None;
int lineState = 0;
int parenCount = 0;
Expand Down Expand Up @@ -169,7 +177,7 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
const KeywordType kwPrev = kwType;
kwType = KeywordType::None;
if (s[0] == '#') {
if (keywords4.InList(s + 1)) {
if (keywordLists[KeywordIndex_Preprocessor].InList(s + 1)) {
sc.ChangeState(SCE_VB_PREPROCESSOR);
if (StrEqualsAny(s + 1, "if", "end", "elseif")) {
kwType = KeywordType::Preprocessor;
Expand All @@ -183,7 +191,7 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
} else {
const int chNext = sc.GetLineNextChar();
if (s[0] != '[') {
if (keywords.InList(s)) {
if (keywordLists[KeywordIndex_Keyword].InListPrefixed(s, '(')) {
sc.ChangeState(SCE_VB_KEYWORD3);
if (!skipType && chBefore != '.') {
sc.ChangeState(SCE_VB_KEYWORD);
Expand All @@ -209,14 +217,25 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
kwType = KeywordType::AccessModifier;
}
}
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_VB_KEYWORD2);
} else if (keywords3.InList(s)) {
} else if (keywordLists[KeywordIndex_VbaKeyword].InList(s)) {
sc.ChangeState(SCE_VB_KEYWORD3);
} else if (keywords5.InList(s)) {
if (language == Language::VBA && !skipType && chBefore != '.') {
sc.ChangeState(SCE_VB_KEYWORD);
}
} else if (keywordLists[KeywordIndex_TypeKeyword].InList(s)) {
sc.ChangeState(SCE_VB_KEYWORD2);
} else if (keywordLists[KeywordIndex_Class].InList(s)) {
sc.ChangeState(SCE_VB_CLASS);
} else if (keywordLists[KeywordIndex_Interface].InList(s)) {
sc.ChangeState(SCE_VB_INTERFACE);
} else if (keywordLists[KeywordIndex_Enumeration].InList(s)) {
sc.ChangeState(SCE_VB_ENUM);
} else if (keywordLists[KeywordIndex_Attribute].InListPrefixed(s, '(')) {
sc.ChangeState(SCE_VB_ATTRIBUTE);
} else if (keywords6.InList(s)) {
} else if (keywordLists[KeywordIndex_Constant].InList(s)) {
sc.ChangeState(SCE_VB_CONSTANT);
} else if (keywordLists[KeywordIndex_BasicFunction].InListPrefixed(s, '(')) {
sc.ChangeState(SCE_VB_BASIC_FUNCTION);
}
}
if (sc.state == SCE_VB_IDENTIFIER) {
Expand Down Expand Up @@ -583,7 +602,7 @@ void FoldVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le
if (isEnd) isEnd = false;
}
}
else if (style == SCE_VB_PREPROCESSOR && ch == '#') {
else if (style == SCE_VB_PREPROCESSOR && stylePrev != SCE_VB_PREPROCESSOR) {
if (VBMatch("#if") || VBMatch("#region") || VBMatch("#externalsource"))
levelNext++;
else if (VBMatch("#end"))
Expand Down
14 changes: 8 additions & 6 deletions src/EditLexers/stlHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ static KEYWORDLIST Keywords_HTML = {{
"this throw true try typeof undefined var void while with yield "

, // 2 VBScript
"Alias And As Attribute Begin Boolean ByRef Byte ByVal Call Case Class Compare Const Continue "
"Currency Date Declare Dim Do Double Each Else ElseIf Empty End Enum Eqv Erase Error Event Exit "
"Explicit False For Friend Function Get Global GoSub Goto If Imp Implement In Integer Is Let Lib "
"Load Long Loop LSet Me Mid Mod Module New Next Not Nothing Null Object On Option Optional Or "
"Preserve Private Property Public RaiseEvent ReDim Rem Resume Return RSet Select Set Single "
"Static Stop String Sub Then To True Type Unload Until Variant WEnd While With WithEvents Xor"
"Alias And As Attribute Begin Boolean ByRef Byte ByVal Call Case Char Class Compare Const Continue Currency "
"Decimal Declare Default Dim Do Double "
"Each Else ElseIf Empty End EndIf Enum Eqv Erase Error Event Execute ExecuteGlobal Exit Explicit "
"False For Friend Function Get Global GoSub GoTo If Imp Implements In Integer Is "
"Let Lib Like Load Long LongLong LongPtr Loop LSet Me Mod Module New Next Not Nothing Null Object On Option Optional Or "
"ParamArray Preserve Private Property Public RaiseEvent Randomize ReDim Rem Resume Return RSet "
"Select Set Shared Single Static Step Stop String Sub Then To True Type TypeOf Unload Until Variant "
"Wend While With WithEvents Xor "

, // 3 Python
nullptr
Expand Down
169 changes: 104 additions & 65 deletions src/EditLexers/stlVB.cpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,104 @@
#include "EditLexer.h"
#include "EditStyleX.h"

// Visual Basic Language Reference
// https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/
// https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/keywords/
// https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/runtime-library-members

static KEYWORDLIST Keywords_VB = {{
"AddHandler AddressOf Alias And AndAlso As ByRef ByVal Call Case Catch Class Const Continue "
"Declare Default Delegate Dim DirectCast Do Each Else ElseIf End Enum Erase Error Event Exit "
"False Finally For Friend Function Get GetType GetXMLNamespace Global Goto Handles If Implements "
"Imports In Inherits Interface Is IsNot Let Lib Like Loop Me Mod Module MustInherit MustOverride "
"My MyBase MyClass NameOf Namespace Narrowing New Next Not Nothing NotInheritable NotOverridable Of On "
"Operator Option Optional Or OrElse Out Overloads Overridable Overrides ParamArray Partial Private "
"Property Protected Public RaiseEvent Readonly ReDim Rem RemoveHandler Resume Return Select Set "
"Shadows Shared Static Step Stop Structure Sub SyncLock Then Throw To True Try TryCast TypeOf Using "
"When While Widening With WithEvents WriteOnly Xor "
// Unreserved Keyword
"Aggregate Ansi Assembly Async Attribute Auto Await Binary By Compare Custom Distinct Equals Explicit "
"From Group Into IsFalse IsTrue Iterator Join Key Mid Off Order Preserve Skip Strict Take Text Unicode Until Where Yield "
//++Autogenerated -- start of section automatically generated
"AddHandler AddHandler( AddressOf Aggregate Alias And AndAlso Ansi As Assembly Async Auto Await Binary By ByRef ByVal "
"Call Case Catch Class Compare Const Continue Custom Declare Default Delegate Dim DirectCast Distinct Do "
"Each Else ElseIf End Enum Equals Erase Error Event Exit Explicit False Finally For Friend From Function "
"Get GetType( GetXMLNamespace( Global GoTo Group Handles "
"If If( Implements Imports In Infer Inherits Interface Into Is IsFalse( IsNot IsTrue( Iterator Join Key "
"Let Lib Like Loop Me Mod Module MustInherit MustOverride My MyBase MyClass "
"NameOf( Namespace Narrowing New Next Not Nothing NotInheritable NotOverridable "
"Of Off On Operator Option Optional Or Order OrElse Out Overloads Overridable Overrides "
"ParamArray Partial Preserve Private Property Protected Public "
"RaiseEvent RaiseEvent( ReadOnly ReDim Rem RemoveHandler RemoveHandler( Resume Return "
"Select Set Set( Shadows Shared Skip Static Step Stop Strict Structure Sub SyncLock "
"Take Text Then Throw To True Try TryCast( TypeOf Unicode Until Using "
"When Where While Widening With WithEvents WriteOnly Xor Yield "

, // 1 type keyword
"Any Boolean Byte Char Currency Date Decimal Double Integer Long LongLong LongPtr Object SByte Short Single String "
"UInteger ULong UShort Variant "

, // 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 "
"Wend Width "

, // 3 preprocessor
"Const Disable Else ElseIf Enable End EndIf ExternalChecksum ExternalSource If Region "

"Array Any Count GroupBy OrderBy "
// VB6
"Begin BeginProperty EndProperty Type"
, // 4 attribute
"AttributeUsage( ComClass( Conditional( DllImport( HideModuleName( MarshalAs( MyGroupCollection( Obsolete( "
"Serializable( StructLayout( VBFixedArray( VBFixedString( "

, // 1 Type Keyword
"Boolean Byte CBool CByte CChar CDate CDbl CDec Char CInt CLng CObj CSByte CShort CSng CStr CType CUInt "
"CULng CUShort Date Decimal Double Integer Long Object SByte Short Single String UInteger ULong UShort "
"Currency LongLong LongPtr Variant Empty Null CCur CLngLng CLngPtr CVar CVDate CVErr "
, // 5 class
"Collection Console ControlChars Conversion DateAndTime Debug Dictionary Drive Err ErrObject "
"File FileSystem FileSystemObject Financial Folder Information Interaction Math Strings TextStream VBMath "

, // 2 not used keyword, used in VBScript
"EndIf GoSub Wend "
, // 6 interface
nullptr

, // 3 Preprocessor
"If Else ElseIf End Const Region ExternalChecksum ExternalSource Disable Enable "
, // 7 enumeration
"AppWinStyle AttributeTargets CallType CompareMethod DateFormat DateInterval DueDate "
"FileAttribute FirstDayOfWeek FirstWeekOfYear LayoutKind MsgBoxResult MsgBoxStyle OpenAccess OpenMode OpenShare TriState "
"VariantType VbStrConv "

, // 4 Attribute
"ComClass HideModuleName WebMethod Serializable MarshalAs AttributeUsage DllImport StructLayout VBFixedString VBFixedArray"
, // 8 constant
"vbAbort vbAbortRetryIgnore vbAlias vbApplicationModal vbAppTaskManager vbAppWindows vbArchive vbArray "
"vbBack vbBinaryCompare vbBlack vbBlue vbBoolean vbByte "
"vbCalGreg vbCalHijri vbCancel vbChar vbCr vbCritical vbCrLf vbCurrency vbCyan vbDatabaseCompare vbDataObject vbDate "
"vbDecimal vbDefaultButton1 vbDefaultButton2 vbDefaultButton3 vbDefaultButton4 vbDirectory vbDouble "
"vbEmpty vbError vbExclamation "
"vbFalse vbFirstFourDays vbFirstFullWeek vbFirstJan1 vbFormCode vbFormControlMenu vbFormFeed vbFriday vbFromUnicode "
"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 "
"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 "
"vbTab vbTextCompare vbThursday vbTraditionalChinese vbTrue vbTuesday "
"vbUnicode vbUpperCase vbUseCompareOption vbUseDefault vbUserDefinedType vbUseSystem vbUseSystemDayOfWeek "
"vbVariant vbVerticalTab vbVolume vbWednesday vbWhite vbWide vbYellow vbYes vbYesNo vbYesNoCancel "

, // 5 VB Const
// String
"vbCr VbCrLf vbFormFeed vbLf vbNewLine vbNullChar vbNullString vbTab vbVerticalTab "
// MsgBox
"vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo "
"vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel "
"vbCritical vbQuestion vbExclamation vbInformation vbDefaultButton1 vbDefaultButton2 "
"vbDefaultButton3 vbApplicationModal vbSystemModal "
"vbMsgBoxHelp vbMsgBoxRight vbMsgBoxRtlReading vbMsgBoxSetForeground "
// Comparison
"vbBinaryCompare vbTextCompare "
// Date and Time
"vbSunday vbMonday vbTuesday vbWednesday vbThursday vbFriday vbSaturday "
"vbUseSystemDayOfWeek vbFirstJan1 vbFirstFourDays vbFirstFullWeek "
// Date Format
"vbGeneralDate vbLongDate vbShortDate vbLongTime vbShortTime "
// Tristate
"vbUseDefault vbTrue vbFalse "
// VarType
"vbEmpty vbNull vbInteger vbLong vbSingle vbDouble vbCurrency vbDate vbString "
"vbObject vbBoolean vbVariant vbDecimal vbByte vbArray vbDirectory "
// Miscellaneous
"vbObjectError vbArchive vbBack vbGet vbHidden vbHide vbLet vbLinguisticCasing "
"vbLowerCase vbMaximizedFocus vbMethod vbMinimizedFocus vbMinimizedNoFocus "
"vbNarrow vbNormal vbNormalFocus vbNormalNoFocus vbProperCase vbReadOnly vbSet "
"vbSystem vbUpperCase vbUserDefinedType vbUseSystem vbVolume vbWide "
"vbHiragana vbKatakana vbSimplifiedChinese vbTraditionalChinese "
, // 9 basic function
"Abs( AppActivate( Array( Asc( AscB( AscW( Atn( Beep( "
"CallByName( CBool( CByte( CChar( CCur( CDate( CDbl( CDec( ChDir( ChDrive( Choose( Chr( ChrB( ChrW( CInt( "
"CLng( CLngLng( CLngPtr( CObj( Command( Cos( CreateObject( CSByte( CShort( CSng( CStr( CType( CTypeDynamic( "
"CUInt( CULng( CurDir( CUShort( CVar( CVDate( CVErr( "
"DateAdd( DateDiff( DatePart( DateSerial( DateString DateValue( Day( DDB( DeleteSetting( Dir( DoEvents( "
"Environ( EOF( Erl( Error( ErrorToString( Exp( "
"FileAttr( FileClose( FileCopy( FileDateTime( FileGet( FileGetObject( FileLen( FileOpen( FilePut( FilePutObject( "
"FileWidth( Filter( Fix( Format( FormatCurrency( FormatDateTime( FormatNumber( FormatPercent( FreeFile( FV( "
"GetAllSettings( GetAttr( GetChar( GetObject( GetSetting( Hex( Hour( "
"IIf( Input( InputB( InputBox( InputString( InStr( InStrB( InStrRev( Int( IPmt( IRR( "
"IsArray( IsDate( IsDBNull( IsEmpty( IsError( IsMissing( IsNothing( IsNull( IsNumeric( IsObject( IsReference( "
"Join( Kill( LBound( LCase( Left( LeftB( Len( LenB( LineInput( Loc( Lock( LOF( Log( LSet( LTrim( "
"Mid( MidB( Minute( MIRR( MkDir( Month( MonthName( MsgBox( Now NPer( NPV( Oct( "
"Partition( Pmt( PPmt( Print( PrintLine( PV( QBColor( "
"Randomize( Rate( Rename( Replace( Reset( RGB( Right( RightB( RmDir( Rnd( Round( RSet( RTrim( "
"SaveSetting( Second( Seek( SetAttr( Sgn( Shell( Sin( SLN( Space( Spc( Split( Sqr( "
"Str( StrComp( StrConv( StrDup( String( StrReverse( Switch( SYD( SystemTypeName( "
"Tab( Tan( Time TimeOfDay Timer TimeSerial( TimeString TimeValue( Today Trim( TypeName( UBound( UCase( Unlock( "
"Val( VarType( VbTypeName( Weekday( WeekdayName( Write( WriteLine( Year( "

, nullptr, nullptr, nullptr
, // 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( "

, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
, nullptr, nullptr, nullptr, nullptr, nullptr
//--Autogenerated -- end of section automatically generated
}};

static EDITSTYLE Styles_VB[] = {
Expand All @@ -77,6 +107,10 @@ static EDITSTYLE Styles_VB[] = {
{ SCE_VB_KEYWORD2, NP2StyleX_TypeKeyword, L"fore:#0000FF" },
{ MULTI_STYLE(SCE_VB_PREPROCESSOR, SCE_VB_PREPROCESSOR_WORD, 0, 0), NP2StyleX_Preprocessor, L"fore:#FF8000" },
{ SCE_VB_ATTRIBUTE, NP2StyleX_Attribute, L"fore:#FF8000" },
{ SCE_VB_CLASS, NP2StyleX_Class, L"bold; fore:#007F7F" },
{ SCE_VB_INTERFACE, NP2StyleX_Interface, L"bold; fore:#1E90FF" },
{ SCE_VB_ENUM, NP2StyleX_Enumeration, L"fore:#FF8000" },
{ SCE_VB_BASIC_FUNCTION, NP2StyleX_BasicFunction, L"fore:#0080C0" },
{ SCE_VB_FUNCTION_DEFINITION, NP2StyleX_FunctionDefinition, L"bold; fore:#A46000" },
{ SCE_VB_CONSTANT, NP2StyleX_Constant, L"fore:#B000B0" },
{ SCE_VB_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
Expand All @@ -100,12 +134,17 @@ EDITLEXER lexVisualBasic = {
0,
0, SCE_VB_COMMENTLINE,
SCE_VB_OPERATOR, SCE_VB_OPERATOR2
, KeywordAttr32(0, KeywordAttr_MakeLower) // keywords
| KeywordAttr32(1, KeywordAttr_MakeLower) // type keyword
| KeywordAttr32(2, KeywordAttr_MakeLower) // demoted keyword
| KeywordAttr32(3, KeywordAttr_MakeLower | KeywordAttr_NoAutoComp) // preprocessor
| KeywordAttr32(4, KeywordAttr_MakeLower) // attribute
| KeywordAttr32(5, KeywordAttr_MakeLower) // constant
, KeywordAttr32(0, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // keywords
| KeywordAttr32(1, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // type 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
| KeywordAttr32(6, KeywordAttr_MakeLower) // interface
| KeywordAttr64(7, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // enumeration
| KeywordAttr64(8, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // constant
| KeywordAttr64(9, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // basic function
| KeywordAttr64(10, KeywordAttr_NoLexer) // misc
, SCE_VB_COMMENTLINE,
SCE_VB_STRING, SCE_VB_PLACEHOLDER,
//Settings--Autogenerated -- end of section automatically generated
Expand Down
Loading

0 comments on commit e3e439d

Please sign in to comment.