liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
 
export CurPos=0
export TOKENS=()
 
mergeInSingleLine() {
  OPENING_TOKEN="${TOKENS[$CurPos]}"
  echo -n "${OPENING_TOKEN}"
  CurPos=$[$CurPos + 1]
  if ! [[ "${OPENING_TOKEN}" =~ \< ]] && ! [[ "${OPENING_TOKEN}" =~ \( ]]
  then
    # This is not an opening token, it's an atomic component.
    return
  fi
  while true
  do
    if ! [[ "${TOKENS[$CurPos]}" =~ \> ]] && ! [[ "${TOKENS[$CurPos]}" =~ \) ]]
    then
      mergeInSingleLine
    else
      if [[ "${TOKENS[$CurPos]}" =~ \< ]] || [[ "${TOKENS[$CurPos]}" =~ \( ]]
      then
        # Both an opening and a closing token, print it and go ahead.
        echo -n "${TOKENS[$CurPos]}"
        CurPos=$[$CurPos + 1]
      else
        break
      fi
    fi
  done
  echo -n "${TOKENS[CurPos]}"
  CurPos=$[$CurPos + 1]
}
 
considerMerging() {
  OPENING_TOKEN="${TOKENS[CurPos]}"
  if ! [[ "${OPENING_TOKEN}" =~ \< ]] && ! [[ "${OPENING_TOKEN}" =~ \( ]]
  then
    # This is not an opening token, it's an atomic component.
    echo "${OPENING_TOKEN}"
    CurPos=$[$CurPos + 1]
    return;
  fi
  if [[ "${OPENING_TOKEN}" = "Type<" ]]
  then
    # Type<...> should be on a single line.
    mergeInSingleLine
    echo
    return;
  fi
  echo "${OPENING_TOKEN}"
  CurPos=$[$CurPos + 1]
  while true
  do
    if ! [[ "${TOKENS[$CurPos]}" =~ \> ]] && ! [[ "${TOKENS[$CurPos]}" =~ \) ]]
    then
      considerMerging
    else
      if [[ "${TOKENS[$CurPos]}" =~ \< ]] || [[ "${TOKENS[$CurPos]}" =~ \( ]]
      then
        # Both an opening and a closing token, print it and go ahead.
        echo "${TOKENS[$CurPos]}"
        CurPos=$[$CurPos + 1]
      else
        break
      fi
    fi
  done
  echo "${TOKENS[$CurPos]}"
  CurPos=$[$CurPos + 1]
}
 
while read line
do
  if [[ "${line}" =~ required\ from\ .*DoEval\< ]]
  then
    echo
    IFS=$'\r\n' GLOBIGNORE='*' :;
    TOKENS=($(echo "${line}" |
        sed 's| (\*)||g;
              s|.* required from .*DoEval<||;
              s|>.$||;
              s/fruit::impl::meta:://g;
              s| >|>|g;
              s|, |,|g' |
        sed 's|[>]|,>|g;
              s|[)]|,)|g' |
        sed 's|[<]|<\n|g;
              s|[(]|(\n|g;
              s|[,]|,\n|g' |
        grep -v "^,$" ))
    considerMerging |
    sed 's|,>|>|g;
         s|,)|)|g' |
    awk -F@ '/^[^()<>]*[>)][^()<>]*[(<][^()<>]*$/ {curIndent-=2; for (i=0; i<curIndent; i++) { printf(" "); } print; curIndent+=2; next;}
             /[()<>].*[()<>]/ || !/[()<>]/ {for (i=0; i<curIndent; i++) { printf(" "); } print; next;}
             /[(<]/ { for (i=0; i<curIndent; i++) { printf(" "); } print; curIndent+=2; next; }
             /[)>]/ || /^[^()<>]*>/ { curIndent-=2; for (i=0; i<curIndent; i++) { printf(" "); } print; next; }
             '
  elif [[ "${line}" =~ required\ from\ .*EvalFun\< ]]
  then
    echo
    IFS=$'\r\n' GLOBIGNORE='*' :;
    TOKENS=($(echo "${line}" |
        sed 's|,|(|' |
        sed 's| (\*)||g;
              s|.* required from .*EvalFun<||;
              s|>.$||;
              s/fruit::impl::meta:://g;
              s| >|>|g;
              s|, |,|g' |
        sed 's|[>]|,>|g;
              s|[)]|,)|g' |
        sed 's|[<]|<\n|g;
              s|[(]|(\n|g;
              s|[,]|,\n|g' |
        grep -v "^,$";
        echo ')'))
    considerMerging |
    sed 's|,>|>|g;
         s|,)|)|g' |
    awk -F@ '/^[^()<>]*[>)][^()<>]*[(<][^()<>]*$/ {curIndent-=2; for (i=0; i<curIndent; i++) { printf(" "); } print; curIndent+=2; next;}
             /[()<>].*[()<>]/ || !/[()<>]/ {for (i=0; i<curIndent; i++) { printf(" "); } print; next;}
             /[(<]/ { for (i=0; i<curIndent; i++) { printf(" "); } print; curIndent+=2; next; }
             /[)>]/ || /^[^()<>]*>/ { curIndent-=2; for (i=0; i<curIndent; i++) { printf(" "); } print; next; }
             '
  else
    echo "${line}"
  fi
done | sed 's/fruit::impl::meta:://g;s/struct //g' | grep -v "required from .EvalIf<"