From b25d64e5e7eb014dbeea14a979d18d1830eabe86 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 14 Feb 2021 10:33:08 +0100 Subject: [PATCH] Fix define directive not accepting define names with digits in them --- .../Impl/AbstractDirectiveStreamProxy.cpp | 2 +- .../Parsing/Impl/DefinesStreamProxyTests.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ZoneCodeGeneratorLib/Parsing/Impl/AbstractDirectiveStreamProxy.cpp b/src/ZoneCodeGeneratorLib/Parsing/Impl/AbstractDirectiveStreamProxy.cpp index 7036a803..28fb79a5 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Impl/AbstractDirectiveStreamProxy.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Impl/AbstractDirectiveStreamProxy.cpp @@ -51,7 +51,7 @@ bool AbstractDirectiveStreamProxy::ExtractIdentifier(const ParserLine& line, uns const auto c = line.m_line[position]; if (isalpha(c) || c == '_' - || firstChar && isdigit(c)) + || !firstChar && isdigit(c)) { position++; } diff --git a/test/ZoneCodeGeneratorLibTests/Parsing/Impl/DefinesStreamProxyTests.cpp b/test/ZoneCodeGeneratorLibTests/Parsing/Impl/DefinesStreamProxyTests.cpp index 9cc8afd1..b722aad9 100644 --- a/test/ZoneCodeGeneratorLibTests/Parsing/Impl/DefinesStreamProxyTests.cpp +++ b/test/ZoneCodeGeneratorLibTests/Parsing/Impl/DefinesStreamProxyTests.cpp @@ -338,4 +338,21 @@ namespace test::parsing::impl::defines_stream_proxy REQUIRE(proxy.Eof()); } + + TEST_CASE("DefinesStreamProxy: Ensure can define name with underscores and digits", "[parsing][parsingstream]") + { + const std::vector lines + { + "#define __int16 short", + "unsigned __int16 value;" + }; + + MockParserLineStream mockStream(lines); + DefinesStreamProxy proxy(&mockStream); + + ExpectLine(&proxy, 1, ""); + ExpectLine(&proxy, 2, "unsigned short value;"); + + REQUIRE(proxy.Eof()); + } }