aboutsummaryrefslogtreecommitdiff
path: root/challenge-332/deadmarshal/modula-3/Ch1/src/Ch1.m3
blob: d96944a1f2caf8e7a177e31744785af170f82ae9 (plain)
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
MODULE Ch1 EXPORTS Main;

IMPORT SIO,Text,TextConv,Fmt,Scan,Lex,FloatMode;
FROM StableError IMPORT Halt;

PROCEDURE BinaryDate(READONLY S:TEXT):TEXT
  RAISES{Lex.Error,FloatMode.Trap} =
  VAR A := ARRAY[0..2] OF TEXT{"",..};
  BEGIN
    A[0] := Text.Sub(S,0,4);
    A[1] := Text.Sub(S,5,2);
    A[2] := Text.Sub(S,8,2);
    FOR I := FIRST(A) TO LAST(A) DO
      A[I] := Fmt.Int(Scan.Int(A[I]),2)
    END;
    RETURN TextConv.Implode(A,'-')
  END BinaryDate;

BEGIN
  TRY
    SIO.PutText(BinaryDate("2025-07-26")); SIO.Nl();
    SIO.PutText(BinaryDate("2000-02-02")); SIO.Nl();
    SIO.PutText(BinaryDate("2024-12-31")); SIO.Nl()
  EXCEPT
    Lex.Error => Halt("Lex.Error")
  | FloatMode.Trap => Halt("FloatMode.Trap")
  ELSE
    Halt("Some other exception!")
  END;
END Ch1.