📄 synhighlightermodelica.pas
字号:
function TSynModelicaSyn.Func119: TtkTokenKind;
begin
if KeyComp('output') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func133: TtkTokenKind;
begin
if KeyComp('annotation') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func137: TtkTokenKind;
begin
if KeyComp('nondiscrete') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynModelicaSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 138 then
Result := fIdentFuncTable[HashKey]
else
Result := tkIdentifier;
end;
procedure TSynModelicaSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'&': fProcTable[I] := AndSymbolProc;
#39: fProcTable[I] := AsciiCharProc;
#13: fProcTable[I] := CRProc;
':': fProcTable[I] := ColonProc;
'#': fProcTable[I] := DirectiveProc;
'>': fProcTable[I] := GreaterProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := IdentProc;
#10: fProcTable[I] := LFProc;
'<': fProcTable[I] := LowerProc;
'-': fProcTable[I] := MinusProc;
#0: fProcTable[I] := NullProc;
'0'..'9':
fProcTable[I] := NumberProc;
'|': fProcTable[I] := OrSymbolProc;
'+': fProcTable[I] := PlusProc;
'.': fProcTable[I] := PointProc;
'/': fProcTable[I] := SlashProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := SpaceProc;
#34: fProcTable[I] := StringProc;
'~', '[', ']', '@', '{', '}', '(', ')', ';', ',':
fProcTable[I] := SymbolProc;
'*', '^', '=', '%', '!':
fProcTable[I] := SymbolProcWithEqual;
else
fProcTable[I] := UnknownProc;
end;
end;
constructor TSynModelicaSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective);
AddAttribute(fDirectiveAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterModelica;
fRange := rsUnknown;
end;
procedure TSynModelicaSyn.SetLine(NewValue: string; LineNumber: integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynModelicaSyn.AndSymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '&'] then
Inc(Run);
end;
procedure TSynModelicaSyn.AsciiCharProc;
begin
fRange := rsString39;
fTokenID := tkString;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13, #39];
if fLine[Run] = #39 then begin
fRange := rsUnknown;
Inc(Run);
end;
end;
procedure TSynModelicaSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynModelicaSyn.ColonProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = ':' then
Inc(Run);
end;
procedure TSynModelicaSyn.DirectiveProc;
begin
fTokenID := tkDirective;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynModelicaSyn.GreaterProc;
begin
Inc(Run);
fTokenID := tkSymbol;
case fLine[Run] of
'=': Inc(Run);
'>': begin
Inc(Run);
if fLine[Run] = '=' then
Inc(Run);
end;
end;
end;
procedure TSynModelicaSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TSynModelicaSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynModelicaSyn.LowerProc;
begin
Inc(Run);
fTokenID := tkSymbol;
case fLine[Run] of
'=': Inc(Run);
'<': begin
Inc(Run);
if fLine[Run] = '=' then
Inc(Run);
end;
end;
end;
procedure TSynModelicaSyn.MinusProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '-', '>'] then
Inc(Run);
end;
procedure TSynModelicaSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynModelicaSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in
['0'..'9', '.', 'u', 'U', 'l', 'L', 'x', 'X', 'e', 'E', 'f', 'F'] do
begin
case FLine[Run] of
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynModelicaSyn.OrSymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '|'] then
Inc(Run);
end;
procedure TSynModelicaSyn.PlusProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '+'] then
Inc(Run);
end;
procedure TSynModelicaSyn.PointProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if (fLine[Run] = '.') and (fLine[Run + 1] = '.') then
Inc(Run, 2);
end;
procedure TSynModelicaSyn.SlashProc;
begin
Inc(Run);
case fLine[Run] of
'/':
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
'*':
begin
fRange := rsComment;
inc(Run);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkComment
else
AnsiCProc;
end;
else
fTokenID := tkSymbol;
if fLine[Run] = '=' then
Inc(Run);
end;
end;
procedure TSynModelicaSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynModelicaSyn.StringProc;
begin
fRange := rsString34;
Inc(Run);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkString
else
String34Proc;
end;
procedure TSynModelicaSyn.SymbolProc;
begin
Inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynModelicaSyn.SymbolProcWithEqual;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = '=' then
Inc(Run);
end;
procedure TSynModelicaSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynModelicaSyn.AnsiCProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then begin
inc(Run, 2);
fRange := rsUnknown;
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.String39Proc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkString;
repeat
if fLine[Run] = #39 then begin
inc(Run);
fRange := rsUnknown;
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.String34Proc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkString;
repeat
case fLine[Run] of
#34:
begin
Inc(Run);
fRange := rsUnknown;
break;
end;
#92:
begin
Inc(Run);
if fLine[Run] = #34 then
Inc(Run);
end;
else
Inc(Run);
end;
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsComment: AnsiCProc;
rsString39: String39Proc;
rsString34: String34Proc;
else
fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
function TSynModelicaSyn.GetDefaultAttribute(
Index: integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT: Result := fCommentAttri;
SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_STRING: Result := fStringAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynModelicaSyn.GetEol: boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynModelicaSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynModelicaSyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynModelicaSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynModelicaSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case GetTokenID of
tkComment: Result := fCommentAttri;
tkDirective: Result := fDirectiveAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynModelicaSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynModelicaSyn.GetTokenPos: integer;
begin
Result := fTokenPos;
end;
procedure TSynModelicaSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynModelicaSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynModelicaSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynModelicaSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterModelica;
end;
class function TSynModelicaSyn.GetLanguageName: string;
begin
Result := SYNS_LangModelica;
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynModelicaSyn);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -