title: How to preserve whitespace when we use text attribute in Antlr4
body: <p>I want to keep white space when I call text attribute of token, is there any way to do it?
  Here is the situation:
  We have the following code</p>
  
  <pre><code>IF L &gt; 40 THEN;
  
  ELSE
  
    IF A = 20 THEN
        PUT "HELLO";
  </code></pre>
  
  <p>In this case, I want to transform it into:</p>
  
  <pre><code>if (!(L&gt;40){
  
        if (A=20)
            put "hello";
  }
  </code></pre>
  
  <p>The rule in Antlr is that:</p>
  
  <pre><code>stmt_if_block: IF expr
                 THEN x=stmt
                 (ELSE y=stmt)?
                 {
                   if ($x.text.equalsIgnoreCase(";"))
                   {
                     WriteLn("if(!(" + $expr.text +")){");
                     WriteLn($stmt.text);
                     Writeln("}");
                   }
                 }
  </code></pre>
  
  <p>But the result looks like:</p>
  
  <pre><code>if(!(L&gt;40))
  {
     ifA=20put"hello";
  }
  </code></pre>
  
  <p>The reason is that the white space in <code>$stmt</code> was removed. I was wondering if there is anyway to keep these white space<br>
  Thank you so much</p>
  
  <p>Update: If I add </p>
  
  <pre><code>SPACE: [ ] -&gt; channel(HIDDEN);
  </code></pre>
  
  <p>The space will be preserved, and the result would look like below, many spaces between tokens:</p>
  
  <pre><code> IF SUBSTR(WNAME3,M-1,1) = ')'             THEN                                        M = L;                                  ELSE                                        M = L - 1;
  </code></pre>