Got whitepace stripping properly working (AFAICT) for parse_define()

Made debug for viewing whitespace in AST::is_equal with String::visualize_whitespace()

Format stripping code is currently confined within parse_define()

I plan to move it to its own function soon, I just want to make sure its finalized first.

Other unvalidated content will need to have an extra check for preprocessed lines.
Example: Function bodies can have a #define <identifier> <definition>. I cannot strip the last <new line> as it will break the semantic importance to distinguish that line.
So it needs to be:
<content before> <new line>
<preprocessed line> <new line>
<content after>

In the content string that is minimally preserved
This commit is contained in:
2023-09-03 20:29:45 -04:00
parent c4c308c8ba
commit 1076818250
3 changed files with 281 additions and 79 deletions

View File

@ -101,6 +101,11 @@ struct String
bool make_space_for( char const* str, sw add_len );
bool append( char c )
{
return append( & c, 1 );
}
bool append( char const* str )
{
return append( str, str_len( str ) );
@ -264,14 +269,52 @@ struct String
return trim( " \t\r\n\v\f" );
}
// Debug function that provides a copy of the string with whitespace characters visualized.
String visualize_whitespace() const
{
Header* header = (Header*)(Data - sizeof(Header));
String result = make_reserve(header->Allocator, length() * 2); // Assume worst case for space requirements.
for ( char c : *this )
{
switch ( c )
{
case ' ':
result.append('·');
break;
case '\t':
result.append('');
break;
case '\n':
result.append('');
break;
case '\r':
result.append('');
break;
case '\v':
result.append('');
break;
case '\f':
result.append('');
break;
default:
result.append(c);
break;
}
}
return result;
}
// For-range support
char* begin()
char* begin() const
{
return Data;
}
char* end()
char* end() const
{
Header const&
header = * rcast( Header const*, Data - sizeof( Header ));