Skip to content

Commit

Permalink
Completion cleanup and support adding keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 8, 2023
1 parent c6f95fc commit 667e92e
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
FPC_VER: release_3_2_2
LAZ_VER: lazarus_2_2_4
LAZ_VER: fixes_3_0

jobs:
build:
Expand Down
6 changes: 5 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="139">
<Units Count="140">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -979,6 +979,10 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
</Unit138>
<Unit139>
<Filename Value="codetools/simba.ide_codetools_keywords.pas"/>
<IsPartOfProject Value="True"/>
</Unit139>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
51 changes: 51 additions & 0 deletions Source/codetools/simba.ide_codetools_keywords.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.ide_codetools_keywords;

{$i simba.inc}

interface

uses
Classes, SysUtils,
simba.mufasatypes, simba.ide_codetools_parser, simba.ide_initialization;

function GetKeywords: TDeclarationArray;

implementation

uses
lpparser,
simba.list;

type
TKeywordList = specialize TSimbaObjectList<TDeclaration>;

var
KeywordsList: TKeywordList;

procedure CreateKeywords;
var
Keyword: TLapeKeyword;
begin
KeywordsList := TKeywordList.Create(True);
for Keyword in Lape_Keywords do
KeywordsList.Add(TDeclaration_Keyword.Create(Keyword.Keyword.ToLower()));
end;

function GetKeywords: TDeclarationArray;
begin
Result := KeywordsList.ToArray();
end;

initialization
SimbaIDEInitialization_AddBeforeCreate(@CreateKeywords, 'Codetools Create Keywords');

finalization
if (KeywordsList <> nil) then
FreeAndNil(KeywordsList);

end.
88 changes: 81 additions & 7 deletions Source/codetools/simba.ide_codetools_parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ TDeclaration = class({$IFDEF PARSER_LEAK_CHECKS}TLeakChecker{$ELSE}TObject{$EN

FFlags: UInt32;

procedure ClearFlags;
procedure SetFlags(const Index: Integer; const AValue: Boolean);
function GetFlags(const Index: Integer): Boolean;
procedure ClearFlags; inline;
procedure SetFlags(const Index: Integer; const AValue: Boolean); inline;
function GetFlags(const Index: Integer): Boolean; inline;

function GetText: String;
function GetTextNoComments: String;
Expand Down Expand Up @@ -137,6 +137,12 @@ TDeclaration = class({$IFDEF PARSER_LEAK_CHECKS}TLeakChecker{$ELSE}TObject{$EN
property isOverrideMethod: Boolean index 6 read GetFlags write SetFlags;
property isOverloadMethod: Boolean index 7 read GetFlags write SetFlags;
property isStaticMethod: Boolean index 8 read GetFlags write SetFlags;
property isVar: Boolean index 9 read GetFlags write SetFlags;
property isConst: Boolean index 10 read GetFlags write SetFlags;
property isField: Boolean index 11 read GetFlags write SetFlags;
property isEnumElement: Boolean index 12 read GetFlags write SetFlags;
property isType: Boolean index 13 read GetFlags write SetFlags;
property isKeyword: Boolean index 14 read GetFlags write SetFlags;

constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); virtual; reintroduce;
destructor Destroy; override;
Expand All @@ -147,6 +153,11 @@ TDeclaration_Root = class(TDeclaration)
constructor Create; reintroduce;
end;

TDeclaration_Keyword = class(TDeclaration)
public
constructor Create(Keyword: String); reintroduce;
end;

TDeclaration_Anchor = class(TDeclaration);

TDeclaration_WithStatement = class(TDeclaration);
Expand Down Expand Up @@ -180,7 +191,11 @@ TDeclaration_Identifier = class(TDeclaration);
TDeclaration_ParentType = class(TDeclaration_Identifier);
TDeclaration_OrdinalType = class(TDeclaration);

TDeclaration_Type = class(TDeclaration);
TDeclaration_Type = class(TDeclaration)
public
constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); override;
end;

TDeclaration_TypeRecord = class(TDeclaration_Type)
public
function Parent: TDeclaration;
Expand Down Expand Up @@ -211,8 +226,10 @@ TDeclaration_TypeAlias = class(TDeclaration_Type)
end;

TDeclaration_EnumElement = class(TDeclaration)
public
protected
function GetName: string; override;
public
constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); override;
end;

TDeclaration_EnumElementName = class(TDeclaration)
Expand Down Expand Up @@ -261,14 +278,21 @@ TDeclaration_Var = class(TDeclaration)
public
DefToken: TptTokenKind;

constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); override;

property VarType: TDeclaration read GetVarType;
property VarTypeString: String read GetVarTypeString;
property VarDefaultString: String read GetVarDefaultString;
end;

TDeclaration_VarClass = class of TDeclaration_Var;
TDeclaration_Const = class(TDeclaration_Var);
TDeclaration_Field = class(TDeclaration_Var);
TDeclaration_Const = class(TDeclaration_Var)
constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); override;
end;

TDeclaration_Field = class(TDeclaration_Var)
constructor Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer); override;
end;

TDeclaration_Method = class(TDeclaration)
protected
Expand Down Expand Up @@ -540,6 +564,24 @@ constructor TDeclaration_Root.Create;
inherited Create(nil, nil, 0, 0);
end;

constructor TDeclaration_Keyword.Create(Keyword: String);
begin
inherited Create(nil, nil, 0, 0);

FName.Value := Keyword;

ClearFlags();
isKeyword := True;
end;

constructor TDeclaration_Type.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);

ClearFlags();
isType := True;
end;

function TDeclaration_EnumElement.GetName: string;
begin
if FName.IsNull then
Expand All @@ -548,6 +590,14 @@ function TDeclaration_EnumElement.GetName: string;
Result := inherited;
end;

constructor TDeclaration_EnumElement.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);

ClearFlags();
isEnumElement := True;
end;

function TDeclaration_TypeAlias.VarType: TDeclaration;
begin
Result := Items.GetByClassFirst(TDeclaration_VarType);
Expand Down Expand Up @@ -627,6 +677,30 @@ function TDeclaration_Var.GetVarDefaultString: String;
Result := FVarDefaultString.Value;
end;

constructor TDeclaration_Var.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);

ClearFlags();
isVar := True;
end;

constructor TDeclaration_Const.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);

ClearFlags();
isConst := True;
end;

constructor TDeclaration_Field.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);

ClearFlags();
isField := True;
end;

function TDeclaration_EnumElementName.GetName: string;
begin
if FName.IsNull then
Expand Down
16 changes: 15 additions & 1 deletion Source/components/simba.component_scrollbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface

uses
Classes, SysUtils, Controls, ComCtrls,
Classes, SysUtils, Controls, ComCtrls, StdCtrls,
ATScrollBar, simba.settings;

type
Expand All @@ -23,6 +23,8 @@ TSimbaScrollBar = class(TATScrollBar)
public
ForwardScrollControl: TControl;

procedure Assign(From: TScrollBar);

constructor Create(AOwner: TComponent); override;
end;

Expand Down Expand Up @@ -53,6 +55,18 @@ procedure TSimbaScrollBar.DoSettingChange_ScrollBarArrowSize(Setting: TSimbaSett
Update();
end;

procedure TSimbaScrollBar.Assign(From: TScrollBar);
begin
Min := From.Min;
Max := From.Max+1;
SmallChange := From.SmallChange;
LargeChange := From.LargeChange;
PageSize := From.PageSize;
Position := From.Position;

Update();
end;

constructor TSimbaScrollBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Expand Down
Loading

0 comments on commit 667e92e

Please sign in to comment.