indents aren't working for me when generating text

Hi,

I don't know if I'm doing something wrong, but I've tried both Textgen and gText, and neither are outputting indentations when I use the indent nodes. As gText uses Textgen to output, I'm guessing the problem lies in Textgen somewhere.

Is there a trick to this, or is it just broken?

I'm running 1.5.1. I tried to get 2.0 running, but it was throwing an exception on startup.

6 comments
Comment actions Permalink

Hi!

Here is brief description of how to use line indentations in Textgen language aspect:

you can increase indent level by wrapping some parts of Textgen definition into "with indent" block:

with indent {

  // nested elements with increased indent 

}

and you can _explicitly_ insert current indent into the buffer by using intent buffer statement:

indent buffer ;

so, following construction

with indent {

  with indent {

    indent buffer ;

    append {public};

  }

}

will produce "public" word prefixed by two indents.

0
Comment actions Permalink
Hi,

i did run into the same problem.

I'm using 2.0M5. And i have a textgen, where i use "with indention". Also tried indent buffer;

Perhaps there is some bug in it... But it is working in the java-textgen...
0
Comment actions Permalink
This is really strange - see text gen for LocalVariableDeclaration as en example:
append \n ; 
indent buffer ; 
append ${node.localVariableDeclaration} {;} ;
prettyPrint();
In addition, you can try calling
increase depth ;
  // text gen for child nodes
decrease depth ;
prettyPrint();
instructions instead of using
with indent {
  // text gen for child nodes
}
prettyPrint();
0
Comment actions Permalink
Hi Alex,

I just created a new project to test the indent stuff and it didn't work there again.

indent.png

TestProject.zip (59KB)

You can look at the generated file:
Just a textso cool!
indent this with "indent buffer"
  children:
child: firstchild

child: secondchild
prettyPrint();

"With indent" and "increase depth" don't seem to work.

The only thing working seems to be indent buffer. But I'm not sure how it is working....
0
Comment actions Permalink
indent buffer;
prettyPrint();
instruction is just a way to insert corresponding indent into the current place in a buffer, so you should put it on each line. I modified text gen of your sample project to produce correct output:
text gen component for concept JustSomeTest { 
  extension : (node)->string { 
    "txt"; 
  } 
  encoding : utf-8 
 
  (node, context, buffer)->void { 
    append {just some test } ${node.name} { {} \n ; 
       
    with indent { 
      indent buffer ; 
      append {test: } ${node.test} \n ; 
         
      append \n ; 
         
      indent buffer ; 
      append {child stuff:} \n ; 
         
      with indent { 
        append $list{node.childStuff} ; 
      } 
    } 
       
    append {}} ; 
  } 
}
prettyPrint();
text gen component for concept ChildConcept { 
  (node, context, buffer)->void { 
    indent buffer ; 
    append {child: } ${node.childtext} \n ; 
  } 
}
prettyPrint();

so it works rather well:
just some test this is cool {
  test: so cool!

  child stuff:
    child: firstchild
    child: secondchild
    child: third
}
prettyPrint();
0
Comment actions Permalink
So much indent buffer...
I though "with indent" would do the job and indent all lines that are in this block automatically...
0

Please sign in to leave a comment.