| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | unit SynHighlighterAA; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | interface |
|---|
| 49 | |
|---|
| 50 | uses |
|---|
| 51 | |
|---|
| 52 | QGraphics, |
|---|
| 53 | QSynEditTypes, |
|---|
| 54 | QSynEditHighlighter, |
|---|
| 55 | |
|---|
| 56 | Windows, |
|---|
| 57 | Graphics, |
|---|
| 58 | SynEditTypes, |
|---|
| 59 | SynEditHighlighter, |
|---|
| 60 | |
|---|
| 61 | SysUtils, |
|---|
| 62 | Classes, |
|---|
| 63 | assemblerunit; |
|---|
| 64 | |
|---|
| 65 | type |
|---|
| 66 | TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber, |
|---|
| 67 | tkSpace, tkString, tkSymbol, tkUnknown, tkFloat, tkHex, tkDirec, tkChar, |
|---|
| 68 | tkRegister); |
|---|
| 69 | |
|---|
| 70 | TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty, |
|---|
| 71 | rsExports, rsDirective, rsDirectiveAsm, rsUnKnown); |
|---|
| 72 | |
|---|
| 73 | TProcTableProc = procedure of object; |
|---|
| 74 | |
|---|
| 75 | PIdentFuncTableFunc = ^TIdentFuncTableFunc; |
|---|
| 76 | TIdentFuncTableFunc = function: TtkTokenKind of object; |
|---|
| 77 | |
|---|
| 78 | TAutoAssemblerVersion = (dvAutoAssembler1, dvAutoAssembler2, dvAutoAssembler3, dvAutoAssembler4, dvAutoAssembler5, |
|---|
| 79 | dvAutoAssembler6, dvAutoAssembler7, dvAutoAssembler8, dvAutoAssembler2005); |
|---|
| 80 | |
|---|
| 81 | const |
|---|
| 82 | LastAutoAssemblerVersion = dvAutoAssembler2005; |
|---|
| 83 | |
|---|
| 84 | type |
|---|
| 85 | TSynAASyn = class(TSynCustomHighlighter) |
|---|
| 86 | private |
|---|
| 87 | fAsmStart: Boolean; |
|---|
| 88 | fRange: TRangeState; |
|---|
| 89 | fLine: PChar; |
|---|
| 90 | fLineNumber: Integer; |
|---|
| 91 | fProcTable: array[#0..#255] of TProcTableProc; |
|---|
| 92 | Run: LongInt; |
|---|
| 93 | fStringLen: Integer; |
|---|
| 94 | fToIdent: PChar; |
|---|
| 95 | fIdentFuncTable: array[0..222] of TIdentFuncTableFunc; |
|---|
| 96 | fTokenPos: Integer; |
|---|
| 97 | FTokenID: TtkTokenKind; |
|---|
| 98 | fStringAttri: TSynHighlighterAttributes; |
|---|
| 99 | fCharAttri: TSynHighlighterAttributes; |
|---|
| 100 | fNumberAttri: TSynHighlighterAttributes; |
|---|
| 101 | fFloatAttri: TSynHighlighterAttributes; |
|---|
| 102 | fHexAttri: TSynHighlighterAttributes; |
|---|
| 103 | fKeyAttri: TSynHighlighterAttributes; |
|---|
| 104 | fSymbolAttri: TSynHighlighterAttributes; |
|---|
| 105 | fAsmAttri: TSynHighlighterAttributes; |
|---|
| 106 | fCommentAttri: TSynHighlighterAttributes; |
|---|
| 107 | fDirecAttri: TSynHighlighterAttributes; |
|---|
| 108 | fIdentifierAttri: TSynHighlighterAttributes; |
|---|
| 109 | fSpaceAttri: TSynHighlighterAttributes; |
|---|
| 110 | fRegisterAttri: TSynHighlighterAttributes; |
|---|
| 111 | fAutoAssemblerVersion: TAutoAssemblerVersion; |
|---|
| 112 | fPackageSource: Boolean; |
|---|
| 113 | function KeyHash(ToHash: PChar): Integer; |
|---|
| 114 | function KeyComp(const aKey: string): Boolean; |
|---|
| 115 | function Func9: TtkTokenKind; //ah |
|---|
| 116 | function Func10: TtkTokenKind; //bh |
|---|
| 117 | function Func11: TtkTokenKind; //ch |
|---|
| 118 | function Func12: TtkTokenKind; //dh |
|---|
| 119 | function Func13: TtkTokenKind; //di / al |
|---|
| 120 | function Func14: TtkTokenKind; //bl |
|---|
| 121 | function Func15: TtkTokenKind; //cl |
|---|
| 122 | function Func16: TtkTokenKind; //dl |
|---|
| 123 | function Func18: TtkTokenKind; //edi / bp |
|---|
| 124 | function Func23: TtkTokenKind; //ebp |
|---|
| 125 | function Func25: TtkTokenKind; //ax / 25 |
|---|
| 126 | function Func26: TtkTokenKind; //bx |
|---|
| 127 | function Func27: TtkTokenKind; //cx |
|---|
| 128 | function Func28: TtkTokenKind; //dx / si |
|---|
| 129 | function Func30: TtkTokenKind; //eax / eip |
|---|
| 130 | function Func31: TtkTokenKind; //ebx |
|---|
| 131 | function Func32: TtkTokenKind; //ecx |
|---|
| 132 | function Func33: TtkTokenKind; //edx / esi |
|---|
| 133 | function Func35: TtkTokenKind; //sp |
|---|
| 134 | function Func39: TtkTokenKind; //enable |
|---|
| 135 | function Func40: TtkTokenKind; //esp |
|---|
| 136 | function Func43: TtkTokenKind; //alloc /define |
|---|
| 137 | function Func52: TtkTokenKind; //dealloc / disable |
|---|
| 138 | function Func54: TtkTokenKind; //kalloc |
|---|
| 139 | function Func59: TtkTokenKind; //readmem |
|---|
| 140 | function Func68: TtkTokenKind; //include |
|---|
| 141 | function Func82: TtkTokenKind; //assert |
|---|
| 142 | function Func92: TtkTokenKind; //globalalloc |
|---|
| 143 | function Func101: TtkTokenKind; //fullaccess/loadbinary |
|---|
| 144 | function Func108: TtkTokenKind; //CreateThread |
|---|
| 145 | function Func117: TtkTokenKind; //loadlibrary |
|---|
| 146 | function Func187: TtkTokenKind; //registersymbol |
|---|
| 147 | function Func222: TtkTokenKind; //unregistersymbol |
|---|
| 148 | |
|---|
| 149 | function AltFunc: TtkTokenKind; |
|---|
| 150 | procedure InitIdent; |
|---|
| 151 | function getfirsttoken(s: string): string; |
|---|
| 152 | function IdentKind(MayBe: PChar): TtkTokenKind; |
|---|
| 153 | procedure MakeMethodTables; |
|---|
| 154 | procedure AddressOpProc; |
|---|
| 155 | procedure AsciiCharProc; |
|---|
| 156 | procedure AnsiProc; |
|---|
| 157 | procedure BorProc; |
|---|
| 158 | procedure BraceOpenProc; |
|---|
| 159 | procedure ColonOrGreaterProc; |
|---|
| 160 | procedure CRProc; |
|---|
| 161 | procedure IdentProc; |
|---|
| 162 | procedure IntegerProc; |
|---|
| 163 | procedure LFProc; |
|---|
| 164 | procedure LowerProc; |
|---|
| 165 | procedure NullProc; |
|---|
| 166 | procedure NumberProc; |
|---|
| 167 | procedure PointProc; |
|---|
| 168 | procedure RoundOpenProc; |
|---|
| 169 | procedure SemicolonProc; |
|---|
| 170 | procedure SlashProc; |
|---|
| 171 | procedure SpaceProc; |
|---|
| 172 | procedure StringProc; |
|---|
| 173 | procedure SymbolProc; |
|---|
| 174 | procedure UnknownProc; |
|---|
| 175 | procedure SetAutoAssemblerVersion(const Value: TAutoAssemblerVersion); |
|---|
| 176 | procedure SetPackageSource(const Value: Boolean); |
|---|
| 177 | protected |
|---|
| 178 | function GetIdentChars: TSynIdentChars; override; |
|---|
| 179 | function GetSampleSource: string; override; |
|---|
| 180 | function IsFilterStored: boolean; override; |
|---|
| 181 | public |
|---|
| 182 | class function GetCapabilities: TSynHighlighterCapabilities; override; |
|---|
| 183 | class function GetLanguageName: string; override; |
|---|
| 184 | public |
|---|
| 185 | constructor Create(AOwner: TComponent); override; |
|---|
| 186 | function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; |
|---|
| 187 | override; |
|---|
| 188 | function GetEol: Boolean; override; |
|---|
| 189 | function GetRange: Pointer; override; |
|---|
| 190 | function GetToken: string; override; |
|---|
| 191 | function GetTokenAttribute: TSynHighlighterAttributes; override; |
|---|
| 192 | function GetTokenID: TtkTokenKind; |
|---|
| 193 | function GetTokenKind: integer; override; |
|---|
| 194 | function GetTokenPos: Integer; override; |
|---|
| 195 | procedure Next; override; |
|---|
| 196 | procedure ResetRange; override; |
|---|
| 197 | procedure SetLine(NewValue: string; LineNumber:Integer); override; |
|---|
| 198 | procedure SetRange(Value: Pointer); override; |
|---|
| 199 | property IdentChars; |
|---|
| 200 | published |
|---|
| 201 | property AsmAttri: TSynHighlighterAttributes read fAsmAttri write fAsmAttri; |
|---|
| 202 | property CommentAttri: TSynHighlighterAttributes read fCommentAttri |
|---|
| 203 | write fCommentAttri; |
|---|
| 204 | property DirectiveAttri: TSynHighlighterAttributes read fDirecAttri |
|---|
| 205 | write fDirecAttri; |
|---|
| 206 | property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri |
|---|
| 207 | write fIdentifierAttri; |
|---|
| 208 | property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri; |
|---|
| 209 | property RegisterAttri: TSynHighlighterAttributes read fRegisterAttri write fRegisterAttri; |
|---|
| 210 | property NumberAttri: TSynHighlighterAttributes read fNumberAttri |
|---|
| 211 | write fNumberAttri; |
|---|
| 212 | property FloatAttri: TSynHighlighterAttributes read fFloatAttri |
|---|
| 213 | write fFloatAttri; |
|---|
| 214 | property HexAttri: TSynHighlighterAttributes read fHexAttri |
|---|
| 215 | write fHexAttri; |
|---|
| 216 | property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri |
|---|
| 217 | write fSpaceAttri; |
|---|
| 218 | property StringAttri: TSynHighlighterAttributes read fStringAttri |
|---|
| 219 | write fStringAttri; |
|---|
| 220 | property CharAttri: TSynHighlighterAttributes read fCharAttri |
|---|
| 221 | write fCharAttri; |
|---|
| 222 | property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri |
|---|
| 223 | write fSymbolAttri; |
|---|
| 224 | property AutoAssemblerVersion: TAutoAssemblerVersion read fAutoAssemblerVersion write SetAutoAssemblerVersion |
|---|
| 225 | default LastAutoAssemblerVersion; |
|---|
| 226 | property PackageSource: Boolean read fPackageSource write SetPackageSource default True; |
|---|
| 227 | end; |
|---|
| 228 | |
|---|
| 229 | procedure aa_AddExtraCommand(command:pchar); |
|---|
| 230 | procedure aa_RemoveExtraCommand(command:pchar); |
|---|
| 231 | function isExtraCommand(token:string): boolean; |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | implementation |
|---|
| 235 | |
|---|
| 236 | uses |
|---|
| 237 | |
|---|
| 238 | QSynEditStrConst; |
|---|
| 239 | |
|---|
| 240 | SynEditStrConst; |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | var |
|---|
| 244 | Identifiers: array[#0..#255] of ByteBool; |
|---|
| 245 | mHashTable: array[#0..#255] of Integer; |
|---|
| 246 | |
|---|
| 247 | extraCommands: Tstringlist; |
|---|
| 248 | |
|---|
| 249 | procedure aa_AddExtraCommand(command:pchar); |
|---|
| 250 | begin |
|---|
| 251 | if extraCommands=nil then |
|---|
| 252 | begin |
|---|
| 253 | extraCommands:=tstringlist.create; |
|---|
| 254 | extraCommands.Duplicates:=dupIgnore; |
|---|
| 255 | extracommands.CaseSensitive:=false; |
|---|
| 256 | end; |
|---|
| 257 | |
|---|
| 258 | extraCommands.Add(command); |
|---|
| 259 | end; |
|---|
| 260 | |
|---|
| 261 | procedure aa_RemoveExtraCommand(command:pchar); |
|---|
| 262 | begin |
|---|
| 263 | if extracommands<>nil then |
|---|
| 264 | begin |
|---|
| 265 | extracommands.Delete(extracommands.IndexOf(command)); |
|---|
| 266 | if extracommands.Count=0 then |
|---|
| 267 | freeandnil(extracommands); |
|---|
| 268 | end; |
|---|
| 269 | end; |
|---|
| 270 | |
|---|
| 271 | function isExtraCommand(token: string): boolean; |
|---|
| 272 | begin |
|---|
| 273 | result:=false; |
|---|
| 274 | if extracommands<>nil then |
|---|
| 275 | result:=extracommands.IndexOf(token)<>-1; |
|---|
| 276 | end; |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | procedure MakeIdentTable; |
|---|
| 280 | var |
|---|
| 281 | I, J: Char; |
|---|
| 282 | begin |
|---|
| 283 | for I := #0 to #255 do |
|---|
| 284 | begin |
|---|
| 285 | Case I of |
|---|
| 286 | '_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True; |
|---|
| 287 | else Identifiers[I] := False; |
|---|
| 288 | end; |
|---|
| 289 | J := UpCase(I); |
|---|
| 290 | Case I of |
|---|
| 291 | 'a'..'z', 'A'..'Z', '_': mHashTable[I] := Ord(J) - 64; |
|---|
| 292 | else mHashTable[Char(I)] := 0; |
|---|
| 293 | end; |
|---|
| 294 | end; |
|---|
| 295 | end; |
|---|
| 296 | |
|---|
| 297 | procedure TSynAASyn.InitIdent; |
|---|
| 298 | var |
|---|
| 299 | I: Integer; |
|---|
| 300 | pF: PIdentFuncTableFunc; |
|---|
| 301 | begin |
|---|
| 302 | pF := PIdentFuncTableFunc(@fIdentFuncTable); |
|---|
| 303 | for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin |
|---|
| 304 | pF^ := AltFunc; |
|---|
| 305 | Inc(pF); |
|---|
| 306 | end; |
|---|
| 307 | fIdentFuncTable[9] := Func9; |
|---|
| 308 | fIdentFuncTable[10] := Func10; |
|---|
| 309 | fIdentFuncTable[11] := Func11; |
|---|
| 310 | fIdentFuncTable[12] := Func12; |
|---|
| 311 | fIdentFuncTable[13] := Func13; |
|---|
| 312 | fIdentFuncTable[14] := Func14; |
|---|
| 313 | fIdentFuncTable[15] := Func15; |
|---|
| 314 | fIdentFuncTable[16] := Func16; |
|---|
| 315 | fIdentFuncTable[18] := Func18; |
|---|
| 316 | fIdentFuncTable[23] := Func23; |
|---|
| 317 | fIdentFuncTable[25] := Func25; |
|---|
| 318 | fIdentFuncTable[26] := Func26; |
|---|
| 319 | fIdentFuncTable[27] := Func27; |
|---|
| 320 | fIdentFuncTable[28] := Func28; |
|---|
| 321 | fIdentFuncTable[30] := Func30; |
|---|
| 322 | fIdentFuncTable[31] := Func31; |
|---|
| 323 | fIdentFuncTable[32] := Func32; |
|---|
| 324 | fIdentFuncTable[33] := Func33; |
|---|
| 325 | fIdentFuncTable[35] := Func35; |
|---|
| 326 | fIdentFuncTable[39] := Func39; |
|---|
| 327 | fIdentFuncTable[40] := Func40; |
|---|
| 328 | fIdentFuncTable[43] := Func43; |
|---|
| 329 | fIdentFuncTable[52] := Func52; |
|---|
| 330 | fIdentFuncTable[54] := Func54; |
|---|
| 331 | fIdentFuncTable[59] := Func59; |
|---|
| 332 | fIdentFuncTable[68] := Func68; |
|---|
| 333 | fIdentFuncTable[82] := Func82; |
|---|
| 334 | fIdentFuncTable[92] := Func92; |
|---|
| 335 | fIdentFuncTable[101] := Func101; |
|---|
| 336 | fIdentFuncTable[108] := Func108; |
|---|
| 337 | fIdentFuncTable[117] := Func117; |
|---|
| 338 | fIdentFuncTable[187] := Func187; |
|---|
| 339 | fIdentFuncTable[222] := Func222; |
|---|
| 340 | end; |
|---|
| 341 | |
|---|
| 342 | function TSynAASyn.KeyHash(ToHash: PChar): Integer; |
|---|
| 343 | begin |
|---|
| 344 | Result := 0; |
|---|
| 345 | while ToHash^ in ['a'..'z', 'A'..'Z'] do |
|---|
| 346 | begin |
|---|
| 347 | inc(Result, mHashTable[ToHash^]); |
|---|
| 348 | inc(ToHash); |
|---|
| 349 | end; |
|---|
| 350 | if ToHash^ in ['_', '0'..'9'] then inc(ToHash); |
|---|
| 351 | fStringLen := ToHash - fToIdent; |
|---|
| 352 | end; |
|---|
| 353 | |
|---|
| 354 | function TSynAASyn.KeyComp(const aKey: string): Boolean; |
|---|
| 355 | var |
|---|
| 356 | I: Integer; |
|---|
| 357 | Temp: PChar; |
|---|
| 358 | begin |
|---|
| 359 | Temp := fToIdent; |
|---|
| 360 | if Length(aKey) = fStringLen then |
|---|
| 361 | begin |
|---|
| 362 | Result := True; |
|---|
| 363 | for i := 1 to fStringLen do |
|---|
| 364 | begin |
|---|
| 365 | if mHashTable[Temp^] <> mHashTable[aKey[i]] then |
|---|
| 366 | begin |
|---|
| 367 | Result := False; |
|---|
| 368 | break; |
|---|
| 369 | end; |
|---|
| 370 | inc(Temp); |
|---|
| 371 | end; |
|---|
| 372 | end else Result := False; |
|---|
| 373 | end; |
|---|
| 374 | |
|---|
| 375 | function TSynAASyn.Func9: TtkTokenKind; |
|---|
| 376 | begin |
|---|
| 377 | if KeyComp('ah') then Result := tkRegister else |
|---|
| 378 | Result := tkIdentifier; |
|---|
| 379 | end; |
|---|
| 380 | |
|---|
| 381 | function TSynAASyn.Func10: TtkTokenKind; |
|---|
| 382 | begin |
|---|
| 383 | if KeyComp('bh') then Result := tkRegister else |
|---|
| 384 | Result := tkIdentifier; |
|---|
| 385 | end; |
|---|
| 386 | |
|---|
| 387 | function TSynAASyn.Func11: TtkTokenKind; |
|---|
| 388 | begin |
|---|
| 389 | if KeyComp('ch') then Result := tkRegister else |
|---|
| 390 | Result := tkIdentifier; |
|---|
| 391 | end; |
|---|
| 392 | |
|---|
| 393 | function TSynAASyn.Func12: TtkTokenKind; |
|---|
| 394 | begin |
|---|
| 395 | if KeyComp('dh') then Result := tkRegister else |
|---|
| 396 | Result := tkIdentifier; |
|---|
| 397 | end; |
|---|
| 398 | |
|---|
| 399 | function TSynAASyn.Func13: TtkTokenKind; |
|---|
| 400 | begin |
|---|
| 401 | if KeyComp('di') then Result := tkRegister else |
|---|
| 402 | if KeyComp('al') then Result := tkRegister else |
|---|
| 403 | Result := tkIdentifier; |
|---|
| 404 | end; |
|---|
| 405 | |
|---|
| 406 | function TSynAASyn.Func14: TtkTokenKind; |
|---|
| 407 | begin |
|---|
| 408 | if KeyComp('bl') then Result := tkRegister else |
|---|
| 409 | Result := tkIdentifier; |
|---|
| 410 | end; |
|---|
| 411 | |
|---|
| 412 | function TSynAASyn.Func15: TtkTokenKind; |
|---|
| 413 | begin |
|---|
| 414 | if KeyComp('cl') then Result := tkRegister else |
|---|
| 415 | Result := tkIdentifier; |
|---|
| 416 | end; |
|---|
| 417 | |
|---|
| 418 | function TSynAASyn.Func16: TtkTokenKind; |
|---|
| 419 | begin |
|---|
| 420 | if KeyComp('dl') then Result := tkRegister else |
|---|
| 421 | Result := tkIdentifier; |
|---|
| 422 | end; |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | function TSynAASyn.Func18: TtkTokenKind; |
|---|
| 426 | begin |
|---|
| 427 | if KeyComp('edi') then Result := tkRegister else |
|---|
| 428 | if KeyComp('bp') then Result := tkRegister else |
|---|
| 429 | Result := tkIdentifier; |
|---|
| 430 | end; |
|---|
| 431 | |
|---|
| 432 | function TSynAASyn.Func23: TtkTokenKind; |
|---|
| 433 | begin |
|---|
| 434 | if KeyComp('ebp') then Result := tkRegister else |
|---|
| 435 | Result := tkIdentifier; |
|---|
| 436 | end; |
|---|
| 437 | |
|---|
| 438 | function TSynAASyn.Func25: TtkTokenKind; |
|---|
| 439 | begin |
|---|
| 440 | if KeyComp('ax') then Result := tkRegister else |
|---|
| 441 | if KeyComp('ip') then Result := tkRegister else |
|---|
| 442 | Result := tkIdentifier; |
|---|
| 443 | end; |
|---|
| 444 | |
|---|
| 445 | function TSynAASyn.Func26: TtkTokenKind; |
|---|
| 446 | begin |
|---|
| 447 | if KeyComp('bx') then Result := tkRegister else |
|---|
| 448 | Result := tkIdentifier; |
|---|
| 449 | end; |
|---|
| 450 | |
|---|
| 451 | function TSynAASyn.Func27: TtkTokenKind; |
|---|
| 452 | begin |
|---|
| 453 | if KeyComp('cx') then Result := tkRegister else |
|---|
| 454 | Result := tkIdentifier; |
|---|
| 455 | end; |
|---|
| 456 | |
|---|
| 457 | function TSynAASyn.Func28: TtkTokenKind; |
|---|
| 458 | begin |
|---|
| 459 | if KeyComp('dx') then Result := tkRegister else |
|---|
| 460 | if KeyComp('si') then Result := tkRegister else |
|---|
| 461 | Result := tkIdentifier; |
|---|
| 462 | end; |
|---|
| 463 | |
|---|
| 464 | function TSynAASyn.Func30: TtkTokenKind; |
|---|
| 465 | begin |
|---|
| 466 | if KeyComp('eax') then Result := tkRegister else |
|---|
| 467 | if KeyComp('eip') then Result := tkRegister else |
|---|
| 468 | Result := tkIdentifier; |
|---|
| 469 | end; |
|---|
| 470 | |
|---|
| 471 | function TSynAASyn.Func31: TtkTokenKind; |
|---|
| 472 | begin |
|---|
| 473 | if KeyComp('ebx') then Result := tkRegister else |
|---|
| 474 | Result := tkIdentifier; |
|---|
| 475 | end; |
|---|
| 476 | |
|---|
| 477 | function TSynAASyn.Func32: TtkTokenKind; |
|---|
| 478 | begin |
|---|
| 479 | if KeyComp('Label') then Result := tkKey else |
|---|
| 480 | if KeyComp('ecx') then Result := tkRegister else |
|---|
| 481 | Result := tkIdentifier; |
|---|
| 482 | end; |
|---|
| 483 | |
|---|
| 484 | function TSynAASyn.Func33: TtkTokenKind; |
|---|
| 485 | begin |
|---|
| 486 | if KeyComp('edx') then Result := tkRegister else |
|---|
| 487 | if KeyComp('esi') then Result := tkRegister else |
|---|
| 488 | Result := tkIdentifier; |
|---|
| 489 | end; |
|---|
| 490 | |
|---|
| 491 | function TSynAASyn.Func35: TtkTokenKind; |
|---|
| 492 | begin |
|---|
| 493 | if KeyComp('bp') then Result := tkRegister else |
|---|
| 494 | Result := tkIdentifier; |
|---|
| 495 | end; |
|---|
| 496 | |
|---|
| 497 | function TSynAASyn.Func39: TtkTokenKind; //enable |
|---|
| 498 | begin |
|---|
| 499 | if KeyComp('enable') then Result := tkspace else |
|---|
| 500 | Result := tkIdentifier; |
|---|
| 501 | end; |
|---|
| 502 | |
|---|
| 503 | function TSynAASyn.Func40: TtkTokenKind; //enable |
|---|
| 504 | begin |
|---|
| 505 | if KeyComp('esp') then Result := tkRegister else |
|---|
| 506 | Result := tkIdentifier; |
|---|
| 507 | end; |
|---|
| 508 | |
|---|
| 509 | function TSynAASyn.Func43: TtkTokenKind; //alloc /define |
|---|
| 510 | begin |
|---|
| 511 | if KeyComp('alloc') then Result := tkKey else |
|---|
| 512 | if KeyComp('define') then Result := tkKey else |
|---|
| 513 | Result := tkIdentifier; |
|---|
| 514 | end; |
|---|
| 515 | |
|---|
| 516 | function TSynAASyn.Func52: TtkTokenKind; //dealloc |
|---|
| 517 | begin |
|---|
| 518 | if KeyComp('dealloc') then Result := tkKey else |
|---|
| 519 | if KeyComp('disable') then Result := tkspace else |
|---|
| 520 | Result := tkIdentifier; |
|---|
| 521 | end; |
|---|
| 522 | |
|---|
| 523 | function TSynAASyn.Func54: TtkTokenKind; //kalloc |
|---|
| 524 | begin |
|---|
| 525 | if KeyComp('kalloc') then Result := tkKey else |
|---|
| 526 | Result := tkIdentifier; |
|---|
| 527 | end; |
|---|
| 528 | |
|---|
| 529 | function TSynAASyn.Func59: TtkTokenKind; //readmem |
|---|
| 530 | begin |
|---|
| 531 | if KeyComp('readmem') then Result := tkKey else |
|---|
| 532 | Result := tkIdentifier; |
|---|
| 533 | end; |
|---|
| 534 | |
|---|
| 535 | function TSynAASyn.Func68: TtkTokenKind; //include |
|---|
| 536 | begin |
|---|
| 537 | if KeyComp('include') then Result := tkKey else |
|---|
| 538 | Result := tkIdentifier; |
|---|
| 539 | end; |
|---|
| 540 | |
|---|
| 541 | function TSynAASyn.Func82: TtkTokenKind; //include |
|---|
| 542 | begin |
|---|
| 543 | if KeyComp('assert') then Result := tkKey else |
|---|
| 544 | Result := tkIdentifier; |
|---|
| 545 | end; |
|---|
| 546 | |
|---|
| 547 | function TSynAASyn.Func92: TtkTokenKind; //globalalloc |
|---|
| 548 | begin |
|---|
| 549 | if KeyComp('globalalloc') then Result := tkKey else |
|---|
| 550 | Result := tkIdentifier; |
|---|
| 551 | end; |
|---|
| 552 | |
|---|
| 553 | function TSynAASyn.Func101: TtkTokenKind; |
|---|
| 554 | begin |
|---|
| 555 | if KeyComp('LoadBinary') then Result := tkKey else |
|---|
| 556 | if KeyComp('fullaccess') then Result := tkKey else |
|---|
| 557 | Result := tkIdentifier; |
|---|
| 558 | end; |
|---|
| 559 | |
|---|
| 560 | function TSynAASyn.Func108: TtkTokenKind; //CreateThread |
|---|
| 561 | begin |
|---|
| 562 | if KeyComp('createthread') then Result := tkKey else |
|---|
| 563 | Result := tkIdentifier; |
|---|
| 564 | end; |
|---|
| 565 | |
|---|
| 566 | function TSynAASyn.Func117: TtkTokenKind; //loadlibrary |
|---|
| 567 | begin |
|---|
| 568 | if KeyComp('loadlibrary') then Result := tkKey else |
|---|
| 569 | Result := tkIdentifier; |
|---|
| 570 | end; |
|---|
| 571 | |
|---|
| 572 | function TSynAASyn.Func187: TtkTokenKind; //registersymbol |
|---|
| 573 | begin |
|---|
| 574 | if KeyComp('registersymbol') then Result := tkKey else |
|---|
| 575 | Result := tkIdentifier; |
|---|
| 576 | end; |
|---|
| 577 | |
|---|
| 578 | function TSynAASyn.Func222: TtkTokenKind; //unregistersymbol |
|---|
| 579 | begin |
|---|
| 580 | if KeyComp('unregistersymbol') then Result := tkKey else |
|---|
| 581 | Result := tkIdentifier; |
|---|
| 582 | end; |
|---|
| 583 | |
|---|
| 584 | function TSynAASyn.AltFunc: TtkTokenKind; |
|---|
| 585 | begin |
|---|
| 586 | Result := tkIdentifier |
|---|
| 587 | end; |
|---|
| 588 | |
|---|
| 589 | function TSynAASyn.getfirsttoken(s: string): string; |
|---|
| 590 | var i: integer; |
|---|
| 591 | begin |
|---|
| 592 | result:=s; |
|---|
| 593 | for i:=1 to length(s) do |
|---|
| 594 | begin |
|---|
| 595 | if (s[i]='(') or (s[i]=' ') or (s[i]=#9) or (s[i]=',') or (s[i]=#10) or (s[i]=#13) then |
|---|
| 596 | begin |
|---|
| 597 | result:=copy(s,1,i-1); |
|---|
| 598 | exit; |
|---|
| 599 | end; |
|---|
| 600 | end; |
|---|
| 601 | end; |
|---|
| 602 | |
|---|
| 603 | function TSynAASyn.IdentKind(MayBe: PChar): TtkTokenKind; |
|---|
| 604 | var |
|---|
| 605 | HashKey: Integer; |
|---|
| 606 | begin |
|---|
| 607 | fToIdent := MayBe; |
|---|
| 608 | HashKey := KeyHash(MayBe); |
|---|
| 609 | if HashKey < 223 then Result := fIdentFuncTable[HashKey] else |
|---|
| 610 | Result := tkIdentifier; |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | if (result=tkIdentifier) then |
|---|
| 614 | begin |
|---|
| 615 | if GetOpcodesIndex(getfirsttoken(maybe))<>-1 then |
|---|
| 616 | result:=tkKey |
|---|
| 617 | else |
|---|
| 618 | if isExtraCommand(getfirsttoken(maybe)) then |
|---|
| 619 | result:=tkKey; |
|---|
| 620 | end; |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | end; |
|---|
| 624 | |
|---|
| 625 | procedure TSynAASyn.MakeMethodTables; |
|---|
| 626 | var |
|---|
| 627 | I: Char; |
|---|
| 628 | begin |
|---|
| 629 | for I := #0 to #255 do |
|---|
| 630 | case I of |
|---|
| 631 | #0: fProcTable[I] := NullProc; |
|---|
| 632 | #10: fProcTable[I] := LFProc; |
|---|
| 633 | #13: fProcTable[I] := CRProc; |
|---|
| 634 | #1..#9, #11, #12, #14..#32: |
|---|
| 635 | fProcTable[I] := SpaceProc; |
|---|
| 636 | '#': fProcTable[I] := IntegerProc; |
|---|
| 637 | #39: fProcTable[I] := StringProc; |
|---|
| 638 | '0'..'9': fProcTable[I] := NumberProc; |
|---|
| 639 | 'A'..'Z', 'a'..'z', '_': |
|---|
| 640 | fProcTable[I] := IdentProc; |
|---|
| 641 | '{': fProcTable[I] := BraceOpenProc; |
|---|
| 642 | '}', '!', '"', '%', '&', '('..'/', ':'..'@', '['..'^', '`', '~': |
|---|
| 643 | begin |
|---|
| 644 | case I of |
|---|
| 645 | '(': fProcTable[I] := RoundOpenProc; |
|---|
| 646 | '.': fProcTable[I] := PointProc; |
|---|
| 647 | ';': fProcTable[I] := SemicolonProc; |
|---|
| 648 | '/': fProcTable[I] := SlashProc; |
|---|
| 649 | ':', '>': fProcTable[I] := ColonOrGreaterProc; |
|---|
| 650 | '<': fProcTable[I] := LowerProc; |
|---|
| 651 | '@': fProcTable[I] := AddressOpProc; |
|---|
| 652 | else |
|---|
| 653 | fProcTable[I] := SymbolProc; |
|---|
| 654 | end; |
|---|
| 655 | end; |
|---|
| 656 | else |
|---|
| 657 | fProcTable[I] := UnknownProc; |
|---|
| 658 | end; |
|---|
| 659 | end; |
|---|
| 660 | |
|---|
| 661 | constructor TSynAASyn.Create(AOwner: TComponent); |
|---|
| 662 | begin |
|---|
| 663 | inherited Create(AOwner); |
|---|
| 664 | fAutoAssemblerVersion := LastAutoAssemblerVersion; |
|---|
| 665 | fPackageSource := True; |
|---|
| 666 | |
|---|
| 667 | fAsmAttri := TSynHighlighterAttributes.Create(SYNS_AttrAssembler); |
|---|
| 668 | AddAttribute(fAsmAttri); |
|---|
| 669 | fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment); |
|---|
| 670 | fCommentAttri.Style:= [fsItalic]; |
|---|
| 671 | fCommentAttri.Foreground:=clBlue; |
|---|
| 672 | |
|---|
| 673 | AddAttribute(fCommentAttri); |
|---|
| 674 | fDirecAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor); |
|---|
| 675 | fDirecAttri.Style:= [fsItalic]; |
|---|
| 676 | AddAttribute(fDirecAttri); |
|---|
| 677 | fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier); |
|---|
| 678 | AddAttribute(fIdentifierAttri); |
|---|
| 679 | fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord); |
|---|
| 680 | fKeyAttri.Style:= [fsBold]; |
|---|
| 681 | |
|---|
| 682 | fRegisterAttri := TSynHighlighterAttributes.Create('Register'); |
|---|
| 683 | fRegisterAttri.Style:= [fsBold]; |
|---|
| 684 | fRegisterAttri.Foreground:=$0080f0; |
|---|
| 685 | |
|---|
| 686 | AddAttribute(fKeyAttri); |
|---|
| 687 | fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber); |
|---|
| 688 | fNumberAttri.Foreground:=clGreen; |
|---|
| 689 | |
|---|
| 690 | AddAttribute(fNumberAttri); |
|---|
| 691 | fFloatAttri := TSynHighlighterAttributes.Create(SYNS_AttrFloat); |
|---|
| 692 | fFloatAttri.Foreground:=clGreen; |
|---|
| 693 | AddAttribute(fFloatAttri); |
|---|
| 694 | |
|---|
| 695 | fHexAttri := TSynHighlighterAttributes.Create(SYNS_AttrHexadecimal); |
|---|
| 696 | fHexAttri.Foreground:=clGreen; |
|---|
| 697 | AddAttribute(fHexAttri); |
|---|
| 698 | |
|---|
| 699 | fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace); |
|---|
| 700 | fSpaceAttri.Foreground:=clNavy; |
|---|
| 701 | AddAttribute(fSpaceAttri); |
|---|
| 702 | |
|---|
| 703 | fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString); |
|---|
| 704 | fStringAttri.Foreground:=clRed; |
|---|
| 705 | |
|---|
| 706 | AddAttribute(fStringAttri); |
|---|
| 707 | fCharAttri := TSynHighlighterAttributes.Create(SYNS_AttrCharacter); |
|---|
| 708 | // fCharAttri.Foreground:=clRed; |
|---|
| 709 | AddAttribute(fCharAttri); |
|---|
| 710 | fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol); |
|---|
| 711 | AddAttribute(fSymbolAttri); |
|---|
| 712 | SetAttributesOnChange(DefHighlightChange); |
|---|
| 713 | |
|---|
| 714 | InitIdent; |
|---|
| 715 | MakeMethodTables; |
|---|
| 716 | fRange := rsUnknown; |
|---|
| 717 | fAsmStart := False; |
|---|
| 718 | fDefaultFilter := SYNS_FilterPascal; |
|---|
| 719 | end; |
|---|
| 720 | |
|---|
| 721 | procedure TSynAASyn.SetLine(NewValue: string; LineNumber:Integer); |
|---|
| 722 | begin |
|---|
| 723 | fLine := PChar(NewValue); |
|---|
| 724 | Run := 0; |
|---|
| 725 | fLineNumber := LineNumber; |
|---|
| 726 | Next; |
|---|
| 727 | end; |
|---|
| 728 | |
|---|
| 729 | procedure TSynAASyn.AddressOpProc; |
|---|
| 730 | begin |
|---|
| 731 | fTokenID := tkSymbol; |
|---|
| 732 | inc(Run); |
|---|
| 733 | if fLine[Run] = '@' then inc(Run); |
|---|
| 734 | end; |
|---|
| 735 | |
|---|
| 736 | procedure TSynAASyn.AsciiCharProc; |
|---|
| 737 | begin |
|---|
| 738 | fTokenID := tkChar; |
|---|
| 739 | Inc(Run); |
|---|
| 740 | while FLine[Run] in ['0'..'9', '$', 'A'..'F', 'a'..'f'] do |
|---|
| 741 | Inc(Run); |
|---|
| 742 | end; |
|---|
| 743 | |
|---|
| 744 | procedure TSynAASyn.BorProc; |
|---|
| 745 | begin |
|---|
| 746 | case fLine[Run] of |
|---|
| 747 | #0: NullProc; |
|---|
| 748 | #10: LFProc; |
|---|
| 749 | #13: CRProc; |
|---|
| 750 | else |
|---|
| 751 | begin |
|---|
| 752 | if fRange in [rsDirective, rsDirectiveAsm] then |
|---|
| 753 | fTokenID := tkDirec |
|---|
| 754 | else |
|---|
| 755 | fTokenID := tkComment; |
|---|
| 756 | repeat |
|---|
| 757 | if fLine[Run] = '}' then |
|---|
| 758 | begin |
|---|
| 759 | Inc(Run); |
|---|
| 760 | if fRange in [rsBorAsm, rsDirectiveAsm] then |
|---|
| 761 | fRange := rsAsm |
|---|
| 762 | else |
|---|
| 763 | fRange := rsUnKnown; |
|---|
| 764 | break; |
|---|
| 765 | end; |
|---|
| 766 | Inc(Run); |
|---|
| 767 | until fLine[Run] in [#0, #10, #13]; |
|---|
| 768 | end; |
|---|
| 769 | end; |
|---|
| 770 | end; |
|---|
| 771 | |
|---|
| 772 | procedure TSynAASyn.BraceOpenProc; |
|---|
| 773 | begin |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | |
|---|
| 783 | if fRange = rsAsm then |
|---|
| 784 | fRange := rsBorAsm |
|---|
| 785 | else |
|---|
| 786 | fRange := rsBor; |
|---|
| 787 | //end; |
|---|
| 788 | BorProc; |
|---|
| 789 | end; |
|---|
| 790 | |
|---|
| 791 | procedure TSynAASyn.ColonOrGreaterProc; |
|---|
| 792 | begin |
|---|
| 793 | fTokenID := tkSymbol; |
|---|
| 794 | inc(Run); |
|---|
| 795 | if fLine[Run] = '=' then inc(Run); |
|---|
| 796 | end; |
|---|
| 797 | |
|---|
| 798 | procedure TSynAASyn.CRProc; |
|---|
| 799 | begin |
|---|
| 800 | fTokenID := tkSpace; |
|---|
| 801 | inc(Run); |
|---|
| 802 | if fLine[Run] = #10 then |
|---|
| 803 | Inc(Run); |
|---|
| 804 | end; |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | procedure TSynAASyn.IdentProc; |
|---|
| 808 | begin |
|---|
| 809 | fTokenID := IdentKind((fLine + Run)); |
|---|
| 810 | inc(Run, fStringLen); |
|---|
| 811 | while Identifiers[fLine[Run]] do |
|---|
| 812 | Inc(Run); |
|---|
| 813 | end; |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | procedure TSynAASyn.IntegerProc; |
|---|
| 817 | begin |
|---|
| 818 | inc(Run); |
|---|
| 819 | fTokenID := tkHex; |
|---|
| 820 | while FLine[Run] in ['0'..'9', 'A'..'F', 'a'..'f'] do |
|---|
| 821 | Inc(Run); |
|---|
| 822 | end; |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | procedure TSynAASyn.LFProc; |
|---|
| 826 | begin |
|---|
| 827 | fTokenID := tkSpace; |
|---|
| 828 | inc(Run); |
|---|
| 829 | end; |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | procedure TSynAASyn.LowerProc; |
|---|
| 833 | begin |
|---|
| 834 | fTokenID := tkSymbol; |
|---|
| 835 | inc(Run); |
|---|
| 836 | if fLine[Run] in ['=', '>'] then |
|---|
| 837 | Inc(Run); |
|---|
| 838 | end; |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | procedure TSynAASyn.NullProc; |
|---|
| 842 | begin |
|---|
| 843 | fTokenID := tkNull; |
|---|
| 844 | end; |
|---|
| 845 | |
|---|
| 846 | procedure TSynAASyn.NumberProc; |
|---|
| 847 | begin |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | fTokenID := IdentKind((fLine + Run)); |
|---|
| 870 | |
|---|
| 871 | if fTokenID=tkIdentifier then |
|---|
| 872 | begin |
|---|
| 873 | inc(Run); |
|---|
| 874 | fTokenID := tkNumber; |
|---|
| 875 | while FLine[Run] in ['0'..'9', '.', 'a'..'f' , 'A'..'F'] do |
|---|
| 876 | begin |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | |
|---|
| 880 | |
|---|
| 881 | inc(Run); |
|---|
| 882 | end; |
|---|
| 883 | |
|---|
| 884 | if ((FLine[Run]>'G') and (FLine[Run]<='Z')) or ((FLine[Run]>='g') and (FLine[Run]<='z')) then |
|---|
| 885 | fTokenID:=tkIdentifier; |
|---|
| 886 | end |
|---|
| 887 | else |
|---|
| 888 | begin |
|---|
| 889 | inc(Run, fStringLen); |
|---|
| 890 | while Identifiers[fLine[Run]] do inc(Run); |
|---|
| 891 | end; |
|---|
| 892 | end; |
|---|
| 893 | |
|---|
| 894 | procedure TSynAASyn.PointProc; |
|---|
| 895 | begin |
|---|
| 896 | fTokenID := tkSymbol; |
|---|
| 897 | inc(Run); |
|---|
| 898 | if fLine[Run] in ['.', ')'] then |
|---|
| 899 | Inc(Run); |
|---|
| 900 | end; |
|---|
| 901 | |
|---|
| 902 | procedure TSynAASyn.AnsiProc; |
|---|
| 903 | begin |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | case fLine[Run] of |
|---|
| 923 | #0: NullProc; |
|---|
| 924 | #10: LFProc; |
|---|
| 925 | #13: CRProc; |
|---|
| 926 | else |
|---|
| 927 | fTokenID := tkComment; |
|---|
| 928 | repeat |
|---|
| 929 | if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then begin |
|---|
| 930 | Inc(Run, 2); |
|---|
| 931 | if fRange = rsAnsiAsm then |
|---|
| 932 | fRange := rsAsm |
|---|
| 933 | else |
|---|
| 934 | fRange := rsUnKnown; |
|---|
| 935 | break; |
|---|
| 936 | end; |
|---|
| 937 | Inc(Run); |
|---|
| 938 | until fLine[Run] in [#0, #10, #13]; |
|---|
| 939 | end; |
|---|
| 940 | end; |
|---|
| 941 | |
|---|
| 942 | procedure TSynAASyn.RoundOpenProc; |
|---|
| 943 | begin |
|---|
| 944 | Inc(Run); |
|---|
| 945 | case fLine[Run] of |
|---|
| 946 | |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | |
|---|
| 957 | '.': |
|---|
| 958 | begin |
|---|
| 959 | inc(Run); |
|---|
| 960 | fTokenID := tkSymbol; |
|---|
| 961 | end; |
|---|
| 962 | else |
|---|
| 963 | fTokenID := tkSymbol; |
|---|
| 964 | end; |
|---|
| 965 | end; |
|---|
| 966 | |
|---|
| 967 | procedure TSynAASyn.SemicolonProc; |
|---|
| 968 | begin |
|---|
| 969 | Inc(Run); |
|---|
| 970 | fTokenID := tkSymbol; |
|---|
| 971 | if fRange in [rsProperty, rsExports] then |
|---|
| 972 | fRange := rsUnknown; |
|---|
| 973 | end; |
|---|
| 974 | |
|---|
| 975 | procedure TSynAASyn.SlashProc; |
|---|
| 976 | begin |
|---|
| 977 | |
|---|
| 978 | |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | |
|---|
| 985 | |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | |
|---|
| 989 | |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | |
|---|
| 993 | |
|---|
| 994 | Inc(Run); |
|---|
| 995 | if fLine[Run] = '/' then |
|---|
| 996 | begin |
|---|
| 997 | fTokenID := tkComment; |
|---|
| 998 | repeat |
|---|
| 999 | Inc(Run); |
|---|
| 1000 | until fLine[Run] in [#0, #10, #13]; |
|---|
| 1001 | end |
|---|
| 1002 | else |
|---|
| 1003 | if fline[run] = '*' then |
|---|
| 1004 | begin |
|---|
| 1005 | begin |
|---|
| 1006 | Inc(Run); |
|---|
| 1007 | if fRange = rsAsm then |
|---|
| 1008 | fRange := rsAnsiAsm |
|---|
| 1009 | else |
|---|
| 1010 | fRange := rsAnsi; |
|---|
| 1011 | fTokenID := tkComment; |
|---|
| 1012 | if not (fLine[Run] in [#0, #10, #13]) then |
|---|
| 1013 | AnsiProc; |
|---|
| 1014 | end; |
|---|
| 1015 | end |
|---|
| 1016 | else fTokenID := tkSymbol; |
|---|
| 1017 | |
|---|
| 1018 | end; |
|---|
| 1019 | |
|---|
| 1020 | procedure TSynAASyn.SpaceProc; |
|---|
| 1021 | begin |
|---|
| 1022 | inc(Run); |
|---|
| 1023 | fTokenID := tkSpace; |
|---|
| 1024 | while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run); |
|---|
| 1025 | end; |
|---|
| 1026 | |
|---|
| 1027 | procedure TSynAASyn.StringProc; |
|---|
| 1028 | begin |
|---|
| 1029 | fTokenID := tkString; |
|---|
| 1030 | Inc(Run); |
|---|
| 1031 | while not (fLine[Run] in [#0, #10, #13]) do begin |
|---|
| 1032 | if fLine[Run] = #39 then begin |
|---|
| 1033 | Inc(Run); |
|---|
| 1034 | if fLine[Run] <> #39 then |
|---|
| 1035 | break; |
|---|
| 1036 | end; |
|---|
| 1037 | Inc(Run); |
|---|
| 1038 | end; |
|---|
| 1039 | end; |
|---|
| 1040 | |
|---|
| 1041 | procedure TSynAASyn.SymbolProc; |
|---|
| 1042 | begin |
|---|
| 1043 | inc(Run); |
|---|
| 1044 | fTokenID := tkSymbol; |
|---|
| 1045 | end; |
|---|
| 1046 | |
|---|
| 1047 | procedure TSynAASyn.UnknownProc; |
|---|
| 1048 | begin |
|---|
| 1049 | |
|---|
| 1050 | if FLine[Run] in LeadBytes then |
|---|
| 1051 | Inc(Run, 2) |
|---|
| 1052 | else |
|---|
| 1053 | |
|---|
| 1054 | inc(Run); |
|---|
| 1055 | fTokenID := tkUnknown; |
|---|
| 1056 | end; |
|---|
| 1057 | |
|---|
| 1058 | procedure TSynAASyn.Next; |
|---|
| 1059 | begin |
|---|
| 1060 | fAsmStart := False; |
|---|
| 1061 | fTokenPos := Run; |
|---|
| 1062 | case fRange of |
|---|
| 1063 | rsAnsi, rsAnsiAsm: |
|---|
| 1064 | AnsiProc; |
|---|
| 1065 | rsBor, rsBorAsm, rsDirective, rsDirectiveAsm: |
|---|
| 1066 | BorProc; |
|---|
| 1067 | else |
|---|
| 1068 | fProcTable[fLine[Run]]; |
|---|
| 1069 | end; |
|---|
| 1070 | end; |
|---|
| 1071 | |
|---|
| 1072 | function TSynAASyn.GetDefaultAttribute(Index: integer): |
|---|
| 1073 | TSynHighlighterAttributes; |
|---|
| 1074 | begin |
|---|
| 1075 | case Index of |
|---|
| 1076 | SYN_ATTR_COMMENT: Result := fCommentAttri; |
|---|
| 1077 | SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri; |
|---|
| 1078 | SYN_ATTR_KEYWORD: Result := fKeyAttri; |
|---|
| 1079 | SYN_ATTR_STRING: Result := fStringAttri; |
|---|
| 1080 | SYN_ATTR_WHITESPACE: Result := fSpaceAttri; |
|---|
| 1081 | SYN_ATTR_SYMBOL: Result := fSymbolAttri; |
|---|
| 1082 | else |
|---|
| 1083 | Result := nil; |
|---|
| 1084 | end; |
|---|
| 1085 | end; |
|---|
| 1086 | |
|---|
| 1087 | function TSynAASyn.GetEol: Boolean; |
|---|
| 1088 | begin |
|---|
| 1089 | Result := fTokenID = tkNull; |
|---|
| 1090 | end; |
|---|
| 1091 | |
|---|
| 1092 | function TSynAASyn.GetToken: string; |
|---|
| 1093 | var |
|---|
| 1094 | Len: LongInt; |
|---|
| 1095 | begin |
|---|
| 1096 | Len := Run - fTokenPos; |
|---|
| 1097 | SetString(Result, (FLine + fTokenPos), Len); |
|---|
| 1098 | end; |
|---|
| 1099 | |
|---|
| 1100 | function TSynAASyn.GetTokenID: TtkTokenKind; |
|---|
| 1101 | begin |
|---|
| 1102 | if not fAsmStart and (fRange = rsAsm) |
|---|
| 1103 | and not (fTokenId in [tkNull, tkComment, tkDirec, tkSpace]) |
|---|
| 1104 | then |
|---|
| 1105 | Result := tkAsm |
|---|
| 1106 | else |
|---|
| 1107 | Result := fTokenId; |
|---|
| 1108 | end; |
|---|
| 1109 | |
|---|
| 1110 | function TSynAASyn.GetTokenAttribute: TSynHighlighterAttributes; |
|---|
| 1111 | begin |
|---|
| 1112 | case GetTokenID of |
|---|
| 1113 | tkAsm: Result := fAsmAttri; |
|---|
| 1114 | tkComment: Result := fCommentAttri; |
|---|
| 1115 | tkDirec: Result := fDirecAttri; |
|---|
| 1116 | tkIdentifier: Result := fIdentifierAttri; |
|---|
| 1117 | tkKey: Result := fKeyAttri; |
|---|
| 1118 | tkRegister: Result := fRegisterAttri; |
|---|
| 1119 | tkNumber: Result := fNumberAttri; |
|---|
| 1120 | tkFloat: Result := fFloatAttri; |
|---|
| 1121 | tkHex: Result := fHexAttri; |
|---|
| 1122 | tkSpace: Result := fSpaceAttri; |
|---|
| 1123 | tkString: Result := fStringAttri; |
|---|
| 1124 | tkChar: Result := fCharAttri; |
|---|
| 1125 | tkSymbol: Result := fSymbolAttri; |
|---|
| 1126 | tkUnknown: Result := fSymbolAttri; |
|---|
| 1127 | else |
|---|
| 1128 | Result := nil; |
|---|
| 1129 | end; |
|---|
| 1130 | end; |
|---|
| 1131 | |
|---|
| 1132 | function TSynAASyn.GetTokenKind: integer; |
|---|
| 1133 | begin |
|---|
| 1134 | Result := Ord(GetTokenID); |
|---|
| 1135 | end; |
|---|
| 1136 | |
|---|
| 1137 | function TSynAASyn.GetTokenPos: Integer; |
|---|
| 1138 | begin |
|---|
| 1139 | Result := fTokenPos; |
|---|
| 1140 | end; |
|---|
| 1141 | |
|---|
| 1142 | function TSynAASyn.GetRange: Pointer; |
|---|
| 1143 | begin |
|---|
| 1144 | Result := Pointer(fRange); |
|---|
| 1145 | end; |
|---|
| 1146 | |
|---|
| 1147 | procedure TSynAASyn.SetRange(Value: Pointer); |
|---|
| 1148 | begin |
|---|
| 1149 | fRange := TRangeState(Value); |
|---|
| 1150 | end; |
|---|
| 1151 | |
|---|
| 1152 | procedure TSynAASyn.ResetRange; |
|---|
| 1153 | begin |
|---|
| 1154 | fRange:= rsUnknown; |
|---|
| 1155 | end; |
|---|
| 1156 | |
|---|
| 1157 | function TSynAASyn.GetIdentChars: TSynIdentChars; |
|---|
| 1158 | begin |
|---|
| 1159 | Result := TSynValidStringChars; |
|---|
| 1160 | end; |
|---|
| 1161 | |
|---|
| 1162 | function TSynAASyn.GetSampleSource: string; |
|---|
| 1163 | begin |
|---|
| 1164 | Result := 'NYI'#13#10; |
|---|
| 1165 | end; |
|---|
| 1166 | |
|---|
| 1167 | |
|---|
| 1168 | class function TSynAASyn.GetLanguageName: string; |
|---|
| 1169 | begin |
|---|
| 1170 | Result := SYNS_LangPascal; |
|---|
| 1171 | end; |
|---|
| 1172 | |
|---|
| 1173 | class function TSynAASyn.GetCapabilities: TSynHighlighterCapabilities; |
|---|
| 1174 | begin |
|---|
| 1175 | Result := inherited GetCapabilities + [hcUserSettings]; |
|---|
| 1176 | end; |
|---|
| 1177 | |
|---|
| 1178 | function TSynAASyn.IsFilterStored: boolean; |
|---|
| 1179 | begin |
|---|
| 1180 | Result := fDefaultFilter <> SYNS_FilterPascal; |
|---|
| 1181 | end; |
|---|
| 1182 | |
|---|
| 1183 | procedure TSynAASyn.SetAutoAssemblerVersion(const Value: TAutoAssemblerVersion); |
|---|
| 1184 | begin |
|---|
| 1185 | if fAutoAssemblerVersion <> Value then |
|---|
| 1186 | begin |
|---|
| 1187 | fAutoAssemblerVersion := Value; |
|---|
| 1188 | if (fAutoAssemblerVersion < dvAutoAssembler3) and fPackageSource then |
|---|
| 1189 | fPackageSource := False; |
|---|
| 1190 | DefHighlightChange( Self ); |
|---|
| 1191 | end; |
|---|
| 1192 | end; |
|---|
| 1193 | |
|---|
| 1194 | |
|---|
| 1195 | procedure TSynAASyn.SetPackageSource(const Value: Boolean); |
|---|
| 1196 | begin |
|---|
| 1197 | if fPackageSource <> Value then |
|---|
| 1198 | begin |
|---|
| 1199 | fPackageSource := Value; |
|---|
| 1200 | if fPackageSource and (fAutoAssemblerVersion < dvAutoAssembler3) then |
|---|
| 1201 | fAutoAssemblerVersion := dvAutoAssembler3; |
|---|
| 1202 | DefHighlightChange( Self ); |
|---|
| 1203 | end; |
|---|
| 1204 | end; |
|---|
| 1205 | |
|---|
| 1206 | |
|---|
| 1207 | initialization |
|---|
| 1208 | MakeIdentTable; |
|---|
| 1209 | |
|---|
| 1210 | RegisterPlaceableHighlighter(TSynAASyn); |
|---|
| 1211 | |
|---|
| 1212 | end. |
|---|