Address review: support enum struct syntax alongside enum class

Requested by @lefticus in PR #679 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
leftibot 2026-04-14 16:20:40 -06:00
parent c08447d9c7
commit f9f7c13995
2 changed files with 8 additions and 2 deletions

View File

@ -2076,8 +2076,8 @@ namespace chaiscript {
const auto prev_stack_top = m_match_stack.size();
if (Keyword("enum")) {
if (!Keyword("class")) {
throw exception::eval_error("Expected 'class' after 'enum' (only 'enum class' is supported)",
if (!Keyword("class") && !Keyword("struct")) {
throw exception::eval_error("Expected 'class' or 'struct' after 'enum' (only 'enum class'/'enum struct' is supported)",
File_Position(m_position.line, m_position.col),
*m_filename);
}

View File

@ -102,3 +102,9 @@ assert_equal(4, Flags::Execute.to_underlying())
auto f = Flags::Flags(2)
assert_true(f == Flags::Write)
// enum struct syntax (equivalent to enum class, like C++)
enum struct Direction { North, East, South, West }
assert_equal(0, Direction::North.to_underlying())
assert_equal(3, Direction::West.to_underlying())
assert_true(Direction::East != Direction::South)