From 67045cf5c5329e45f53a8c0d346f3fe681566576 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sat, 4 Aug 2012 08:47:28 +0200 Subject: [PATCH] Bug 774032 part 2 - Allow to disable markers in Preprocessor.py. r=ted --- config/Preprocessor.py | 11 +++++++++-- config/tests/unit-Preprocessor.py | 10 ++++++++++ js/src/config/Preprocessor.py | 11 +++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/config/Preprocessor.py b/config/Preprocessor.py index 3ebfbbc0dea..c9192a83e3a 100644 --- a/config/Preprocessor.py +++ b/config/Preprocessor.py @@ -92,10 +92,17 @@ class Preprocessor: """ Set the marker to be used for processing directives. Used for handling CSS files, with pp.setMarker('%'), for example. + The given marker may be None, in which case no markers are processed. """ self.marker = aMarker - self.instruction = re.compile('%s(?P[a-z]+)(?:\s(?P.*))?$'%aMarker, re.U) - self.comment = re.compile(aMarker, re.U) + if aMarker: + self.instruction = re.compile('%s(?P[a-z]+)(?:\s(?P.*))?$'%aMarker, re.U) + self.comment = re.compile(aMarker, re.U) + else: + class NoMatch(object): + def match(self, *args): + return False + self.instruction = self.comment = NoMatch() def clone(self): """ diff --git a/config/tests/unit-Preprocessor.py b/config/tests/unit-Preprocessor.py index fd8c463a480..3fd2a3534af 100644 --- a/config/tests/unit-Preprocessor.py +++ b/config/tests/unit-Preprocessor.py @@ -33,6 +33,16 @@ PASS self.pp.do_include(f) self.assertEqual(self.pp.out.getvalue(), "PASS\n") + def test_no_marker(self): + no_marker = """#if 0 +PASS +#endif +""" + f = NamedIO("no_marker.in", no_marker) + self.pp.setMarker(None) + self.pp.do_include(f) + self.assertEqual(self.pp.out.getvalue(), no_marker) + def test_string_value(self): f = NamedIO("string_value.in", """#define FOO STRING #if FOO diff --git a/js/src/config/Preprocessor.py b/js/src/config/Preprocessor.py index 3ebfbbc0dea..c9192a83e3a 100644 --- a/js/src/config/Preprocessor.py +++ b/js/src/config/Preprocessor.py @@ -92,10 +92,17 @@ class Preprocessor: """ Set the marker to be used for processing directives. Used for handling CSS files, with pp.setMarker('%'), for example. + The given marker may be None, in which case no markers are processed. """ self.marker = aMarker - self.instruction = re.compile('%s(?P[a-z]+)(?:\s(?P.*))?$'%aMarker, re.U) - self.comment = re.compile(aMarker, re.U) + if aMarker: + self.instruction = re.compile('%s(?P[a-z]+)(?:\s(?P.*))?$'%aMarker, re.U) + self.comment = re.compile(aMarker, re.U) + else: + class NoMatch(object): + def match(self, *args): + return False + self.instruction = self.comment = NoMatch() def clone(self): """