Copying source text

Top  Previous  Next

Examples > Guard > Copying source text

 

The method for copying the text which was recognized by the last token is already known.

The spaces in front of the text shall be included in this copy. I.e. the text of the end of the second to the last token is copied until the beginning of the next expected token:

 

 

{{ out << xState.copy(); }}

 

This command is an abbreviated notation for:

 

{{ out << xState.str(-1) << xState.str(); }}

 

where the ignored text is accessed by xState.str(-1) and the recognized text is accessed by xState.str() By means of a parameter certain sections of the input text, relatively to the last recognized section, can be accessed. The parameter "-1" has the special meaning, that it is related to the ignorable characters, which were skipped, when reading the input. xState.str(-1) returns the text between the end of the previous recognized token and the beginning of the last recognized token.

In the "Exchange" examples, there were no ignorable characters. There only were the sections of text recognized by the SKIP symbol and the replaced parts of text.

In the project options of the present example the line break, carriage return, white space and tab are set ignorable (this is by default).

By the call of xState.copy() after each recognized token is made sure, that the source text is copied to the output completely, the ignorable characters included.

 

An analogous method for copying the complete text which was recognized by a production is new here:

 

{{ out << xState.lp_copy(); }}

 

The "lp" of "lp_copy" is for "last production".

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German