1 {-------------------------------------------------------------------------------
2 The contents of this file are subject to the Mozilla Public License
3 Version 1.1 (the "License"); you may not use this file except in compliance
4 with the License. You may obtain a copy of the License at
5 http://www.mozilla.org/MPL/
6
7 Software distributed under the License is distributed on an "AS IS" basis,
8 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9 the specific language governing rights and limitations under the License.
10
11 The Original Code is: SynHighlighterJava.pas, released 2000-04-10.
12 The Original Code is based on the DcjSynJava.pas file from the
13 mwEdit component suite by Martin Waldenburg and other developers, the Initial
14 Author of this file is Michael Trier.
15 All Rights Reserved.
16
17 Contributors to the SynEdit and mwEdit projects are listed in the
18 Contributors.txt file.
19
20 Alternatively, the contents of this file may be used under the terms of the
21 GNU General Public License Version 2 or later (the "GPL"), in which case
22 the provisions of the GPL are applicable instead of those above.
23 If you wish to allow use of your version of this file only under the terms
24 of the GPL and not to allow others to use your version of this file
25 under the MPL, indicate your decision by deleting the provisions above and
26 replace them with the notice and other provisions required by the GPL.
27 If you do not delete the provisions above, a recipient may use your version
28 of this file under either the MPL or the GPL.
29
30 $Id$
31
32 You may retrieve the latest version of this file at the SynEdit home page,
33 located at http://SynEdit.SourceForge.net
34
35 Known Issues:
36 -------------------------------------------------------------------------------}
37 {
38 @abstract(Provides a Java highlighter for SynEdit)
39 @author(Michael Trier)
40 @created(December 1998, converted to SynEdit 2000-04-10 by Michael Hieke)
41 @lastmod(2000-06-23)
42 The SynHighlighterJava unit provides SynEdit with a Java source (.java) highlighter.
43 }
44 unit SynHighlighterJava;
45
46 {$I SynEdit.inc}
47
48 interface
49
50 uses
51 SysUtils, Classes,
52 LCLIntf, LCLType, Graphics,
53 SynEditTypes, SynEditHighlighter, SynEditStrConst;
54
55 type
56 TtkTokenKind = (tkComment, tkDocument, tkIdentifier, tkInvalid, tkKey,
57 tkNull, tkNumber, tkSpace, tkString, tkSymbol, tkUnknown, tkAnnotation);
58
59 TxtkTokenKind = (
60 xtkAdd, xtkAddAssign, xtkAnd, xtkAndAssign, xtkAssign, xtkBitComplement,
61 xtkBraceClose, xtkBraceOpen, xtkColon, xtkCondAnd, xtkCondOr, xtkDecrement,
62 xtkDivide, xtkDivideAssign, xtkGreaterThan, xtkGreaterThanEqual, xtkIncOr,
63 xtkIncOrAssign, xtkIncrement, xtkLessThan, xtkLessThanEqual,
64 xtkLogComplement, xtkLogEqual, xtkMultiply, xtkMultiplyAssign, xtkNotEqual,
65 xtkPoint, xtkQuestion, xtkRemainder, xtkRemainderAssign, xtkRoundClose,
66 xtkRoundOpen, xtkSemiColon, xtkShiftLeft, xtkShiftLeftAssign, xtkShiftRight,
67 xtkShiftRightAssign, xtkSquareClose, xtkSquareOpen, xtkSubtract,
68 xtkSubtractAssign, xtkUnsignShiftRight, xtkUnsignShiftRightAssign, xtkXor,
69 xtkXorAssign, xtkComma,
70 xtkNonSymbol);
71
72 TRangeState = (rsANil, rsComment, rsDocument, rsUnknown);
73
74 TProcTableProc = procedure of Object;
TtkTokenKindnull75 TIdentFuncTableFunc = function: TtkTokenKind of Object;
76
77 TSynJavaSyn = class(TSynCustomHighlighter)
78 private
79 fRange: TRangeState;
80 fLine: PChar;
81 fProcTable: array[#0..#255] of TProcTableProc;
82 Run: LongInt;
83 FRoundCount: Integer;
84 FSquareCount: Integer;
85 fStringLen: Integer;
86 fToIdent: PChar;
87 fTokenPos: Integer;
88 FTokenID: TtkTokenKind;
89 FExtTokenID: TxtkTokenKind;
90 fEol: Boolean;
91 fLineNumber: Integer;
92 fCommentAttri: TSynHighlighterAttributes;
93 fDocumentAttri: TSynHighlighterAttributes;
94 fIdentifierAttri: TSynHighlighterAttributes;
95 fInvalidAttri: TSynHighlighterAttributes;
96 fKeyAttri: TSynHighlighterAttributes;
97 fNumberAttri: TSynHighlighterAttributes;
98 fSpaceAttri: TSynHighlighterAttributes;
99 fStringAttri: TSynHighlighterAttributes;
100 fSymbolAttri: TSynHighlighterAttributes;
101 fAnnotationAttri: TSynHighlighterAttributes;
Func17null102 function Func17: TtkTokenKind;
Func21null103 function Func21: TtkTokenKind;
Func32null104 function Func32: TtkTokenKind;
Func34null105 function Func34: TtkTokenKind;
Func40null106 function Func40: TtkTokenKind;
Func42null107 function Func42: TtkTokenKind;
Func45null108 function Func45: TtkTokenKind;
Func46null109 function Func46: TtkTokenKind;
Func47null110 function Func47: TtkTokenKind;
Func48null111 function Func48: TtkTokenKind;
Func51null112 function Func51: TtkTokenKind;
Func52null113 function Func52: TtkTokenKind;
Func54null114 function Func54: TtkTokenKind;
Func56null115 function Func56: TtkTokenKind;
Func59null116 function Func59: TtkTokenKind;
Func60null117 function Func60: TtkTokenKind;
Func61null118 function Func61: TtkTokenKind;
Func62null119 function Func62: TtkTokenKind;
Func63null120 function Func63: TtkTokenKind;
Func65null121 function Func65: TtkTokenKind;
Func66null122 function Func66: TtkTokenKind;
Func68null123 function Func68: TtkTokenKind;
Func69null124 function Func69: TtkTokenKind;
Func71null125 function Func71: TtkTokenKind;
Func76null126 function Func76: TtkTokenKind;
Func77null127 function Func77: TtkTokenKind;
Func78null128 function Func78: TtkTokenKind;
Func84null129 function Func84: TtkTokenKind;
Func85null130 function Func85: TtkTokenKind;
Func86null131 function Func86: TtkTokenKind;
Func88null132 function Func88: TtkTokenKind;
Func89null133 function Func89: TtkTokenKind;
Func90null134 function Func90: TtkTokenKind;
Func92null135 function Func92: TtkTokenKind;
Func97null136 function Func97: TtkTokenKind;
Func98null137 function Func98: TtkTokenKind;
Func102null138 function Func102: TtkTokenKind;
Func104null139 function Func104: TtkTokenKind;
Func109null140 function Func109: TtkTokenKind;
Func115null141 function Func115: TtkTokenKind;
Func116null142 function Func116: TtkTokenKind;
Func119null143 function Func119: TtkTokenKind;
Func129null144 function Func129: TtkTokenKind;
Func136null145 function Func136: TtkTokenKind;
Func172null146 function Func172: TtkTokenKind;
147 procedure CommentProc;
148 procedure AndSymbolProc;
149 procedure AsciiCharProc;
150 procedure AnnotationProc;
151 procedure BraceCloseProc;
152 procedure BraceOpenProc;
153 procedure CRProc;
154 procedure ColonProc;
155 procedure CommaProc;
156 procedure EqualProc;
157 procedure GreaterProc;
158 procedure IdentProc;
159 procedure LFProc;
160 procedure LowerProc;
161 procedure MinusProc;
162 procedure MultiplyProc;
163 procedure NotSymbolProc;
164 procedure NullProc;
165 procedure NumberProc;
166 procedure OrSymbolProc;
167 procedure PlusProc;
168 procedure PointProc;
169 procedure PoundProc;
170 procedure QuestionProc;
171 procedure RemainderSymbolProc;
172 procedure RoundCloseProc;
173 procedure RoundOpenProc;
174 procedure SemiColonProc;
175 procedure SlashProc;
176 procedure SpaceProc;
177 procedure SquareCloseProc;
178 procedure SquareOpenProc;
179 procedure StringProc;
180 procedure TildeProc;
181 procedure XOrSymbolProc;
182 procedure UnknownProc;
IdentKindnull183 function IdentKind(MayBe: PChar): TtkTokenKind;
184 procedure MakeMethodTables;
185 protected
186 fIdentFuncTable: array[0..172] of TIdentFuncTableFunc;
AltFuncnull187 function AltFunc: TtkTokenKind;
KeyHashnull188 function KeyHash(ToHash: PChar): Integer;
KeyCompnull189 function KeyComp(const aKey: String): Boolean;
190 procedure InitIdent; virtual;
GetIdentCharsnull191 function GetIdentChars: TSynIdentChars; override;
GetSampleSourcenull192 function GetSampleSource: string; override;
GetExtTokenIDnull193 function GetExtTokenID: TxtkTokenKind;
194 public
GetLanguageNamenull195 class function GetLanguageName: string; override;
196 public
197 constructor Create(AOwner: TComponent); override;
GetDefaultAttributenull198 function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
199 override;
GetEolnull200 function GetEol: Boolean; override;
GetRangenull201 function GetRange: Pointer; override;
GetTokenIDnull202 function GetTokenID: TtkTokenKind;
203 procedure SetLine(const NewValue: String;
204 LineNumber:Integer); override;
GetTokennull205 function GetToken: String; override;
206 procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
GetTokenAttributenull207 function GetTokenAttribute: TSynHighlighterAttributes; override;
GetTokenKindnull208 function GetTokenKind: integer; override;
GetTokenPosnull209 function GetTokenPos: Integer; override;
210 procedure Next; override;
211 procedure SetRange(Value: Pointer); override;
212 procedure ResetRange; override;
213 property ExtTokenID: TxtkTokenKind read GetExtTokenID;
214 published
215 property AnnotationAttri: TSynHighlighterAttributes read fAnnotationAttri
216 write fAnnotationAttri;
217 property CommentAttri: TSynHighlighterAttributes read fCommentAttri
218 write fCommentAttri;
219 property DocumentAttri: TSynHighlighterAttributes read fDocumentAttri
220 write fDocumentAttri;
221 property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
222 write fIdentifierAttri;
223 property InvalidAttri: TSynHighlighterAttributes read fInvalidAttri
224 write fInvalidAttri;
225 property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
226 property NumberAttri: TSynHighlighterAttributes read fNumberAttri
227 write fNumberAttri;
228 property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
229 write fSpaceAttri;
230 property StringAttri: TSynHighlighterAttributes read fStringAttri
231 write fStringAttri;
232 property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
233 write fSymbolAttri;
234 end;
235
236 implementation
237
238 var
239 Identifiers: array[#0..#255] of ByteBool;
240 mHashTable: array[#0..#255] of Integer;
241
242 procedure MakeIdentTable;
243 var
244 I: Char;
245 begin
246 for I := #0 to #255 do
247 begin
248 // Java allows special characters in identifier names
249 Identifiers[I] := (I in ['_', '$', '0'..'9', 'a'..'z', 'A'..'Z']) or (I in TSynSpecialChars);
250 if (I in ['_', '$', 'a'..'z', 'A'..'Z']) or (I in TSynSpecialChars) then
251 begin
252 if (I > #64) and (I < #91) then
253 mHashTable[I] := Ord(I) - 64
254 else
255 if (I > #96) then
256 mHashTable[I] := Ord(I) - 95;
257 end
258 else
259 mHashTable[I] := 0;
260 end;
261 end;
262
263 procedure TSynJavaSyn.InitIdent;
264 var
265 I: Integer;
266 begin
267 for I := 0 to 172 do
268 Case I of
269 17: fIdentFuncTable[I] := @Func17;
270 21: fIdentFuncTable[I] := @Func21;
271 32: fIdentFuncTable[I] := @Func32;
272 34: fIdentFuncTable[I] := @Func34;
273 40: fIdentFuncTable[I] := @Func40;
274 42: fIdentFuncTable[I] := @Func42;
275 45: fIdentFuncTable[I] := @Func45;
276 46: fIdentFuncTable[I] := @Func46;
277 47: fIdentFuncTable[I] := @Func47;
278 48: fIdentFuncTable[I] := @Func48;
279 51: fIdentFuncTable[I] := @Func51;
280 52: fIdentFuncTable[I] := @Func52;
281 54: fIdentFuncTable[I] := @Func54;
282 56: fIdentFuncTable[I] := @Func56;
283 59: fIdentFuncTable[I] := @Func59;
284 60: fIdentFuncTable[I] := @Func60;
285 61: fIdentFuncTable[I] := @Func61;
286 62: fIdentFuncTable[I] := @Func62;
287 63: fIdentFuncTable[I] := @Func63;
288 65: fIdentFuncTable[I] := @Func65;
289 66: fIdentFuncTable[I] := @Func66;
290 68: fIdentFuncTable[I] := @Func68;
291 69: fIdentFuncTable[I] := @Func69;
292 71: fIdentFuncTable[I] := @Func71;
293 76: fIdentFuncTable[I] := @Func76;
294 77: fIdentFuncTable[I] := @Func77;
295 78: fIdentFuncTable[I] := @Func78;
296 84: fIdentFuncTable[I] := @Func84;
297 85: fIdentFuncTable[I] := @Func85;
298 86: fIdentFuncTable[I] := @Func86;
299 88: fIdentFuncTable[I] := @Func88;
300 89: fIdentFuncTable[I] := @Func89;
301 90: fIdentFuncTable[I] := @Func90;
302 92: fIdentFuncTable[I] := @Func92;
303 97: fIdentFuncTable[I] := @Func97;
304 98: fIdentFuncTable[I] := @Func98;
305 102: fIdentFuncTable[I] := @Func102;
306 104: fIdentFuncTable[I] := @Func104;
307 109: fIdentFuncTable[I] := @Func109;
308 115: fIdentFuncTable[I] := @Func115;
309 116: fIdentFuncTable[I] := @Func116;
310 119: fIdentFuncTable[I] := @Func119;
311 129: fIdentFuncTable[I] := @Func129;
312 136: fIdentFuncTable[I] := @Func136;
313 172: fIdentFuncTable[I] := @Func172;
314 else fIdentFuncTable[I] := @AltFunc;
315 end;
316 end;
317
KeyHashnull318 function TSynJavaSyn.KeyHash(ToHash: PChar): Integer;
319 begin
320 Result := 0;
321 while (ToHash^ in ['_', '$', '0'..'9', 'a'..'z', 'A'..'Z']) or
322 (ToHash^ in TSynSpecialChars) do
323 begin
324 inc(Result, mHashTable[ToHash^]);
325 inc(ToHash);
326 end;
327 fStringLen := ToHash - fToIdent;
328 end; { KeyHash }
329
TSynJavaSyn.KeyCompnull330 function TSynJavaSyn.KeyComp(const aKey: String): Boolean;
331 var
332 I: Integer;
333 Temp: PChar;
334 begin
335 Temp := FToIdent;
336 if Length(aKey) = fStringLen then
337 begin
338 Result := True;
339 for i := 1 to fStringLen do
340 begin
341 if Temp^ <> aKey[i] then
342 begin
343 Result := False;
344 break;
345 end;
346 inc(Temp);
347 end;
348 end else Result := False;
349 end; { KeyComp }
350
TSynJavaSyn.Func17null351 function TSynJavaSyn.Func17: TtkTokenKind;
352 begin
353 if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
354 end;
355
Func21null356 function TSynJavaSyn.Func21: TtkTokenKind;
357 begin
358 if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
359 end;
360
Func32null361 function TSynJavaSyn.Func32: TtkTokenKind;
362 begin
363 if KeyComp('case') then Result := tkKey else Result := tkIdentifier;
364 end;
365
Func34null366 function TSynJavaSyn.Func34: TtkTokenKind;
367 begin
368 if KeyComp('char') then Result := tkKey else Result := tkIdentifier;
369 end;
370
Func40null371 function TSynJavaSyn.Func40: TtkTokenKind;
372 begin
373 if KeyComp('catch') then Result := tkKey else Result := tkIdentifier;
374 end;
375
Func42null376 function TSynJavaSyn.Func42: TtkTokenKind;
377 begin
378 if KeyComp('for') then Result := tkKey else
379 if KeyComp('break') then Result := tkKey else Result := tkIdentifier;
380 end;
381
Func45null382 function TSynJavaSyn.Func45: TtkTokenKind;
383 begin
384 if KeyComp('else') then Result := tkKey else
385 if KeyComp('new') then Result := tkKey else Result := tkIdentifier;
386 end;
387
Func46null388 function TSynJavaSyn.Func46: TtkTokenKind;
389 begin
390 if KeyComp('int') then Result := tkKey else Result := tkIdentifier;
391 end;
392
Func47null393 function TSynJavaSyn.Func47: TtkTokenKind;
394 begin
395 if KeyComp('final') then Result := tkKey else Result := tkIdentifier;
396 end;
397
TSynJavaSyn.Func48null398 function TSynJavaSyn.Func48: TtkTokenKind;
399 begin
400 if KeyComp('false') then Result := tkKey else Result := tkIdentifier;
401 end;
402
Func51null403 function TSynJavaSyn.Func51: TtkTokenKind;
404 begin
405 if KeyComp('package') then Result := tkKey else Result := tkIdentifier;
406 end;
407
Func52null408 function TSynJavaSyn.Func52: TtkTokenKind;
409 begin
410 if KeyComp('long') then Result := tkKey else Result := tkIdentifier;
411 end;
412
Func54null413 function TSynJavaSyn.Func54: TtkTokenKind;
414 begin
415 if KeyComp('void') then Result := tkKey else Result := tkIdentifier;
416 end;
417
Func56null418 function TSynJavaSyn.Func56: TtkTokenKind;
419 begin
420 if KeyComp('byte') then Result := tkKey else Result := tkIdentifier;
421 end;
422
TSynJavaSyn.Func59null423 function TSynJavaSyn.Func59: TtkTokenKind;
424 begin
425 if KeyComp('class') then Result := tkKey else
426 if KeyComp('float') then Result := tkKey else Result := tkIdentifier;
427 end;
428
Func60null429 function TSynJavaSyn.Func60: TtkTokenKind;
430 begin
431 if KeyComp('this') then Result := tkKey else Result := tkIdentifier;
432 end;
433
Func61null434 function TSynJavaSyn.Func61: TtkTokenKind;
435 begin
436 if KeyComp('goto') then Result := tkKey else Result := tkIdentifier;
437 end;
438
Func62null439 function TSynJavaSyn.Func62: TtkTokenKind;
440 begin
441 if KeyComp('while') then Result := tkKey else Result := tkIdentifier;
442 end;
443
Func63null444 function TSynJavaSyn.Func63: TtkTokenKind;
445 begin
446 if KeyComp('null') then Result := tkKey else Result := tkIdentifier;
447 end;
448
Func65null449 function TSynJavaSyn.Func65: TtkTokenKind;
450 begin
451 if KeyComp('double') then Result := tkKey else Result := tkIdentifier;
452 end;
453
Func66null454 function TSynJavaSyn.Func66: TtkTokenKind;
455 begin
456 if KeyComp('try') then Result := tkKey else Result := tkIdentifier;
457 end;
458
Func68null459 function TSynJavaSyn.Func68: TtkTokenKind;
460 begin
461 if KeyComp('true') then Result := tkKey else Result := tkIdentifier;
462 end;
463
Func69null464 function TSynJavaSyn.Func69: TtkTokenKind;
465 begin
466 if KeyComp('public') then Result := tkKey else Result := tkIdentifier;
467 end;
468
Func71null469 function TSynJavaSyn.Func71: TtkTokenKind;
470 begin
471 if KeyComp('boolean') then Result := tkKey else Result := tkIdentifier;
472 end;
473
Func76null474 function TSynJavaSyn.Func76: TtkTokenKind;
475 begin
476 if KeyComp('default') then Result := tkKey else
477 if KeyComp('const') then Result := tkKey else Result := tkIdentifier;
478 end;
479
Func77null480 function TSynJavaSyn.Func77: TtkTokenKind;
481 begin
482 if KeyComp('native') then Result := tkKey else Result := tkIdentifier;
483 end;
484
Func78null485 function TSynJavaSyn.Func78: TtkTokenKind;
486 begin
487 if KeyComp('static') then Result := tkKey else Result := tkIdentifier;
488 end;
489
Func84null490 function TSynJavaSyn.Func84: TtkTokenKind;
491 begin
492 if KeyComp('super') then Result := tkKey else Result := tkIdentifier;
493 end;
494
Func85null495 function TSynJavaSyn.Func85: TtkTokenKind;
496 begin
497 if KeyComp('short') then Result := tkKey else Result := tkIdentifier;
498 end;
499
Func86null500 function TSynJavaSyn.Func86: TtkTokenKind;
501 begin
502 if KeyComp('finally') then Result := tkKey else Result := tkIdentifier;
503 end;
504
Func88null505 function TSynJavaSyn.Func88: TtkTokenKind;
506 begin
507 if KeyComp('switch') then Result := tkKey else
508 if KeyComp('assert') then Result := tkKey else Result := tkIdentifier;
509 end;
510
Func89null511 function TSynJavaSyn.Func89: TtkTokenKind;
512 begin
513 if KeyComp('throw') then Result := tkKey else Result := tkIdentifier;
514 end;
515
TSynJavaSyn.Func90null516 function TSynJavaSyn.Func90: TtkTokenKind;
517 begin
518 if KeyComp('interface') then Result := tkKey else Result := tkIdentifier;
519 end;
520
Func92null521 function TSynJavaSyn.Func92: TtkTokenKind;
522 begin
523 if KeyComp('abstract') then Result := tkKey else Result := tkIdentifier;
524 end;
525
Func97null526 function TSynJavaSyn.Func97: TtkTokenKind;
527 begin
528 if KeyComp('import') then Result := tkKey else Result := tkIdentifier;
529 end;
530
Func98null531 function TSynJavaSyn.Func98: TtkTokenKind;
532 begin
533 if KeyComp('extends') then Result := tkKey else
534 if KeyComp('private') then Result := tkKey else Result := tkIdentifier;
535 end;
536
TSynJavaSyn.Func102null537 function TSynJavaSyn.Func102: TtkTokenKind;
538 begin
539 if KeyComp('return') then Result := tkKey else Result := tkIdentifier;
540 end;
541
TSynJavaSyn.Func104null542 function TSynJavaSyn.Func104: TtkTokenKind;
543 begin
544 if KeyComp('volatile') then Result := tkKey else Result := tkIdentifier;
545 end;
546
Func109null547 function TSynJavaSyn.Func109: TtkTokenKind;
548 begin
549 if KeyComp('continue') then Result := tkKey else
550 if KeyComp('throws') then Result := tkKey else Result := tkIdentifier;
551 end;
552
TSynJavaSyn.Func115null553 function TSynJavaSyn.Func115: TtkTokenKind;
554 begin
555 if KeyComp('protected') then Result := tkKey else Result := tkIdentifier;
556 end;
557
TSynJavaSyn.Func116null558 function TSynJavaSyn.Func116: TtkTokenKind;
559 begin
560 if KeyComp('instanceof') then Result := tkKey else Result := tkIdentifier;
561 end;
562
Func119null563 function TSynJavaSyn.Func119: TtkTokenKind;
564 begin
565 if KeyComp('strictfp') then Result := tkKey else Result := tkIdentifier;
566 end;
567
Func129null568 function TSynJavaSyn.Func129: TtkTokenKind;
569 begin
570 if KeyComp('transient') then Result := tkKey else Result := tkIdentifier;
571 end;
572
TSynJavaSyn.Func136null573 function TSynJavaSyn.Func136: TtkTokenKind;
574 begin
575 if KeyComp('implements') then Result := tkKey else Result := tkIdentifier;
576 end;
577
TSynJavaSyn.Func172null578 function TSynJavaSyn.Func172: TtkTokenKind;
579 begin
580 if KeyComp('synchronized') then Result := tkKey else Result := tkIdentifier;
581 end;
582
TSynJavaSyn.AltFuncnull583 function TSynJavaSyn.AltFunc: TtkTokenKind;
584 begin
585 Result := tkIdentifier;
586 end;
587
TSynJavaSyn.IdentKindnull588 function TSynJavaSyn.IdentKind(MayBe: PChar): TtkTokenKind;
589 var
590 HashKey: Integer;
591 begin
592 fToIdent := MayBe;
593 HashKey := KeyHash(MayBe);
594 if HashKey < 173 then
595 Result := fIdentFuncTable[HashKey]()
596 else
597 Result := tkIdentifier;
598 end;
599
600 procedure TSynJavaSyn.MakeMethodTables;
601 var
602 I: Char;
603 begin
604 for I := #0 to #255 do
605 case I of
606 '&': fProcTable[I] := @AndSymbolProc;
607 #39: fProcTable[I] := @AsciiCharProc;
608 '@': fProcTable[I] := @AnnotationProc;
609 '}': fProcTable[I] := @BraceCloseProc;
610 '{': fProcTable[I] := @BraceOpenProc;
611 #13: fProcTable[I] := @CRProc;
612 ':': fProcTable[I] := @ColonProc;
613 ',': fProcTable[I] := @CommaProc;
614 '=': fProcTable[I] := @EqualProc;
615 '>': fProcTable[I] := @GreaterProc;
616 'A'..'Z', 'a'..'z', '_', '$':
617 fProcTable[I] := @IdentProc;
618 #10: fProcTable[I] := @LFProc;
619 '<': fProcTable[I] := @LowerProc;
620 '-': fProcTable[I] := @MinusProc;
621 '*': fProcTable[I] := @MultiplyProc;
622 '!': fProcTable[I] := @NotSymbolProc;
623 #0: fProcTable[I] := @NullProc;
624 '0'..'9': fProcTable[I] := @NumberProc;
625 '|': fProcTable[I] := @OrSymbolProc;
626 '+': fProcTable[I] := @PlusProc;
627 '.': fProcTable[I] := @PointProc;
628 '#': fProcTable[I] := @PoundProc;
629 '?': fProcTable[I] := @QuestionProc;
630 '%': fProcTable[I] := @RemainderSymbolProc;
631 ')': fProcTable[I] := @RoundCloseProc;
632 '(': fProcTable[I] := @RoundOpenProc;
633 ';': fProcTable[I] := @SemiColonProc;
634 '/': fProcTable[I] := @SlashProc;
635 #1..#9, #11, #12, #14..#32:
636 fProcTable[I] := @SpaceProc;
637 ']': fProcTable[I] := @SquareCloseProc;
638 '[': fProcTable[I] := @SquareOpenProc;
639 #34: fProcTable[I] := @StringProc;
640 '~': fProcTable[I] := @TildeProc;
641 '^': fProcTable[I] := @XOrSymbolProc;
642 else
643 if (I in TSynSpecialChars) then
644 fProcTable[I] := @IdentProc
645 else
646 fProcTable[I] := @UnknownProc;
647 end;
648 end;
649
650 constructor TSynJavaSyn.Create(AOwner: TComponent);
651 begin
652 inherited Create(AOwner);
653 fAnnotationAttri := TSynHighlighterAttributes.Create(@SYNS_AttrAnnotation, SYNS_XML_AttrAnnotation);
654 AddAttribute(fAnnotationAttri);
655 fCommentAttri := TSynHighlighterAttributes.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
656 fCommentAttri.Style := [fsItalic];
657 AddAttribute(fCommentAttri);
658 fDocumentAttri := TSynHighlighterAttributes.Create(@SYNS_AttrDocumentation, SYNS_XML_AttrDocumentation);
659 fDocumentAttri.Style := [fsItalic];
660 AddAttribute(fDocumentAttri);
661 fIdentifierAttri := TSynHighlighterAttributes.Create(@SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
662 AddAttribute(fIdentifierAttri);
663 fInvalidAttri := TSynHighlighterAttributes.Create(@SYNS_AttrInvalidSymbol, SYNS_XML_AttrInvalidSymbol);
664 AddAttribute(fInvalidAttri);
665 fKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrReservedWord, SYNS_XML_AttrReservedWord);
666 fKeyAttri.Style := [fsBold];
667 AddAttribute(fKeyAttri);
668 fNumberAttri := TSynHighlighterAttributes.Create(@SYNS_AttrNumber, SYNS_XML_AttrNumber);
669 AddAttribute(fNumberAttri);
670 fSpaceAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSpace, SYNS_XML_AttrSpace);
671 fSpaceAttri.Foreground := clWindow;
672 AddAttribute(fSpaceAttri);
673 fStringAttri := TSynHighlighterAttributes.Create(@SYNS_AttrString, SYNS_XML_AttrString);
674 AddAttribute(fStringAttri);
675 fSymbolAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
676 AddAttribute(fSymbolAttri);
677 fRange := rsUnknown;
678 SetAttributesOnChange(@DefHighlightChange);
679
680 InitIdent;
681 MakeMethodTables;
682 fDefaultFilter := SYNS_FilterJava;
683 end; { Create }
684
685 procedure TSynJavaSyn.SetLine(const NewValue: String;
686 LineNumber:Integer);
687 begin
688 inherited;
689 fLine := PChar(NewValue);
690 Run := 0;
691 fEol := False;
692 fLineNumber := LineNumber;
693 Next;
694 end; { SetLine }
695
696 procedure TSynJavaSyn.CommentProc;
697 begin
698 if fRange = rsComment then
699 fTokenID := tkComment
700 else
701 fTokenID := tkDocument;
702 case FLine[Run] of
703 #0:
704 begin
705 NullProc;
706 exit;
707 end;
708 #10:
709 begin
710 LFProc;
711 exit;
712 end;
713 #13:
714 begin
715 CRProc;
716 exit;
717 end;
718 end;
719
720 while FLine[Run] <> #0 do
721 case FLine[Run] of
722 '*':
723 if fLine[Run + 1] = '/' then
724 begin
725 inc(Run, 2);
726 fRange := rsUnknown;
727 break;
728 end
729 else inc(Run);
730 #10: break;
731 #13: break;
732 else inc(Run);
733 end;
734 end;
735
736 procedure TSynJavaSyn.AndSymbolProc;
737 begin
738 case FLine[Run + 1] of
739 '=': {and assign}
740 begin
741 inc(Run, 2);
742 fTokenID := tkSymbol;
743 FExtTokenID := xtkAndAssign;
744 end;
745 '&': {conditional and}
746 begin
747 inc(Run, 2);
748 fTokenID := tkSymbol;
749 FExtTokenID := xtkCondAnd;
750 end;
751 else {and}
752 begin
753 inc(Run);
754 fTokenID := tkSymbol;
755 FExtTokenID := xtkAnd;
756 end;
757 end;
758 end;
759
760 procedure TSynJavaSyn.AsciiCharProc;
761 begin
762 fTokenID := tkString;
763 repeat
764 case FLine[Run] of
765 #0, #10, #13: break;
766 #92: Inc(Run); // backslash, if we have an escaped single character, skip to the next
767 end;
768 if FLine[Run] <> #0 then inc(Run); //Add check here to prevent overrun from backslash being last char
769 until FLine[Run] = #39;
770 if FLine[Run] <> #0 then inc(Run);
771 end;
772
773 procedure TSynJavaSyn.AnnotationProc;
774 begin
775 inc(Run);
776 fTokenID := tkAnnotation;
777 while Identifiers[fLine[Run]] do inc(Run);
778 end;
779
780 procedure TSynJavaSyn.BraceCloseProc;
781 begin
782 inc(Run);
783 fTokenId := tkSymbol;
784 FExtTokenID := xtkBraceClose;
785 end;
786
787 procedure TSynJavaSyn.BraceOpenProc;
788 begin
789 inc(Run);
790 fTokenId := tkSymbol;
791 FExtTokenID := xtkBraceOpen;
792 end;
793
794 procedure TSynJavaSyn.CRProc;
795 begin
796 fTokenID := tkSpace;
797 Case FLine[Run + 1] of
798 #10: inc(Run, 2);
799 else inc(Run);
800 end;
801 end;
802
803 procedure TSynJavaSyn.ColonProc;
804 begin
805 inc(Run); {colon - conditional}
806 fTokenID := tkSymbol;
807 FExtTokenID := xtkColon;
808 end;
809
810 procedure TSynJavaSyn.CommaProc;
811 begin
812 inc(Run);
813 fTokenID := tkSymbol; //tkInvalid; //DDH Addition from Eden Kirin
814 fExtTokenID := xtkComma; //GBN 13/12/2001
815 end;
816
817 procedure TSynJavaSyn.EqualProc;
818 begin
819 case FLine[Run + 1] of
820 '=': {logical equal}
821 begin
822 inc(Run, 2);
823 fTokenID := tkSymbol;
824 FExtTokenID := xtkLogEqual;
825 end;
826 else {assign}
827 begin
828 inc(Run);
829 fTokenID := tkSymbol;
830 FExtTokenID := xtkAssign;
831 end;
832 end;
833 end;
834
835 procedure TSynJavaSyn.GreaterProc;
836 begin
837 Case FLine[Run + 1] of
838 '=': {greater than or equal to}
839 begin
840 inc(Run, 2);
841 fTokenID := tkSymbol;
842 FExtTokenID := xtkGreaterThanEqual;
843 end;
844 '>':
845 begin
846 Case FLine[Run + 2] of
847 '=': {shift right assign}
848 begin
849 inc(Run, 3);
850 FExtTokenID := xtkShiftRightAssign;
851 end;
852 '>':
853 if FLine[Run + 3] = '=' then
854 begin
855 inc(Run, 4); {unsigned shift right assign}
856 FExtTokenID := xtkUnsignShiftRightAssign;
857 end
858 else
859 begin
860 inc(Run, 3); {unsigned shift right}
861 FExtTokenID := xtkUnsignShiftRight;
862 end;
863 else {shift right}
864 begin
865 inc(Run, 2);
866 FExtTokenID := xtkShiftRight;
867 end;
868 end;
869 fTokenID := tkSymbol;
870 end;
871 else {greater than}
872 begin
873 inc(Run);
874 fTokenID := tkSymbol;
875 FExtTokenID := xtkGreaterThan;
876 end;
877 end;
878 end;
879
880 procedure TSynJavaSyn.IdentProc;
881 begin
882 fTokenID := IdentKind((fLine + Run));
883 inc(Run, fStringLen);
884 while Identifiers[fLine[Run]] do inc(Run);
885 end;
886
887 procedure TSynJavaSyn.LFProc;
888 begin
889 fTokenID := tkSpace;
890 inc(Run);
891 end;
892
893 procedure TSynJavaSyn.LowerProc;
894 begin
895 case FLine[Run + 1] of
896 '=': {less than or equal to}
897 begin
898 inc(Run, 2);
899 fTokenID := tkSymbol;
900 FExtTokenID := xtkLessThanEqual;
901 end;
902 '<':
903 begin
904 if FLine[Run + 2] = '=' then {shift left assign}
905 begin
906 inc(Run, 3);
907 FExtTokenID := xtkShiftLeftAssign;
908 end
909 else {shift left}
910 begin
911 inc(Run, 2);
912 FExtTokenID := xtkShiftLeft;
913 end;
914 fTokenID := tkSymbol;
915 end;
916 else {less than}
917 begin
918 inc(Run);
919 fTokenID := tkSymbol;
920 FExtTokenID := xtkLessThan;
921 end;
922 end;
923 end;
924
925 procedure TSynJavaSyn.MinusProc;
926 begin
927 case FLine[Run + 1] of
928 '=': {subtract assign}
929 begin
930 inc(Run, 2);
931 fTokenID := tkSymbol;
932 FExtTokenID := xtkSubtractAssign;
933 end;
934 '-': {decrement}
935 begin
936 inc(Run, 2);
937 fTokenID := tkSymbol;
938 FExtTokenID := xtkDecrement;
939 end;
940 else {subtract}
941 begin
942 inc(Run);
943 fTokenID := tkSymbol;
944 FExtTokenID := xtkSubtract;
945 end;
946 end;
947 end;
948
949 procedure TSynJavaSyn.MultiplyProc;
950 begin
951 case FLine[Run + 1] of
952 '=': {multiply assign}
953 begin
954 inc(Run, 2);
955 fTokenID := tkSymbol;
956 FExtTokenID := xtkMultiplyAssign;
957 end;
958 else {multiply}
959 begin
960 inc(Run);
961 fTokenID := tkSymbol;
962 FExtTokenID := xtkMultiply;
963 end;
964 end;
965 end;
966
967 procedure TSynJavaSyn.NotSymbolProc;
968 begin
969 case FLine[Run + 1] of
970 '=': {not equal}
971 begin
972 inc(Run, 2);
973 fTokenID := tkSymbol;
974 FExtTokenID := xtkNotEqual;
975 end;
976 else {logical complement}
977 begin
978 inc(Run);
979 fTokenID := tkSymbol;
980 FExtTokenID := xtkLogComplement;
981 end;
982 end;
983 end;
984
985 procedure TSynJavaSyn.NullProc;
986 begin
987 fTokenID := tkNull;
988 fEol := True;
989 end;
990
991 procedure TSynJavaSyn.NumberProc;
992 begin
993 fTokenID := tkNumber;
994 if (FLine[Run] = '0') and (FLine[Run+1] in ['x', 'X'])then
995 begin
996 inc(Run, 2);
997 while FLine[Run] in ['0'..'9', 'A'..'F', 'a'..'f'] do inc(Run);
998 if FLine[Run] in ['l', 'L'] then inc(Run);
999 exit;
1000 end;
1001
1002 inc(Run);
1003 while FLine[Run] in ['0'..'9'] do inc(Run);
1004 if (FLine[Run]='.') and not(fLine[Run+1]='.') then begin
1005 inc(Run);
1006 while FLine[Run] in ['0'..'9'] do inc(Run);
1007 end;
1008 if (FLine[Run]='e') or (fLine[Run]='E') then begin
1009 inc(Run);
1010 if (FLine[Run]='+') or (fLine[Run]='-') then inc(Run);
1011 while FLine[Run] in ['0'..'9'] do inc(Run);
1012 end;
1013 if FLine[Run] in ['l', 'L'] then inc(Run);
1014 end;
1015
1016 procedure TSynJavaSyn.OrSymbolProc;
1017 begin
1018 case FLine[Run + 1] of
1019 '=': {inclusive or assign}
1020 begin
1021 inc(Run, 2);
1022 fTokenID := tkSymbol;
1023 FExtTokenID := xtkIncOrAssign;
1024 end;
1025 '|': {conditional or}
1026 begin
1027 inc(Run, 2);
1028 fTokenID := tkSymbol;
1029 FExtTokenID := xtkCondOr;
1030 end;
1031 else {inclusive or}
1032 begin
1033 inc(Run);
1034 fTokenID := tkSymbol;
1035 FExtTokenID := xtkIncOr;
1036 end;
1037 end;
1038 end;
1039
1040 procedure TSynJavaSyn.PlusProc;
1041 begin
1042 case FLine[Run + 1] of
1043 '=': {add assign}
1044 begin
1045 inc(Run, 2);
1046 fTokenID := tkSymbol;
1047 FExtTokenID := xtkAddAssign;
1048 end;
1049 '+': {increment}
1050 begin
1051 inc(Run, 2);
1052 fTokenID := tkSymbol;
1053 FExtTokenID := xtkIncrement;
1054 end;
1055 else {add}
1056 begin
1057 inc(Run);
1058 fTokenID := tkSymbol;
1059 FExtTokenID := xtkAdd;
1060 end;
1061 end;
1062 end;
1063
1064 procedure TSynJavaSyn.PointProc;
1065 begin
1066 inc(Run); {point}
1067 if FLine[Run] in ['0'..'9'] then
1068 begin
1069 NumberProc;
1070 Exit;
1071 end;
1072 fTokenID := tkSymbol;
1073 FExtTokenID := xtkPoint;
1074 end;
1075
1076 procedure TSynJavaSyn.PoundProc;
1077 begin
1078 inc(Run);
1079 fTokenID := tkInvalid;
1080 end;
1081
1082 procedure TSynJavaSyn.QuestionProc;
1083 begin
1084 fTokenID := tkSymbol; {question mark - conditional}
1085 FExtTokenID := xtkQuestion;
1086 inc(Run);
1087 end;
1088
1089 procedure TSynJavaSyn.RemainderSymbolProc;
1090 begin
1091 case FLine[Run + 1] of
1092 '=': {remainder assign}
1093 begin
1094 inc(Run, 2);
1095 fTokenID := tkSymbol;
1096 FExtTokenID := xtkRemainderAssign;
1097 end;
1098 else {remainder}
1099 begin
1100 inc(Run);
1101 fTokenID := tkSymbol;
1102 FExtTokenID := xtkRemainder;
1103 end;
1104 end;
1105 end;
1106
1107 procedure TSynJavaSyn.RoundCloseProc;
1108 begin
1109 inc(Run);
1110 fTokenID := tkSymbol;
1111 FExtTokenID := xtkRoundClose;
1112 dec(FRoundCount);
1113 end;
1114
1115 procedure TSynJavaSyn.RoundOpenProc;
1116 begin
1117 inc(Run);
1118 FTokenID := tkSymbol;
1119 FExtTokenID := xtkRoundOpen;
1120 inc(FRoundCount);
1121 end;
1122
1123 procedure TSynJavaSyn.SemiColonProc;
1124 begin
1125 inc(Run); {semicolon}
1126 fTokenID := tkSymbol;
1127 FExtTokenID := xtkSemiColon;
1128 end;
1129
1130 procedure TSynJavaSyn.SlashProc;
1131 begin
1132 case FLine[Run + 1] of
1133 '/': {c++ style comments}
1134 begin
1135 inc(Run, 2);
1136 fTokenID := tkComment;
1137 while FLine[Run] <> #0 do
1138 begin
1139 case FLine[Run] of
1140 #10, #13: break;
1141 end;
1142 inc(Run);
1143 end;
1144 end;
1145 '*':
1146 begin
1147 if fLine[Run+2] = '*' then {documentation comment}
1148 begin
1149 fRange := rsDocument;
1150 fTokenID := tkDocument;
1151 inc(Run);
1152 end
1153 else {c style comment}
1154 begin
1155 fRange := rsComment;
1156 fTokenID := tkComment;
1157 end;
1158
1159 inc(Run,2);
1160 while fLine[Run] <> #0 do
1161 case fLine[Run] of
1162 '*':
1163 if fLine[Run + 1] = '/' then
1164 begin
1165 inc(Run, 2);
1166 fRange := rsUnknown;
1167 break;
1168 end else inc(Run);
1169 #10: break;
1170 #13: break;
1171 else
1172 inc(Run);
1173 end;
1174 end;
1175 '=': {division assign}
1176 begin
1177 inc(Run, 2);
1178 fTokenID := tkSymbol;
1179 FExtTokenID := xtkDivideAssign;
1180 end;
1181 else {division}
1182 begin
1183 inc(Run);
1184 fTokenID := tkSymbol;
1185 FExtTokenID := xtkDivide;
1186 end;
1187 end;
1188 end;
1189
1190 procedure TSynJavaSyn.SpaceProc;
1191 begin
1192 inc(Run);
1193 fTokenID := tkSpace;
1194 while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
1195 end;
1196
1197 procedure TSynJavaSyn.SquareCloseProc;
1198 begin
1199 inc(Run);
1200 fTokenID := tkSymbol;
1201 FExtTokenID := xtkSquareClose;
1202 dec(FSquareCount);
1203 end;
1204
1205 procedure TSynJavaSyn.SquareOpenProc;
1206 begin
1207 inc(Run);
1208 fTokenID := tkSymbol;
1209 FExtTokenID := xtkSquareOpen;
1210 inc(FSquareCount);
1211 end;
1212
1213 procedure TSynJavaSyn.StringProc;
1214 begin
1215 fTokenID := tkString;
1216 if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34) then inc(Run, 2);
1217 repeat
1218 case FLine[Run] of
1219 #0, #10, #13: break;
1220 #92: Inc(Run); // Backslash, if we have an escaped charcter it can be skipped
1221 end;
1222 if FLine[Run] <> #0 then inc(Run); //Add check here to prevent overrun from backslash being last char
1223 until FLine[Run] = #34;
1224 if FLine[Run] <> #0 then inc(Run);
1225 end;
1226
1227 procedure TSynJavaSyn.TildeProc;
1228 begin
1229 inc(Run); {bitwise complement}
1230 fTokenId := tkSymbol;
1231 FExtTokenID := xtkBitComplement;
1232 end;
1233
1234 procedure TSynJavaSyn.XOrSymbolProc;
1235 begin
1236 Case FLine[Run + 1] of
1237 '=': {xor assign}
1238 begin
1239 inc(Run, 2);
1240 fTokenID := tkSymbol;
1241 FExtTokenID := xtkXorAssign;
1242 end;
1243 else {xor}
1244 begin
1245 inc(Run);
1246 fTokenID := tkSymbol;
1247 FExtTokenID := xtkXor;
1248 end;
1249 end;
1250 end;
1251
1252 procedure TSynJavaSyn.UnknownProc;
1253 begin
1254 {$IFDEF SYN_MBCSSUPPORT}
1255 if FLine[Run] in LeadBytes then
1256 Inc(Run,2)
1257 else
1258 {$ENDIF}
1259 inc(Run);
1260 while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
1261 ((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
1262 fTokenID := tkUnknown;
1263 end;
1264
1265 procedure TSynJavaSyn.Next;
1266 begin
1267 fTokenPos := Run;
1268 FExtTokenID := xtkNonSymbol;
1269 Case fRange of
1270 rsComment: CommentProc;
1271 rsDocument: CommentProc;
1272 else
1273 begin
1274 fRange := rsUnknown;
1275 fProcTable[fLine[Run]];
1276 end;
1277 end;
1278 end;
1279
TSynJavaSyn.GetDefaultAttributenull1280 function TSynJavaSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
1281 begin
1282 case Index of
1283 SYN_ATTR_COMMENT: Result := fCommentAttri;
1284 SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
1285 SYN_ATTR_KEYWORD: Result := fKeyAttri;
1286 SYN_ATTR_STRING: Result := fStringAttri;
1287 SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
1288 SYN_ATTR_SYMBOL: Result := fSymbolAttri;
1289 SYN_ATTR_NUMBER: Result := fNumberAttri;
1290 else Result := nil;
1291 end;
1292 end;
1293
GetEolnull1294 function TSynJavaSyn.GetEol: Boolean;
1295 begin
1296 Result := fTokenID = tkNull;
1297 end;
1298
GetRangenull1299 function TSynJavaSyn.GetRange: Pointer;
1300 begin
1301 Result := Pointer(PtrInt(fRange));
1302 end;
1303
1304 procedure TSynJavaSyn.ReSetRange;
1305 begin
1306 fRange := rsUnknown;
1307 end;
1308
1309 procedure TSynJavaSyn.SetRange(Value: Pointer);
1310 begin
1311 fRange := TRangeState(PtrUInt(Value));
1312 end;
1313
GetTokennull1314 function TSynJavaSyn.GetToken: String;
1315 var
1316 Len: LongInt;
1317 begin
1318 Result := '';
1319 Len := Run - fTokenPos;
1320 SetString(Result, (FLine + fTokenPos), Len);
1321 end;
1322
1323 procedure TSynJavaSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
1324 begin
1325 TokenLength:=Run-fTokenPos;
1326 TokenStart:=FLine + fTokenPos;
1327 end;
1328
GetTokenIDnull1329 function TSynJavaSyn.GetTokenID: TtkTokenKind;
1330 begin
1331 Result := fTokenId;
1332 end;
1333
GetExtTokenIDnull1334 function TSynJavaSyn.GetExtTokenID: TxtkTokenKind;
1335 begin
1336 if FTokenID = tkSymbol then
1337 Result := FExtTokenID
1338 else
1339 Result := xtkNonSymbol;
1340 end;
1341
GetTokenAttributenull1342 function TSynJavaSyn.GetTokenAttribute: TSynHighlighterAttributes;
1343 begin
1344 case fTokenID of
1345 tkAnnotation: Result := fAnnotationAttri;
1346 tkComment: Result := fCommentAttri;
1347 tkDocument: Result := fDocumentAttri;
1348 tkIdentifier: Result := fIdentifierAttri;
1349 tkInvalid: Result := fInvalidAttri;
1350 tkKey: Result := fKeyAttri;
1351 tkNumber: Result := fNumberAttri;
1352 tkSpace: Result := fSpaceAttri;
1353 tkString: Result := fStringAttri;
1354 tkSymbol: Result := fSymbolAttri;
1355 tkUnknown: Result := fInvalidAttri;
1356 else Result := nil;
1357 end;
1358 end;
1359
GetTokenKindnull1360 function TSynJavaSyn.GetTokenKind: integer;
1361 begin
1362 Result := Ord(fTokenId);
1363 end;
1364
GetTokenPosnull1365 function TSynJavaSyn.GetTokenPos: Integer;
1366 begin
1367 Result := fTokenPos;
1368 end;
1369
GetIdentCharsnull1370 function TSynJavaSyn.GetIdentChars: TSynIdentChars;
1371 begin
1372 Result := ['_', '$', '0'..'9', 'a'..'z', 'A'..'Z'] + TSynSpecialChars;
1373 end;
1374
TSynJavaSyn.GetLanguageNamenull1375 class function TSynJavaSyn.GetLanguageName: string;
1376 begin
1377 Result := SYNS_LangJava;
1378 end;
1379
GetSampleSourcenull1380 function TSynJavaSyn.GetSampleSource: string;
1381 begin
1382 Result := '/* Java syntax highlighting */'#13#10 +
1383 'import java.util.*;'#13#10 +
1384 #13#10 +
1385 '/** Example class */'#13#10 +
1386 'public class Sample {'#13#10 +
1387 ' public static void main(String[] args) {'#13#10 +
1388 ' int i = 0;'#13#10 +
1389 ' for(i = 0; i < 10; i++)'#13#10 +
1390 ' System.out.println("Hello world");'#13#10 +
1391 ' }'#13#10 +
1392 '}';
1393 end;
1394
1395 initialization
1396 MakeIdentTable;
1397 RegisterPlaceableHighlighter(TSynJavaSyn);
1398
1399 end.
1400
1401