From a91bd145008432fb8c5d91d94ab6f50473a277f5 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 27 Oct 2026 13:55:36 +0000 Subject: feat(preprocessor): add file-local conditional switches Co-Authored-By: Claude Opus 5.5 --- tests/i/preprocessor/case.json | 6 ++++ tests/i/preprocessor/expected.txt | 8 +++++ tests/i/preprocessor/notes.md | 5 +++ tests/i/preprocessor/peer.cps | 9 ++++++ tests/i/preprocessor/program.cps | 44 +++++++++++++++++++++++++++ tests/iii/preprocessor-directives/case.json | 28 +++++++++++++++++ tests/iii/preprocessor-directives/program.cps | 6 ++++ tests/iii/preprocessor-lines/case.json | 8 +++++ tests/iii/preprocessor-lines/program.cps | 7 +++++ tests/iii/preprocessor-reserved/case.json | 8 +++++ tests/iii/preprocessor-reserved/program.cps | 1 + 11 files changed, 130 insertions(+) create mode 100644 tests/i/preprocessor/case.json create mode 100644 tests/i/preprocessor/expected.txt create mode 100644 tests/i/preprocessor/notes.md create mode 100644 tests/i/preprocessor/peer.cps create mode 100644 tests/i/preprocessor/program.cps create mode 100644 tests/iii/preprocessor-directives/case.json create mode 100644 tests/iii/preprocessor-directives/program.cps create mode 100644 tests/iii/preprocessor-lines/case.json create mode 100644 tests/iii/preprocessor-lines/program.cps create mode 100644 tests/iii/preprocessor-reserved/case.json create mode 100644 tests/iii/preprocessor-reserved/program.cps (limited to 'tests') diff --git a/tests/i/preprocessor/case.json b/tests/i/preprocessor/case.json new file mode 100644 index 0000000..c66d109 --- /dev/null +++ b/tests/i/preprocessor/case.json @@ -0,0 +1,6 @@ +{ + "sources": [ + "program.cps", + "peer.cps" + ] +} diff --git a/tests/i/preprocessor/expected.txt b/tests/i/preprocessor/expected.txt new file mode 100644 index 0000000..d537856 --- /dev/null +++ b/tests/i/preprocessor/expected.txt @@ -0,0 +1,8 @@ +1 +2 +3 +4 +5 +6 +7 +PP_DEFINE Quoted diff --git a/tests/i/preprocessor/notes.md b/tests/i/preprocessor/notes.md new file mode 100644 index 0000000..2afe007 --- /dev/null +++ b/tests/i/preprocessor/notes.md @@ -0,0 +1,5 @@ +# Trace notes + +Review status: pending human review. + +The main file enables MainFlag, independently checks lowercase mainflag, and skips a disabled nested region containing invalid source and switch changes. Hidden remains undefined and MainFlag remains defined until explicitly removed. A switch named Flag does not replace the ordinary variable. Neither input sees the other's switches. Enabled branches print 1 through 7, followed by a literal containing a directive name. These are compiler extensions. diff --git a/tests/i/preprocessor/peer.cps b/tests/i/preprocessor/peer.cps new file mode 100644 index 0000000..bb745c3 --- /dev/null +++ b/tests/i/preprocessor/peer.cps @@ -0,0 +1,9 @@ +PP_DEFINE PeerFlag +PROCEDURE Peer() +PP_IFDEF MainFlag +OUTPUT MissingMainFlag +PP_ENDIF +PP_IFDEF PeerFlag +OUTPUT 7 +PP_ENDIF +ENDPROCEDURE diff --git a/tests/i/preprocessor/program.cps b/tests/i/preprocessor/program.cps new file mode 100644 index 0000000..fe0b9ce --- /dev/null +++ b/tests/i/preprocessor/program.cps @@ -0,0 +1,44 @@ +PP_DEFINE MainFlag // File-local and case-sensitive. +PP_DEFINE MainFlag +INCLUDE "peer.cps" +PP_IFDEF MainFlag +OUTPUT 1 +PP_ENDIF +PP_IFNDEF mainflag +OUTPUT 2 +PP_ENDIF +PP_IFDEF PeerFlag +OUTPUT MissingPeerFlag +PP_ENDIF +PP_IFDEF Absent +"unterminated literal +PP_DEFINE Hidden +PP_UNDEF MainFlag +PP_IFNDEF Other +#INVALID +PP_DEFINE +PP_ENDIF +PP_ENDIF +PP_IFNDEF Hidden +OUTPUT 3 +PP_ENDIF +PP_IFDEF MainFlag +OUTPUT 4 +PP_ENDIF +PP_UNDEF MainFlag +PP_UNDEF MainFlag +PP_IFDEF MainFlag +OUTPUT MissingMainFlag +PP_ENDIF +PP_IFNDEF MainFlag + PP_IFNDEF Hidden // Nested enabled conditions. +OUTPUT 5 + PP_ENDIF +PP_ENDIF +DECLARE Flag : INTEGER +PP_DEFINE Flag +Flag <- 6 +OUTPUT Flag +CALL Peer() +// PP_IFDEF CommentedOut +OUTPUT "PP_DEFINE Quoted" diff --git a/tests/iii/preprocessor-directives/case.json b/tests/iii/preprocessor-directives/case.json new file mode 100644 index 0000000..cc0301b --- /dev/null +++ b/tests/iii/preprocessor-directives/case.json @@ -0,0 +1,28 @@ +{ + "errors": [ + { + "reason": "PP_ENDIF without matching", + "line": 1 + }, + { + "reason": "PP_DEFINE requires exactly one switch name", + "line": 2 + }, + { + "reason": "PP_UNDEF requires exactly one switch name", + "line": 3 + }, + { + "reason": "PP_IFDEF requires exactly one switch name", + "line": 4 + }, + { + "reason": "PP_ENDIF does not take arguments", + "line": 5 + }, + { + "reason": "Unterminated preprocessor conditional.*PP_ENDIF", + "line": 6 + } + ] +} diff --git a/tests/iii/preprocessor-directives/program.cps b/tests/iii/preprocessor-directives/program.cps new file mode 100644 index 0000000..8b9bee6 --- /dev/null +++ b/tests/iii/preprocessor-directives/program.cps @@ -0,0 +1,6 @@ +PP_ENDIF +PP_DEFINE +PP_UNDEF Flag extra +PP_IFDEF 123 +PP_ENDIF extra +PP_IFNDEF Open diff --git a/tests/iii/preprocessor-lines/case.json b/tests/iii/preprocessor-lines/case.json new file mode 100644 index 0000000..c84bc94 --- /dev/null +++ b/tests/iii/preprocessor-lines/case.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "reason": "Unknown variable name Unknown", + "line": 7 + } + ] +} diff --git a/tests/iii/preprocessor-lines/program.cps b/tests/iii/preprocessor-lines/program.cps new file mode 100644 index 0000000..5b21eaf --- /dev/null +++ b/tests/iii/preprocessor-lines/program.cps @@ -0,0 +1,7 @@ +PP_IFDEF Missing +"invalid skipped literal +PP_IFNDEF Nested +OUTPUT Unknown +PP_ENDIF +PP_ENDIF +OUTPUT Unknown diff --git a/tests/iii/preprocessor-reserved/case.json b/tests/iii/preprocessor-reserved/case.json new file mode 100644 index 0000000..e4d76fa --- /dev/null +++ b/tests/iii/preprocessor-reserved/case.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "reason": "Expected identifier after DECLARE", + "line": 1 + } + ] +} diff --git a/tests/iii/preprocessor-reserved/program.cps b/tests/iii/preprocessor-reserved/program.cps new file mode 100644 index 0000000..be20fb2 --- /dev/null +++ b/tests/iii/preprocessor-reserved/program.cps @@ -0,0 +1 @@ +DECLARE PP_DEFINE : INTEGER -- cgit v1.3.1-4-g156e