Skip to content

Commit

Permalink
Update remove_phase_2.md
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Jun 6, 2024
1 parent e317d99 commit db4f66c
Showing 1 changed file with 30 additions and 41 deletions.
71 changes: 30 additions & 41 deletions docs/remove_phase_2.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
## Removing Phase 2

## Removal of Phase 2

### Motivation

Phase 2, works as being a preprocessor of the preprocessor, it does not make any distinction or judgment
about where the backslash character `\` followed by a newline can be used. This allows it to be used in
nonsensical places like in the middle of identifiers, punctuations and `//single-line comment`.
I propose we remove Phase 2 and handle the backslash character `\` followed by a newline in Phase 3.
Phase 2 works as a preprocessor of the preprocessor, without making any distinction or judgment about where the backslash character `\` followed by a newline can be used. This allows it to appear in nonsensical places such as in the middle of keywords, identifiers, constants, punctuation, and at the end of single-line comments.

## Current Text of Phase 2
This complexity makes the language and tools more cumbersome and can create errors due to the misuse of whitespace.

I propose we remove Phase 2 and handle the backslash character `\` as part of lexical elements.

2. Each instance of a backslash character (\) immediately followed by a new-line character is
deleted, splicing physical source lines to form logical source lines. Only the last backslash on
any physical source line shall be eligible for being part of such a splice. A source file that is
not empty shall end in a new-line character, which shall not be immediately preceded by a
backslash character before any such splicing takes place.
## Current Text of Phase 2

## New text for phase 2
2. Each instance of a backslash character (\) immediately followed by a newline character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a newline character, which shall not be immediately preceded by a backslash character before any such splicing takes place.

2. Phase 2, responsable for line splicing has been removed in C2Y.
The backslash character (\) followed by new line are now handled at phase 3.
## New Text for Phase 2

## 6.4 Lexical elements
2. Phase 2, responsible for line splicing, has been removed in C2Y. Phase 2 is empty in C2Y.

I propouse the backslash character (\) followed by spaces and new line to be handled inside
string-literal, single line comment, comment and white spaces as follow.
## 6.4 Lexical Elements

I propose that the backslash character `\` followed optionally by spaces and a newline be handled within string literals, single-line comments, multi-line comments, and whitespace as follows:

Backslash character (\) followed optionally by spaces and new line are part of comment and single-line comments.
They will be part of comments

Sample:

Expand All @@ -35,7 +30,7 @@ int main() {
int i = 0;
// See this path: c:\path\
i = 2;
return i; //always returns 2
return i; // always returns 2
}
```

Expand All @@ -45,36 +40,35 @@ int main() {
\*********/
```

Backslash character (\) followed optionally by spaces and new line are ignored inside literal strings
Note: I will use · to represent the space character.
They are parsed and ignored inside string literals

```c
const·char·s =
const·char·s·=·
"·
b";
```
Same as
is the same as

```c
const·char·s·=·
"a·b";
```

Backslash character (\) followed optionally by spaces and new line are ignored inside whitespaces
They are parsed and ignored inside white spaces

```c
const char s = 1·+·\···
····2;
```
Same as
is the same as
```c
const char s = 1·+·····2;
```

## Breaking changes
For all other tokens like idenfifiers, keywords, punctuators, constant the backslash character (\) is not accepct.
## Breaking Changes
For all other tokens like identifiers, keywords, and punctuators, the backslash character (`\`) is not accepted.

Currently we have
Currently, we have

```c
#define A\
Expand All @@ -85,12 +79,12 @@ This is the same as
```c
#define ABC
```
But if we had one space before B. This would be the same as
But if we had one space before B, this would be the same as

```c
#define A BC
```
With this proposal we have a error while parcing identifer A.
This will promove clarification because the code will have to be write as
With this proposal, we will have an error while parsing the identifier A. This will promote clarification because the code will have to be written as
```c
#define AB \
C
Expand All @@ -100,23 +94,18 @@ or
#define A B \
C
```
Slicing punctuators and other tokens will be an error.
Slicing punctuators and other tokens will result in an error.
```c
int i;
i+\
int i;
i+\
+;
```


## References

Trimming whitespaces before line splicing
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf




Trimming whitespace before line splicing:
[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf)



Expand Down

0 comments on commit db4f66c

Please sign in to comment.