mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Cleanup and better contract error messages.
This commit is contained in:
@@ -1240,8 +1240,8 @@ typedef enum
|
||||
TOKEN_CT_VAEXPR, // $vaexpr,
|
||||
TOKEN_CT_VASPLAT, // $vasplat,
|
||||
TOKEN_LAST_KEYWORD = TOKEN_CT_VASPLAT,
|
||||
TOKEN_DOCS_START, // /**
|
||||
TOKEN_DOCS_END, // */ (may start with an arbitrary number of `*`
|
||||
TOKEN_DOCS_START, // <*
|
||||
TOKEN_DOCS_END, // *>
|
||||
TOKEN_DOCS_EOL,
|
||||
|
||||
TOKEN_EOF, // \n - SHOULD ALWAYS BE THE LAST TOKEN.
|
||||
|
||||
@@ -1159,21 +1159,6 @@ static inline bool scan_base64(Lexer *lexer)
|
||||
|
||||
// --- Lexer doc lexing
|
||||
|
||||
|
||||
INLINE void skip_to_doc_line_end(Lexer *lexer)
|
||||
{
|
||||
// Let's skip to either EOF, EOL or */
|
||||
char c = peek(lexer);
|
||||
while (1)
|
||||
{
|
||||
if (reached_end(lexer)) return;
|
||||
if (c == '\n') return;
|
||||
if (c == '*' && peek_next(lexer) == '/') return;
|
||||
c = next(lexer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the <* *> directives comments
|
||||
**/
|
||||
|
||||
@@ -2526,7 +2526,7 @@ static inline bool parse_doc_contract(ParseContext *c, AstId *docs, AstId **docs
|
||||
scratch_buffer_append("@require \"");
|
||||
break;
|
||||
}
|
||||
scratch_buffer_append_len(start, end - start);
|
||||
scratch_buffer_append_remove_space(start, end - start);
|
||||
scratch_buffer_append("\" violated");
|
||||
if (try_consume(c, TOKEN_COLON))
|
||||
{
|
||||
|
||||
@@ -161,6 +161,7 @@ void scratch_buffer_append_len(const char *string, size_t len);
|
||||
void scratch_buffer_append_char(char c);
|
||||
void scratch_buffer_append_in_quote(const char *string);
|
||||
void scratch_buffer_append_char_repeat(char c, size_t count);
|
||||
void scratch_buffer_append_remove_space(const char *start, int len);
|
||||
void scratch_buffer_append_signed_int(int64_t i);
|
||||
void scratch_buffer_append_double(double d);
|
||||
void scratch_buffer_append_shell_escaped(const char *string);
|
||||
|
||||
@@ -479,6 +479,22 @@ void scratch_buffer_append_in_quote(const char *string)
|
||||
}
|
||||
}
|
||||
|
||||
void scratch_buffer_append_remove_space(const char *start, int len)
|
||||
{
|
||||
char clast = ' ';
|
||||
int printed = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
char ch = start[i];
|
||||
if (ch == '\n' || ch == '\t') ch = ' ';
|
||||
if (ch == ' ' && clast == ch) continue;
|
||||
scratch_buffer_append_char(ch);
|
||||
clast = ch;
|
||||
printed++;
|
||||
}
|
||||
if (clast == ' ' && printed > 0) scratch_buffer.len--;
|
||||
}
|
||||
|
||||
void scratch_buffer_append_char(char c)
|
||||
{
|
||||
if (scratch_buffer.len + 1 > MAX_STRING_BUFFER - 1)
|
||||
|
||||
Reference in New Issue
Block a user