changeset 1400:a95414cd1280

wiki parser: replace numerical in_pre state values by strings
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 21 Aug 2006 23:16:39 +0200
parents 4f591cf4f1c6
children acdf0da7a78e
files MoinMoin/parser/text_moin_wiki.py
diffstat 1 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_moin_wiki.py	Mon Aug 21 21:09:46 2006 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Mon Aug 21 23:16:39 2006 +0200
@@ -134,7 +134,14 @@
         self.in_list = 0 # between <ul/ol/dl> and </ul/ol/dl>
         self.in_li = 0 # between <li> and </li>
         self.in_dd = 0 # between <dd> and </dd>
-        self.in_pre = 0
+
+        # states of the parser concerning being inside/outside of some "pre" section:
+        # None == we are not in any kind of pre section (was: 0)
+        # 'search_parser' == we didn't get a parser yet, still searching for it (was: 1)
+        # 'found_parser' == we found a valid parser (was: 2)
+        # 'no_parser' == we have no (valid) parser, use a normal <pre>...</pre> (was: 3)
+        self.in_pre = None
+
         self.in_table = 0
         self.is_big = False
         self.is_small = False
@@ -772,7 +779,7 @@
             # empty bang paths lead to a normal code display
             # can be used to escape real, non-empty bang paths
             word = ''
-            self.in_pre = 3
+            self.in_pre = 'no_parser'
             return self._closeP() + self.formatter.preformatted(1)
         elif s_word.startswith('#!'):
             # First try to find a parser for this (will go away in 2.0)
@@ -781,27 +788,27 @@
 
         if self.parser:
             self.parser_name = parser_name
-            self.in_pre = 2
+            self.in_pre = 'found_parser'
             self.parser_lines = [word]
             return ''
         elif s_word:
-            self.in_pre = 3
+            self.in_pre = 'no_parser'
             return self._closeP() + self.formatter.preformatted(1) + \
                    self.formatter.text(s_word + ' (-)')
         else:
-            self.in_pre = 1
+            self.in_pre = 'search_parser'
             return ''
 
     def _pre_repl(self, word):
         """Handle code displays."""
         word = word.strip()
         if word == '{{{' and not self.in_pre:
-            self.in_pre = 3
-            return self._closeP() + self.formatter.preformatted(self.in_pre)
+            self.in_pre = 'no_parser'
+            return self._closeP() + self.formatter.preformatted(0)
         elif word == '}}}' and self.in_pre:
-            self.in_pre = 0
+            self.in_pre = None
             self.inhibit_p = 0
-            return self.formatter.preformatted(self.in_pre)
+            return self.formatter.preformatted(0)
         return self.formatter.text(word)
 
 
@@ -972,8 +979,7 @@
             if self.in_pre:
                 # TODO: move this into function
                 # still looking for processing instructions
-                # TODO: use strings for pre state, not numbers
-                if self.in_pre == 1:
+                if self.in_pre == 'search_parser':
                     self.parser = None
                     parser_name = ''
                     if line.strip().startswith("#!"):
@@ -981,15 +987,15 @@
                         self.setParser(parser_name)
 
                     if self.parser:
-                        self.in_pre = 2
+                        self.in_pre = 'found_parser'
                         self.parser_lines = [line]
                         self.parser_name = parser_name
                         continue
                     else:
                         self.request.write(self._closeP() +
                                            self.formatter.preformatted(1))
-                        self.in_pre = 3
-                if self.in_pre == 2:
+                        self.in_pre = 'no_parser'
+                if self.in_pre == 'found_parser':
                     # processing mode
                     endpos = line.find("}}}")
                     if endpos == -1:
@@ -1004,7 +1010,7 @@
                     res = self.formatter.parser(self.parser_name, self.parser_lines)
                     self.request.write(res)
                     del self.parser_lines
-                    self.in_pre = 0
+                    self.in_pre = None
                     self.parser = None
 
                     # send rest of line through regex machinery
@@ -1089,7 +1095,7 @@
             formatted_line = self.scan(scan_re, line)
             self.request.write(formatted_line)
 
-            if self.in_pre == 3:
+            if self.in_pre == 'no_parser':
                 self.request.write(self.formatter.linebreak())
 
         # Close code displays, paragraphs, tables and open lists