Bug 774032 part 2 - Allow to disable markers in Preprocessor.py. r=ted

This commit is contained in:
Mike Hommey 2012-08-04 08:47:28 +02:00
parent afb4432cd9
commit 67045cf5c5
3 changed files with 28 additions and 4 deletions

View File

@ -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
if aMarker:
self.instruction = re.compile('%s(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'%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):
"""

View File

@ -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

View File

@ -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
if aMarker:
self.instruction = re.compile('%s(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'%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):
"""