Author: waldi
Date: Tue Mar 11 13:14:19 2008
New Revision: 10783

Log:
/people/waldi/utils/kconfigeditor2: Add finally.


Added:
   people/waldi/utils/kconfigeditor2/
   people/waldi/utils/kconfigeditor2/kconfigeditor/
   people/waldi/utils/kconfigeditor2/kconfigeditor/__init__.py
   people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/
   people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/__init__.py
   people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/
   people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/__init__.py
   people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py

Added: people/waldi/utils/kconfigeditor2/kconfigeditor/__init__.py
==============================================================================

Added: people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/__init__.py
==============================================================================

Added: people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/__init__.py
==============================================================================

Added: people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py
==============================================================================
--- (empty file)
+++ people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py        
Tue Mar 11 13:14:19 2008
@@ -0,0 +1,280 @@
+import re
+
+class File(object):
+    pass
+
+class _Parser(object):
+    def __call__(self, fd):
+        lineno = 0
+
+        stack = _Stack()
+        _BlockRoot(stack)
+
+        for line in fd:
+            line = line.rstrip()
+            if not line:
+                stack.top().process_line_empty()
+            elif line.lstrip()[0] == '#':
+                pass
+            else:
+                print stack._list
+                print line
+                stack.top().process_line(line)
+            lineno += 1
+        stack.top().stop(lineno, 0)
+
+class _Text(object):
+    __slots__ = "text", "lineno", "column"
+
+    def __init__(self, text, lineno, column):
+        self.text = text
+        self.lineno = lineno
+        self.column = column
+
+    def __getitem__(self, key):
+        if isinstance(key, slice):
+            return _text(self.text[key], self.lineno, self.column + key.start)
+        raise TypeError
+
+    def __len__(self):
+        return len(self.text)
+
+    def __str__(self):
+        raise Exception
+
+    def __unicode__(self):
+        return self.text
+
+class _Stack(object):
+    __slots__ = '_list'
+
+    def __init__(self, list = []):
+        self._list = list
+
+    def pop(self, check = None):
+        if check is not None and self._list[-1] != check:
+            raise Exception
+        return self._list.pop()
+
+    def push(self, item):
+        self._list.append(item)
+
+    def top(self):
+        return self._list[-1]
+
+class _Element(object):
+    def __init__(self, parent):
+        self.stack = parent.stack
+        self.stack.push(self)
+
+    def end(self):
+        pass
+
+    def pop(self):
+        self.end()
+        self.stack.pop(self)
+
+    def recurse(self, name, *args):
+        self.pop()
+        getattr(self.stack.top(), name)(*args)
+
+class _BlockContainer(object):
+    split_rules = r"""
+^
+    (?P<ind>\s*)
+    (---)?(?P<word>[a-z_]+)(---)?
+    (
+        \s+(?P<rest1>.+)
+        |
+        "(?P<rest2>.+)"
+    )?
+    \s*
+$"""
+    split_re = re.compile(split_rules, re.X)
+
+    def process_line(self, text):
+        match = self.split_re.match(text)
+        if not match:
+            raise Exception, "Can't parse: '%s'" % text
+        rest = match.group('rest1') or match.group('rest2')
+        print "rest:", rest
+        getattr(self, "process_%s" % match.group('word'))(rest, 
match.group('ind'))
+
+    def process_line_empty(self):
+        pass
+
+class _BlockContainerChoice(_BlockContainer):
+    def process_choice(self, text, ind):
+        _BlockChoice(self)
+
+class _BlockContainerCommon(_BlockContainer):
+    def process_comment(self, text, ind):
+        _BlockComment(self)
+
+    def process_config(self, text, ind):
+        _BlockConfig(self)
+
+    def process_if(self, text, ind):
+        _BlockIf(self)
+
+    def process_menuconfig(self, text, ind):
+        _BlockMenuconfig(self, ind)
+
+    def process_source(self, text, ind):
+        pass
+
+class _BlockContainerDepends(_BlockContainer):
+    def process_depends(self, text, ind):
+        _BlockDepends(self, ind)
+
+class _BlockContainerMenu(_BlockContainer):
+    def process_menu(self, text, ind):
+        _BlockMenu(self, text)
+
+class _BlockObject(_Element):
+    def __getattr__(self, name):
+        def ret(*args):
+            self.recurse(name, *args)
+        return ret
+
+class _BlockObjectIndentation(_BlockObject):
+    split_rules = r"^(?P<ind>\s+)(?P<rest>.*)$"
+    split_re = re.compile(split_rules)
+
+    def __init__(self, parent, ind):
+        super(_BlockObjectIndentation, self).__init__(parent)
+        self._indentation = ind
+
+    def process_line(self, text):
+        match = self.split_re.match(text)
+        if not match:
+            return self.recurse('process_line', text)
+        l = len(match.group('ind'))
+        if self._indentation < l:
+            return self.recurse('process_line', text)
+
+    def process_line_empty(self):
+        pass
+
+class _BlockRoot(
+    _BlockContainerChoice,
+    _BlockContainerCommon,
+    _BlockContainerMenu,
+    ):
+    def __init__(self, stack):
+        self.stack = stack
+        stack.push(self)
+
+    def __getattr__(self, name):
+        raise AttributeError, name
+
+    def process_mainmenu(self, text, ind):
+        pass
+
+    def stop(self, lineno, column):
+        self.stack.pop(self)
+
+class _BlockChoice(_BlockObject, _BlockContainerCommon):
+    def __init__(self, parent):
+        super(_BlockChoice, self).__init__(parent)
+        _BlockConfig(self)
+
+    def process_default(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_endchoice(self, text, ind):
+        self.pop()
+
+class _BlockComment(_BlockObject, _BlockContainerDepends):
+    pass
+
+class _BlockConfig(_BlockObject, _BlockContainerDepends):
+    def process_bool(self, text, ind):
+        _BlockType(self, text, ind)
+
+    process_boolean = process_bool
+
+    def process_default(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_def_bool(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_def_tristate(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_help(self, text, ind):
+        _BlockHelp(self, ind)
+
+    def process_hex(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_int(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_option(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_optional(self, text, ind):
+        pass
+
+    def process_prompt(self, text, ind):
+        pass
+
+    def process_range(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_select(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_string(self, text, ind):
+        _BlockType(self, text, ind)
+
+    def process_tristate(self, text, ind):
+        _BlockType(self, text, ind)
+
+class _BlockDepends(_BlockObjectIndentation):
+    pass
+
+class _BlockHelp(_BlockObjectIndentation):
+    pass
+
+class _BlockIf(_BlockObject,
+    _BlockContainerChoice,
+    _BlockContainerCommon,
+    _BlockContainerMenu,
+    ):
+
+    def process_endif(self, text, ind):
+        self.pop()
+
+class _BlockMenu(_BlockObject,
+    _BlockContainerChoice,
+    _BlockContainerCommon,
+    _BlockContainerMenu,
+    ):
+    def __init__(self, parent, text):
+        super(_BlockMenu, self).__init__(parent)
+        pass
+
+    def process_depends(self, text, ind):
+        pass
+
+    def process_endmenu(self, text, ind):
+        self.pop()
+
+class _BlockMenuconfig(_BlockConfig, _BlockMenu):
+    pass
+
+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)

_______________________________________________
Kernel-svn-changes mailing list
Kernel-svn-changes@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/kernel-svn-changes

Reply via email to