Line breaks in strings
Posted: Fri Apr 14, 2017 2:39 am
When I first encountered Oberon and then Component Pascal I was appalled that line breaks were not allowed in strings. Before that time I had used for 14+ years the languages SAIL and MAINSAIL in which one could include line breaks in strings. That was very nice for a whole paragraph of text could be encoded in a single string.
Recently I encountered the need to initialize a matrix given a textual representation of its data (C++ code). To do that in Component Pascal it is necessary to break the lines of the matrix into separate strings. That makes the code cumbersome and ugly.
I propose to allow line breaks in Component Pascal strings.
Doing so would be backwards compatible with all code.
Here is what the CP documentation says about strings.
-Doug
Recently I encountered the need to initialize a matrix given a textual representation of its data (C++ code). To do that in Component Pascal it is necessary to break the lines of the matrix into separate strings. That makes the code cumbersome and ugly.
I propose to allow line breaks in Component Pascal strings.
Doing so would be backwards compatible with all code.
Here is what the CP documentation says about strings.
Comments please.The following lexical rules must be observed: Blanks and line breaks must not occur within symbols (except in comments, and blanks in strings).
4. Strings are sequences of characters enclosed in single (') or double (") quote marks. The opening quote must be the same as the closing quote and must not occur within the string. The number of characters in a string is called its length. A string of length 1 can be used wherever a character constant is allowed and vice versa. Characters in string constants are allowed to be Unicode (16 bit) characters.
string = ' " ' {char} ' " ' | " ' " {char} " ' ".
Examples: "Component Pascal" "Don't worry!" "x" "αβ"
6.6 String Types
Values of a string type are sequences of characters terminated by a null character (0X). The length of a string is the number of characters it contains excluding the null character.
Strings are either constants or stored in an array of character type. There are no predeclared identifiers for string types because there is no need to use them in a declaration.
Constant strings which consist solely of characters in the range 0X..0FFX and strings stored in an array of SHORTCHAR are of type Shortstring, all others are of type String.
-Doug