Add C23 bool, true, and false keywords (fixes #250) - #255
Open
MaxwellCalkin wants to merge 1 commit into
Open
Conversation
C23 promotes `bool`, `true`, and `false` from <stdbool.h> macros to first-class keywords. This change: - Adds `"bool"` as an alternate spelling for `TokenKind::Bool` (alongside `_Bool`), following the same pattern used for `static_assert` / `_Static_assert` - Adds new `TokenKind::True` and `TokenKind::False` variants - Maps `"true"` and `"false"` to these new token kinds in `from_keyword()` - Handles `True`/`False` tokens in the parser's `parse_primary_expr()`, emitting `IntLiteral(1)` and `IntLiteral(0)` respectively Code that includes <stdbool.h> continues to work unchanged since the preprocessor macro expansion occurs before keyword recognition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #250 — CCC fails to recognize
bool,true, andfalsein C23 mode.C23 (N3096 §6.4.1) promotes
bool,true, andfalsefrom<stdbool.h>macros to first-class keywords. This PR adds support for all three:bool: Added as an alternate spelling forTokenKind::Bool(alongside_Bool), following the same pattern already used forstatic_assert/_Static_asserttrue/false: Added as newTokenKind::TrueandTokenKind::Falsevariants, recognized byfrom_keyword()and handled inparse_primary_expr()asIntLiteral(1)andIntLiteral(0)respectivelyWhat changed
src/frontend/lexer/token.rsTrue/FalsetoTokenKindenum,Displayimpl, andfrom_keyword()match; added"bool"alternate for_Boolsrc/frontend/parser/expressions.rsTokenKind::True→Expr::IntLiteral(1)andTokenKind::False→Expr::IntLiteral(0)in primary expression parsingCompatibility
#include <stdbool.h>continues to work unchanged — preprocessor macro expansion occurs before keyword recognitionfrom_keyword()already accept the first characters (b,t,f) and lengths (4, 4, 5), so no filter updates are neededTokenKindin the parser use wildcard catch-allsTest case (from issue #250)
🤖 Generated with Claude Code
AI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).