prettier.pas

来自「一个Pascal语言分析器」· PAS 代码 · 共 69 行

PAS
69
字号
UNIT Prettier;
(* Pretty printing auxiliary functions for use with TASTE pretty printing
   program generated by COCO from an attributed grammar
   P.D. Terry, Rhodes University, 1995 *)

INTERFACE

  VAR
    results : TEXT;

  PROCEDURE Append (Str : STRING);
  (* Append Str to results file *)

  PROCEDURE IndentNextLine;
  (* Write line mark to results file and prepare to indent further lines
     by two spaces more than before *)

  PROCEDURE ExdentNextLine;
  (* Write line mark to results file and prepare to indent further lines
     by two spaces less *)

  PROCEDURE NewLine;
  (* Write line mark to results file but leave indentation as before *)

  PROCEDURE Indent;
  PROCEDURE Exdent;

IMPLEMENTATION

  VAR
    Indentation : INTEGER;

  PROCEDURE Append (Str : STRING);
    BEGIN
      Write(results, Str);
    END;

  PROCEDURE NewLine;
    VAR
      I : INTEGER;
    BEGIN
      WriteLn(results);
      FOR I := 1 TO Indentation DO Write(results, ' ');
    END;

  PROCEDURE IndentNextLine;
    BEGIN
      INC(Indentation, 2); NewLine
    END;

  PROCEDURE ExdentNextLine;
    BEGIN
      DEC(Indentation, 2); NewLine
    END;

  PROCEDURE Indent;
    BEGIN
      INC(Indentation, 2)
    END;

  PROCEDURE Exdent;
    BEGIN
      DEC(Indentation, 2)
    END;

  BEGIN
    Indentation := 0
  END.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?