| 91 | The Heredoc processor has only one task: flattening heredoc strings. By "flattening", I mean the following. This string: |
| 92 | |
| 93 | {{{ |
| 94 | $S0 = <<'EOS' |
| 95 | This is |
| 96 | a multi-line |
| 97 | heredoc |
| 98 | string |
| 99 | with |
| 100 | increasing |
| 101 | indention |
| 102 | on each line. |
| 103 | EOS |
| 104 | }}} |
| 105 | |
| 106 | is "flattened" into: |
| 107 | |
| 108 | {{{ |
| 109 | $S0 = "This is a multi-line\n heredoc\n string\n with\n increasing\n indention\n on each line." |
| 110 | }}} |
| 111 | |
| 112 | Note that "newline" characters are inserted as well, so that the string is equivalent to the original heredoc string. |
| 113 | Besides assigning heredoc strings to String registers, the PIR specification also allows you to use heredoc strings as arguments in subroutine invocations: |
| 114 | |
| 115 | {{{ |
| 116 | .sub main |
| 117 | foo(<<'A') |
| 118 | This is a heredoc |
| 119 | string argument |
| 120 | A |
| 121 | .end |
| 122 | |
| 123 | .sub foo |
| 124 | # ... |
| 125 | .end |
| 126 | }}} |
| 127 | |
| 128 | Again, the heredoc string (delimited by the string "A") will be flattened. According to the PIR specification, you can even pass multiple heredoc string arguments, like so: |
| 129 | |
| 130 | {{{ |
| 131 | .sub main |
| 132 | foo(<<'A', 42, <<'B', 3.14, <<'C') |
| 133 | I have a Parrot |
| 134 | A |
| 135 | It is not a bird |
| 136 | B |
| 137 | It is a virtual machine |
| 138 | C |
| 139 | .end |
| 140 | |
| 141 | }}} |
| 142 | |
| 143 | Note that the heredoc arguments may be mixed with other, simple arguments such as integers and numbers. In the rest of this section, the implementation will be discussed. |
| 144 | |