cwcacsyn.pas
来自「本人买的<<VC++项目开发实例>>源代码配套光盘.」· PAS 代码 · 共 1,112 行 · 第 1/3 页
PAS
1,112 行
function TcwCACSyn.Func116: TtkTokenKind;
begin
if KeyComp('PARAMETERS') then Result := tkKey else Result := tkIdentifier;
end;
function TcwCACSyn.Func124: TtkTokenKind;
begin
if KeyComp('TRANSFORM') then Result := tkKey else Result := tkIdentifier;
end;
function TcwCACSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TcwCACSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 125 then Result := fIdentFuncTable[HashKey] else Result := tkIdentifier;
end;
procedure TcwCACSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'@': fProcTable[I] := SymbolProc;
'&': fProcTable[I] := SymbolProc;
'{': fProcTable[I] := SymbolProc;
'}': fProcTable[I] := SymbolProc;
#13: fProcTable[I] := CRProc;
':': fProcTable[I] := SymbolProc;
',': fProcTable[I] := SymbolProc;
'#': fProcTable[I] := DirectiveProc;
'=': fProcTable[I] := SymbolProc;
'>': fProcTable[I] := SymbolProc;
'A'..'Z', 'a'..'z': fProcTable[I] := IdentProc;
'$': fProcTable[I] := SymbolProc;
#10: fProcTable[I] := LFProc;
'<': fProcTable[I] := SymbolProc;
'-': fProcTable[I] := SymbolProc;
'!': fProcTable[I] := SymbolProc;
#0: fProcTable[I] := NullProc;
'0'..'9': fProcTable[I] := NumberProc;
'+': fProcTable[I] := SymbolProc;
'.': fProcTable[I] := SymbolProc;
'?': fProcTable[I] := SymbolProc;
')': fProcTable[I] := SymbolProc;
'(': fProcTable[I] := SymbolProc;
';': fProcTable[I] := SymbolProc;
'/': fProcTable[I] := SlashProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := SpaceProc;
']': fProcTable[I] := SymbolProc;
'[': fProcTable[I] := SymbolProc;
'*': fProcTable[I] := StarProc;
#39, #34: fProcTable[I] := StringProc;
else fProcTable[I] := UnknownProc;
end;
end;
constructor TcwCACSyn.Create(AOwner: TComponent);
begin
fCommentAttri := TmwHighLightAttributes.Create(MWS_AttrComment);
fCommentAttri.Style := [fsItalic];
fIdentifierAttri := TmwHighLightAttributes.Create(MWS_AttrIdentifier);
fKeyAttri := TmwHighLightAttributes.Create(MWS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
fNumberAttri := TmwHighLightAttributes.Create(MWS_AttrNumber);
fSpaceAttri := TmwHighLightAttributes.Create(MWS_AttrSpace);
fStringAttri := TmwHighLightAttributes.Create(MWS_AttrString);
fOperatorAttri := TmwHighLightAttributes.Create(MWS_AttrOperator);
fDirecAttri := TmwHighLightAttributes.Create(MWS_AttrPreprocessor);
inherited Create(AOwner);
AddAttribute(fCommentAttri);
AddAttribute(fIdentifierAttri);
AddAttribute(fKeyAttri);
AddAttribute(fNumberAttri);
AddAttribute(fSpaceAttri);
AddAttribute(fStringAttri);
AddAttribute(fOperatorAttri);
AddAttribute(fDirecAttri);
InitIdent;
SetAttributesOnChange(DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := MWS_FilterCAClipper;
end; { Create }
procedure TcwCACSyn.SetLine(NewValue: string; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fEol := False;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TcwCACSyn.CStyleProc;
begin
fTokenID := tkComment;
case FLine[Run] of
#0:
begin
NullProc;
exit;
end;
#10:
begin
LFProc;
exit;
end;
#13:
begin
CRProc;
exit;
end;
end;
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = '/' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10: break;
#13: break;
else inc(Run);
end;
end;
procedure TcwCACSyn.CRProc;
begin
fTokenID := tkSpace;
case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
end;
procedure TcwCACSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TcwCACSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TcwCACSyn.NullProc;
begin
fTokenID := tkNull;
fEol := True;
end;
procedure TcwCACSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'e', 'E'] do
begin
case FLine[Run] of
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TcwCACSyn.SlashProc;
begin
case FLine[Run + 1] of
'/':
begin
inc(Run, 2);
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
'*':
begin
fTokenID := tkComment;
fRange := rsCStyle;
inc(Run, 2);
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = '/' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10: break;
#13: break;
else inc(Run);
end;
end;
else
begin
inc(Run);
fTokenID := tkOperator;
end;
end;
end;
procedure TcwCACSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TcwCACSyn.SymbolProc;
begin
inc(Run);
fTokenID := tkOperator;
end;
procedure TcwCACSyn.StringProc;
var
ActiveStr: string[1];
begin
fTokenID := tkString;
ActiveStr := FLine[Run];
if ((FLine[Run + 1] = #39) and (FLine[Run + 2] = #39)) or
((FLine[Run + 1] = #34) and (FLine[Run + 2] = #34)) then inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until (FLine[Run] = ActiveStr);
if FLine[Run] <> #0 then inc(Run);
end;
procedure TcwCACSyn.DirectiveProc;
begin
fTokenID := tkDirective;
repeat
case FLine[Run] of
#0, #10, #13: break;
'/': if FLine[Run + 1] = '/' then break;
#34, #39: break;
end;
inc(Run);
until FLine[Run] = #0;
end;
procedure TcwCACSyn.UnknownProc;
begin
inc(Run);
end;
procedure TcwCACSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsCStyle: CStyleProc;
else fProcTable[fLine[Run]];
end;
end;
function TcwCACSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TcwCACSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TcwCACSyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TcwCACSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TcwCACSyn.GetTokenAttribute: TmwHighLightAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkDirective: Result := fDirecAttri;
tkOperator: Result := fOperatorAttri;
tkUnknown: Result := fOperatorAttri;
else Result := nil;
end;
end;
function TcwCACSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TcwCACSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TcwCACSyn.ReSetRange;
begin
fRange := rsUnknown;
end;
procedure TcwCACSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TcwCACSyn.GetLanguageName: string;
begin
Result := MWS_LangCAClipper;
end;
{Begin cw 1999-5-7}
procedure TcwCACSyn.StarProc;
begin
// if Run is 0 there could be an access violation
if (Run = 0) or (fLine[Run - 1] in [#0, #10, #13]) then
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end else begin
inc(Run);
fTokenID := tkOperator;
end;
end;
initialization
MakeIdentTable;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?