From dd5bbae055fd34ce2e12ef63f8a261c6b15dc83e Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 05:43:35 +0000 Subject: feat(parser): parse TEMPLATE declarations, template ids and parameter packs Co-Authored-By: Claude Opus 5.5 --- tests/iii/template-header-errors/case.json | 36 +++++++++++++++++++++++++ tests/iii/template-header-errors/program.cps | 39 ++++++++++++++++++++++++++++ tests/iii/template-pack-errors/case.json | 32 +++++++++++++++++++++++ tests/iii/template-pack-errors/program.cps | 32 +++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 tests/iii/template-header-errors/case.json create mode 100644 tests/iii/template-header-errors/program.cps create mode 100644 tests/iii/template-pack-errors/case.json create mode 100644 tests/iii/template-pack-errors/program.cps (limited to 'tests/iii') diff --git a/tests/iii/template-header-errors/case.json b/tests/iii/template-header-errors/case.json new file mode 100644 index 0000000..f74cc0d --- /dev/null +++ b/tests/iii/template-header-errors/case.json @@ -0,0 +1,36 @@ +{ + "errors": [ + { + "reason": "Duplicate template parameter", + "line": 1 + }, + { + "reason": "template parameter pack must be last", + "line": 6 + }, + { + "reason": "only one parameter pack", + "line": 10 + }, + { + "reason": "TEMPLATE cannot prefix TYPE", + "line": 14 + }, + { + "reason": "Operator templates are not supported", + "line": 17 + }, + { + "reason": "TEMPLATE declarations are only allowed at top level", + "line": 23 + }, + { + "reason": "TEMPLATE declarations are only allowed at top level", + "line": 30 + }, + { + "reason": "Expected '<' after TEMPLATE", + "line": 35 + } + ] +} diff --git a/tests/iii/template-header-errors/program.cps b/tests/iii/template-header-errors/program.cps new file mode 100644 index 0000000..73c34a2 --- /dev/null +++ b/tests/iii/template-header-errors/program.cps @@ -0,0 +1,39 @@ +TEMPLATE +FUNCTION Duplicate(Value : T) RETURNS T + RETURN Value +ENDFUNCTION + +TEMPLATE +PROCEDURE NotLast() +ENDPROCEDURE + +TEMPLATE +PROCEDURE TwoPacks() +ENDPROCEDURE + +TEMPLATE +TYPE Alias = ^T + +TEMPLATE +OVERLOAD FUNCTION OPERATOR+(Value : T) RETURNS T + RETURN Value +ENDFUNCTION + +IF TRUE THEN + TEMPLATE + PROCEDURE Nested(Value : T) + OUTPUT 99 + ENDPROCEDURE +ENDIF + +CLASS Outer + TEMPLATE + PROCEDURE Member(Value : T) + ENDPROCEDURE +ENDCLASS + +TEMPLATE <> +PROCEDURE Empty() +ENDPROCEDURE + +OUTPUT 0 diff --git a/tests/iii/template-pack-errors/case.json b/tests/iii/template-pack-errors/case.json new file mode 100644 index 0000000..53b5a23 --- /dev/null +++ b/tests/iii/template-pack-errors/case.json @@ -0,0 +1,32 @@ +{ + "errors": [ + { + "reason": "A pack parameter must be last", + "line": 2 + }, + { + "reason": "pack parameter must use the current template pack and cannot be ARRAY", + "line": 6 + }, + { + "reason": "pack parameter must use the current template pack and cannot be ARRAY", + "line": 10 + }, + { + "reason": "parameter pack must be expanded", + "line": 15 + }, + { + "reason": "Only a parameter pack may be expanded", + "line": 20 + }, + { + "reason": "Only the current template parameter pack may use", + "line": 25 + }, + { + "reason": "template parameter pack requires", + "line": 29 + } + ] +} diff --git a/tests/iii/template-pack-errors/program.cps b/tests/iii/template-pack-errors/program.cps new file mode 100644 index 0000000..51ffa46 --- /dev/null +++ b/tests/iii/template-pack-errors/program.cps @@ -0,0 +1,32 @@ +TEMPLATE +PROCEDURE NotLast(Values : Rest..., Extra : INTEGER) +ENDPROCEDURE + +TEMPLATE +PROCEDURE ArrayPack(Values : ARRAY OF Rest...) +ENDPROCEDURE + +TEMPLATE +PROCEDURE WrongPack(Values : T...) +ENDPROCEDURE + +TEMPLATE +PROCEDURE BarePack(Values : Rest...) + OUTPUT Values +ENDPROCEDURE + +TEMPLATE +PROCEDURE ScalarExpansion(Value : T) + CALL Missing(Value...) +ENDPROCEDURE + +TEMPLATE +PROCEDURE WrongTypeExpansion(Value : T) + CALL Missing(Value) +ENDPROCEDURE + +TEMPLATE +PROCEDURE MissingDots(Values : Rest) +ENDPROCEDURE + +OUTPUT 0 -- cgit v1.3.1-4-g156e