Generally speaking, whitespace is unimportant in PTPScript. The only place that it matters is where Operator disambiguation is required. Other than that, as much or little whitespace as is desired can be used.

For example:

{ a + b }
{ a+b }
  a + b

All of the expressions in the example above are semantically indentical. However, consider the following:

{ a and b }
{ aandb }

Obviously, in this case the logical AND operator, which uses alphabetic characters, can only be distinguished when whitespace is used to separate it from the terms on either side.

Another scenario is where multiple Operators are being used next to each other.

For example:

{ a++ + ++++b }
{ a+++++++b }

Both expressions are perfectly valid. However, the PTP engine uses the "maximum munch" method, which means that it is as greedy as possible when resolving Operators. The second expression therefore equates to (((a++)++)++) + b, which is obviously not what was intended.

Occasionally, the ambiguation can also cause errors.

For example:

{ a - -b }
{ a--b }

In this case, the second expression equates to a-- b, which is then missing an infix Operator, and will generate an error saying that b is unexpected.

Whitespace Suppression Symbols

Whitespace inside placeholders is unimportant, as shown in the section above. However, external whitespace can often be a concern. For this reason, whitespace suppression symbols exist. These symbols are ellipses (…) by default, but the backend programmer may choose to change them. The ellipsis character has an ASCII code of 133, and can generally be used by holding the "Alt" key and typing "0133" on the numeric keypad of most keyboards. This character was chosen due to its look and semantic value, plus the fact that it is a lesser-used character and unlikely to cause issues. If disliked, the PTP engine can be configured to use alternative characters.

Whitespace suppression symbols are used to suppress whitespace on one or both sides of a placeholder. The amount of whitespace suppressed depends upon the Directives in place at the time. The default Directives are LinebreakSuppression and NoWhitespaceSuppression, and examples will be written accordingly. Different behaviour can be enforced by setting different Directives, using the Use command.

For example:

{ 1 }
{ 2 }


The above example outputs the placeholder contents on different lines. This may not always be the desired result.

For example:

{ 1 }{ 2 }


Using the whitespace suppression symbols, as shown in the second example above, prevents the linebreak from being displayed. Of course, this may also not be the desired result in some situations.

Using different Directives, one or many linebreaks can be suppressed, and one or many whitespace sequences can be suppressed. The suppression functionality can also be turned off.

Whitespace suppresion symbols need to appear immediately before or after a placeholder, if they are to be used.

Whitespace suppression will continue until a non-whitespace character is found. If this character is itself a whitespace suppression symbol, it will be removed. This allows a point to be defined at which to stop removing whitespace.

ptpscript/basic_syntax/whitespace.txt · Last modified: 2007/01/24 10:15
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki