From f9f7c13995852c4141d8057a3f089fc23d280432 Mon Sep 17 00:00:00 2001 From: leftibot Date: Tue, 14 Apr 2026 16:20:40 -0600 Subject: [PATCH] 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) --- include/chaiscript/language/chaiscript_parser.hpp | 4 ++-- unittests/enum.chai | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f110bcd5..0af66d4e 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -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); } diff --git a/unittests/enum.chai b/unittests/enum.chai index 7f85de73..1821af7a 100644 --- a/unittests/enum.chai +++ b/unittests/enum.chai @@ -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)