|
|
|
@ -9,8 +9,10 @@ from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\
|
|
|
|
|
|
|
|
|
|
class CompizFormat(BaseFormat):
|
|
|
|
|
_initialized = False
|
|
|
|
|
_comment_symbol = ''
|
|
|
|
|
|
|
|
|
|
def __init__(self, document_text: str, ignore_comments=False):
|
|
|
|
|
def __init__(self, document_text: str, ignore_comments=False,
|
|
|
|
|
join_before=False, comment_symbol=''):
|
|
|
|
|
processing_methods = [self._parse_comment_line,
|
|
|
|
|
self._parse_section_line,
|
|
|
|
|
self._parse_parameter_line,
|
|
|
|
@ -19,6 +21,7 @@ class CompizFormat(BaseFormat):
|
|
|
|
|
super().__init__(processing_methods)
|
|
|
|
|
self._ignore_comments = ignore_comments
|
|
|
|
|
self._comments_processing = True
|
|
|
|
|
self._join_before = join_before
|
|
|
|
|
self._need_finish = True
|
|
|
|
|
self._format = 'compiz'
|
|
|
|
|
|
|
|
|
@ -26,8 +29,8 @@ class CompizFormat(BaseFormat):
|
|
|
|
|
self._current_section_name = ''
|
|
|
|
|
|
|
|
|
|
self._last_comments_list = []
|
|
|
|
|
if not self._initialized:
|
|
|
|
|
self._initialize_parser()
|
|
|
|
|
if not self._initialized or comment_symbol != self._comment_symbol:
|
|
|
|
|
self._initialize_parser(comment_symbol)
|
|
|
|
|
|
|
|
|
|
if document_text == '':
|
|
|
|
|
self._document_dictionary = OrderedDict()
|
|
|
|
@ -36,7 +39,7 @@ class CompizFormat(BaseFormat):
|
|
|
|
|
self._lines_to_dictionary(document_lines)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def _initialize_parser(cls):
|
|
|
|
|
def _initialize_parser(cls, comment_symbol):
|
|
|
|
|
section_name = originalTextFor(
|
|
|
|
|
OneOrMore(Word(alphanums+'_'))
|
|
|
|
|
)
|
|
|
|
@ -66,11 +69,21 @@ class CompizFormat(BaseFormat):
|
|
|
|
|
+ parameter_name('name')
|
|
|
|
|
+ restOfLine.suppress())('parameter_name')
|
|
|
|
|
|
|
|
|
|
cls._comment_line = originalTextFor(
|
|
|
|
|
Literal('#')
|
|
|
|
|
+ ZeroOrMore(Word(printables
|
|
|
|
|
+ pyparsing_unicode.alphanums))
|
|
|
|
|
)('comment')
|
|
|
|
|
if not comment_symbol:
|
|
|
|
|
cls._comment_line = originalTextFor(
|
|
|
|
|
Literal('#')
|
|
|
|
|
+ ZeroOrMore(Word(
|
|
|
|
|
printables
|
|
|
|
|
+ pyparsing_unicode.alphanums))
|
|
|
|
|
)('comment')
|
|
|
|
|
else:
|
|
|
|
|
cls._comment_line = originalTextFor(
|
|
|
|
|
(Literal('#') | Literal(comment_symbol))
|
|
|
|
|
+ ZeroOrMore(Word(
|
|
|
|
|
printables
|
|
|
|
|
+ pyparsing_unicode.alphanums))
|
|
|
|
|
)('comment')
|
|
|
|
|
|
|
|
|
|
cls._initialized = True
|
|
|
|
|
|
|
|
|
|
def _parse_section_line(self, line):
|
|
|
|
|