tw23912.pp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. program crash_2_7_1;
  2. {$mode objfpc}{$H+}
  3. //uses
  4. type
  5. TSynCommentType = (sctAnsi, sctBor, sctSlash);
  6. TSynCommentIndentFlag = (
  7. // * For Matching lines (FCommentMode)
  8. // By default indent is the same as for none comment lines (none overrides sciAlignOpen)
  9. sciNone, // Does not Indent comment lines (Prefix may contain a fixed indent)
  10. sciAlignOpen, // Indent to real opening pos on first line, if comment does not start at BOL "Foo(); (*"
  11. sciAddTokenLen, // add 1 or 2 spaces to indent (for the length of the token)
  12. sciAddPastTokenIndent, // Adds any indent found past the opening token "(*", "{" or "//".
  13. sciMatchOnlyTokenLen, // Apply the Above only if first line matches. (Only if sciAddTokenLen is specified)
  14. sciMatchOnlyPastTokenIndent,
  15. sciAlignOnlyTokenLen, // Apply the Above only if sciAlignOpen was used (include via max)
  16. sciAlignOnlyPastTokenIndent,
  17. sciApplyIndentForNoMatch // Apply above rules For NONE Matching lines (FCommentMode),
  18. // includes FIndentFirstLineExtra
  19. );
  20. TSynCommentIndentFlags = set of TSynCommentIndentFlag;
  21. TSynCommentContineMode = (
  22. sccNoPrefix, // May still do indent, if matched
  23. sccPrefixAlways, // If the pattern did not match all will be done, except the indent AFTER the prefix (can not be detected)
  24. sccPrefixMatch
  25. );
  26. TSynCommentMatchMode = (
  27. scmMatchAfterOpening, // will not include (*,{,//. The ^ will match the first char after
  28. scmMatchOpening, // will include (*,{,//. The ^ will match the ({/
  29. scmMatchWholeLine, // Match the entire line
  30. scmMatchAtAsterisk // AnsiComment only, will match the * of (*, but not the (
  31. );
  32. TSynCommentMatchLine = (
  33. sclMatchFirst, // Match the first line of the comment to get substitutes for Prefix ($1)
  34. sclMatchPrev // Match the previous line of the comment to get substitutes for Prefix ($1)
  35. );
  36. TSynBeautifierIndentType = (sbitSpace, sbitCopySpaceTab, sbitPositionCaret);
  37. TSynCommentExtendMode = (
  38. sceNever, // Never Extend
  39. sceAlways, // Always
  40. sceSplitLine, // If the line was split (caret was not at EOL, when enter was pressed
  41. sceMatching, // If the line matched (even if sccPrefixAlways or sccNoPrefix
  42. sceMatchingSplitLine
  43. );
  44. function dbgs(AIndentFlag: TSynCommentIndentFlag): String;
  45. begin
  46. Result := ''; WriteStr(Result, AIndentFlag);
  47. end;
  48. function dbgs(AIndentFlags: TSynCommentIndentFlags): String;
  49. var
  50. i: TSynCommentIndentFlag;
  51. begin
  52. Result := '';
  53. for i := low(TSynCommentIndentFlag) to high(TSynCommentIndentFlag) do
  54. if i in AIndentFlags then
  55. if Result = ''
  56. then Result := dbgs(i)
  57. else Result := Result + ',' + dbgs(i);
  58. if Result <> '' then
  59. Result := '[' + Result + ']';
  60. end;
  61. procedure Foo(Atype: TSynCommentType;
  62. AIndentMode: TSynCommentIndentFlags;
  63. AIndentFirstLineMax: Integer; AIndentFirstLineExtra: String;
  64. ACommentMode: TSynCommentContineMode; AMatchMode: TSynCommentMatchMode;
  65. AMatchLine: TSynCommentMatchLine; ACommentIndent: TSynBeautifierIndentType;
  66. AMatch: String; APrefix: String;
  67. AExtenbSlash: TSynCommentExtendMode = sceNever);
  68. var
  69. s: String;
  70. begin
  71. writestr(s, AType,':',
  72. ' IMode=', dbgs(AIndentMode), ' IMax=', AIndentFirstLineMax, ' IExtra=', AIndentFirstLineExtra,
  73. ' CMode=', ACommentMode, ' CMatch=', AMatchMode, ' CLine=', AMatchLine,
  74. ' M=''', AMatch, ''' R=''', APrefix, ''' CIndent=', ACommentIndent
  75. );
  76. if s<>'sctAnsi: IMode=[sciAddTokenLen] IMax=5 IExtra= CMode=sccPrefixMatch CMatch=scmMatchOpening CLine=sclMatchPrev M=''.'' R=''+'' CIndent=sbitCopySpaceTab' then
  77. halt(1);
  78. end;
  79. begin
  80. Foo(sctAnsi, [sciAddTokenLen], 5, ' ', sccPrefixMatch, scmMatchOpening,
  81. sclMatchPrev, sbitCopySpaceTab, '.', '+');
  82. end.