Author: waldi Date: Tue Mar 11 17:39:58 2008 New Revision: 10806 Log: lib/kconfigeditor/kconfig/menu/file.py - Parse '-enclosed strings correctly. - End text correctly.
Modified: people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py Modified: people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py ============================================================================== --- people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py (original) +++ people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py Tue Mar 11 17:39:58 2008 @@ -4,37 +4,20 @@ def __init__(self, filename): self.filename = filename - def __lt__(self, other): - return self.filename < other.filename - - def __le__(self, other): - return self.filename <= other.filename - - def __eq__(self, other): - return self.filename == other.filename - - def __ne__(self, other): - return self.filename != other.filename - - def __gt__(self, other): - return self.filename > other.filename - - def __ge__(self, other): - return self.filename >= other.filename - class FileConfig(object): def __init__(self, name): self.name = name + self.prompt = None def __repr__(self): - return "<%s(%s)>" % (self.__class__.__name__, self.name) + return "<%s(%r, %r)>" % (self.__class__.__name__, self.name, self.prompt) class FileSource(object): def __init__(self, filename): self.filename = filename def __repr__(self): - return "<%s(%s)>" % (self.__class__.__name__, self.filename) + return "<%s(%r)>" % (self.__class__.__name__, self.filename) class Parser(object): def __call__(self, fd, filename): @@ -50,6 +33,8 @@ elif line.lstrip()[0] == '#': pass else: + print line + print stack._list stack.top().process_line(line) lineno += 1 return stack.top().process_stop(lineno, 0) @@ -118,7 +103,7 @@ (?P<ind>\s*) (---\s*)?(?P<word>[a-z_]+)(\s*---)? ( - \s*"(?P<rest2>.+)" + \s*(?P<rest2>["'].+) | \s+(?P<rest1>.+) )? @@ -154,6 +139,7 @@ _BlockMenuconfig(self, text) def process_source(self, text, ind): + text = text.strip('"') _BlockSource(self, text) class _BlockContainerDepends(_BlockContainer): @@ -196,7 +182,7 @@ super(_BlockChoice, self).__init__(parent) # TODO self.entry = parent.entry - _BlockConfigData(self) + _BlockConfigData(self, FileConfig(None)) def process_default(self, text, ind): _BlockType(self, text, ind) @@ -208,8 +194,37 @@ pass class _BlockConfigData(_BlockObject, _BlockContainerDepends): + _prompt_rules = r""" +^ + ( + "(?P<text1>[^"]*)" + | + '(?P<text2>[^']*)' + ) + ( + \s* + if + \s+ + (?P<expression>.*) + )? +$""" + _prompt_re = re.compile(_prompt_rules, re.X) + + def __init__(self, parent, entry): + super(_BlockConfigData, self).__init__(parent) + self.entry = entry + + def _process_prompt(self, text, ind): + if text is not None: + match = self._prompt_re.match(text) + if match: + self.entry.prompt = match.group('text1') or match.group('text2') + text = match.group('expression') + _BlockType(self, text, ind) + def process_bool(self, text, ind): - _BlockType(self, text, ind) + # TODO + self._process_prompt(text, ind) process_boolean = process_bool @@ -226,10 +241,12 @@ _BlockHelp(self, ind) def process_hex(self, text, ind): - _BlockType(self, text, ind) + # TODO + self._process_prompt(text, ind) def process_int(self, text, ind): - _BlockType(self, text, ind) + # TODO + self._process_prompt(text, ind) def process_option(self, text, ind): _BlockType(self, text, ind) @@ -238,7 +255,7 @@ pass def process_prompt(self, text, ind): - pass + self._process_prompt(text, ind) def process_range(self, text, ind): _BlockType(self, text, ind) @@ -247,15 +264,16 @@ _BlockType(self, text, ind) def process_string(self, text, ind): - _BlockType(self, text, ind) + # TODO + self._process_prompt(text, ind) def process_tristate(self, text, ind): - _BlockType(self, text, ind) + # TODO + self._process_prompt(text, ind) class _BlockConfig(_BlockConfigData): def __init__(self, parent, name): - super(_BlockConfig, self).__init__(parent) - self.entry = FileConfig(name) + super(_BlockConfig, self).__init__(parent, FileConfig(name)) parent.entry.append(self.entry) class _BlockHelp(_BlockObject): @@ -320,7 +338,7 @@ # TODO entry = FileConfig(name) parent.entry.append(entry) - _BlockConfigData(self) + _BlockConfigData(self, entry) class _BlockSource(_BlockObject): def __init__(self, parent, text): @@ -331,13 +349,9 @@ class _BlockType(_BlockObject): def __init__(self, parent, text, ind): super(_BlockType, self).__init__(parent) - self.nextline = True self.process_line(text) def process_line(self, text): - if self.nextline: - if not text or not text.endswith('\\'): - self.nextline = False - else: - return self.recurse('process_line', text) + if not text or not text.endswith('\\'): + self.pop() _______________________________________________ Kernel-svn-changes mailing list Kernel-svn-changes@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/kernel-svn-changes