From 5206c838f3c53c881cb0becab6a600206bd23eab Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 19 Aug 2005 20:29:35 +0000 Subject: "surface" portion of the move to METAL 1.1: macro extension requires the extend-macro attribute instead of use-macro, and cannot be combined with use-macro --- taldefs.py | 1 + talgenerator.py | 18 ++++++++++++++++-- tests/input/acme_template.pt | 2 +- tests/input/test_metal9.html | 2 +- tests/test_htmltalparser.py | 12 ++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/taldefs.py b/taldefs.py index 9668ab1..591a8c8 100644 --- a/taldefs.py +++ b/taldefs.py @@ -36,6 +36,7 @@ NAME_RE = "[a-zA-Z_][-a-zA-Z0-9_]*" # TODO: In Python 2.4 we can use frozenset() instead of dict.fromkeys() KNOWN_METAL_ATTRIBUTES = dict.fromkeys([ "define-macro", + "extend-macro", "use-macro", "define-slot", "fill-slot", diff --git a/talgenerator.py b/talgenerator.py index 203c68d..03819bc 100644 --- a/talgenerator.py +++ b/talgenerator.py @@ -508,6 +508,7 @@ class TALGenerator(object): todo = {} defineMacro = metaldict.get("define-macro") + extendMacro = metaldict.get("extend-macro") useMacro = metaldict.get("use-macro") defineSlot = metaldict.get("define-slot") fillSlot = metaldict.get("fill-slot") @@ -537,11 +538,24 @@ class TALGenerator(object): raise I18NError("i18n:data must be accompanied by i18n:translate", position) - if defineMacro or useMacro: + if extendMacro: + if useMacro: + raise METALError( + "extend-macro cannot be used with use-macro", position) + if not defineMacro: + raise METALError( + "extend-macro must be used with define-macro", position) + + if defineMacro or extendMacro or useMacro: if fillSlot or defineSlot: raise METALError( "define-slot and fill-slot cannot be used with " - "define-macro or use-macro", position) + "define-macro, extend-macro, or use-macro", position) + if defineMacro and useMacro: + raise METALError( + "define-macro may not be used with use-macro", position) + + useMacro = useMacro or extendMacro if content and msgid: raise I18NError( diff --git a/tests/input/acme_template.pt b/tests/input/acme_template.pt index 35d88e3..0af01ba 100644 --- a/tests/input/acme_template.pt +++ b/tests/input/acme_template.pt @@ -1,6 +1,6 @@ - + ACME Look and Feel diff --git a/tests/input/test_metal9.html b/tests/input/test_metal9.html index f8ac37e..46b1b45 100644 --- a/tests/input/test_metal9.html +++ b/tests/input/test_metal9.html @@ -4,7 +4,7 @@ Default for macro1 -
+
Macro 2's slot 1 decoration diff --git a/tests/test_htmltalparser.py b/tests/test_htmltalparser.py index 40cea3a..eb53f51 100644 --- a/tests/test_htmltalparser.py +++ b/tests/test_htmltalparser.py @@ -557,6 +557,18 @@ class TALGeneratorTestCases(TestCaseBase): self._should_error("

", exc) self._should_error("

", exc) + def test_extend_macro_errors(self): + exc = taldefs.METALError + # extend-macro requires define-macro: + self._should_error("

xxx

", exc) + # extend-macro prevents use-macro: + self._should_error("

xxx

", exc) + # use-macro doesn't co-exist with define-macro: + self._should_error("

xxx

", exc) + # # I18N test cases # -- cgit v1.2.1