]> git.lyx.org Git - features.git/commitdiff
* LyX.py
authorJosé Matox <jamatos@lyx.org>
Thu, 27 Jul 2006 18:30:13 +0000 (18:30 +0000)
committerJosé Matox <jamatos@lyx.org>
Thu, 27 Jul 2006 18:30:13 +0000 (18:30 +0000)
* lyx_1_1_5.py
* lyx_1_2.py
* lyx_1_3.py
* lyx_1_4.py
* lyx_1_5.py

* parser_tools.py: remove functions that are not generic, i.e.
assume a specific pattern for the file format, and move them to the
places where they are used.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14503 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_1_1_5.py
lib/lyx2lyx/lyx_1_2.py
lib/lyx2lyx/lyx_1_3.py
lib/lyx2lyx/lyx_1_4.py
lib/lyx2lyx/lyx_1_5.py
lib/lyx2lyx/parser_tools.py

index 1ee2fb0c06c55be9a44b4a4ef7cdcfe66c248c85..6d9605f06a1e0e7a8ba1c53ea1f7e018ad1db065 100644 (file)
@@ -17,7 +17,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 from parser_tools import get_value, check_token, find_token,\
-     find_tokens, find_end_of, find_end_of_inset
+     find_tokens, find_end_of
 import os.path
 import gzip
 import sys
@@ -30,6 +30,16 @@ version_lyx2lyx = lyx2lyx_version.version
 
 default_debug_level = 2
 
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
 # Regular expressions used
 format_re = re.compile(r"(\d)[\.,]?(\d\d)")
 fileformat = re.compile(r"\\lyxformat\s*(\S*)")
@@ -230,6 +240,7 @@ class LyX_Base:
             except:
                 self.input = open(input)
         else:
+            self.dir = ''
             self.input = sys.stdin
 
 
index d8dc59006e727065208b91bb8c39f0b4b99d7640..bb924dd16758904b900696f8c8252deb5cc82e40 100644 (file)
 
 import re
 import string
-from parser_tools import find_token, find_token_backwards, find_re, get_layout
+from parser_tools import find_token, find_token_backwards, find_re
 
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+    tokens = string.split(line)
+    if len(tokens) > 1:
+        return tokens[1]
+    return default_layout
+
+
+####################################################################
 
 math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"]
 
index 3ac5d9cfb92eba3c7fef187e492f2f92aaa71293..3d9cd8b9121e81e382d3b04346698d00217f2ad9 100644 (file)
 import string
 import re
 
-from parser_tools import find_token, find_token_backwards, get_next_paragraph,\
-                         find_tokens, find_end_of_inset, find_re, \
-                         is_nonempty_line, get_paragraph, find_nonempty_line, \
-                         get_value, get_tabular_lines, check_token, get_layout
+from parser_tools import find_token, find_token_backwards, \
+                         find_tokens,  find_tokens_backwards, find_beginning_of, find_end_of, find_re, \
+                         is_nonempty_line, find_nonempty_line, \
+                         get_value, check_token
+
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+    tokens = string.split(line)
+    if len(tokens) > 1:
+        return tokens[1]
+    return default_layout
+
+
+# Finds the paragraph that contains line i.
+def get_paragraph(lines, i, format):
+    begin_layout = "\\layout"
+
+    while i != -1:
+        i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
+        if i == -1: return -1
+        if check_token(lines[i], begin_layout):
+            return i
+        i = find_beginning_of_inset(lines, i)
+    return -1
+
+
+# Finds the paragraph after the paragraph that contains line i.
+def get_next_paragraph(lines, i, format):
+    tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
+
+    while i != -1:
+        i = find_tokens(lines, tokens, i)
+        if not check_token(lines[i], "\\begin_inset"):
+            return i
+        i = find_end_of_inset(lines, i)
+    return -1
+
+
+def find_beginning_of_inset(lines, i):
+    return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+# Finds the matching \end_inset
+def find_end_of_inset(lines, i):
+    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+def find_end_of_tabular(lines, i):
+    return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
+
+
+def get_tabular_lines(lines, i):
+    result = []
+    i = i+1
+    j = find_end_of_tabular(lines, i)
+    if j == -1:
+        return []
+
+    while i <= j:
+        if check_token(lines[i], "\\begin_inset"):
+            i = find_end_of_inset(lines, i)+1
+        else:
+            result.append(i)
+            i = i+1
+    return result
+
+# End of helper functions
+####################################################################
+
 
 floats = {
     "footnote": ["\\begin_inset Foot",
index acb8d9f62f0894a82a3cb0d79436df5549725af2..0439f72ded59ca4604fc1d1f78a7acc73bf57a24 100644 (file)
 
 import string
 import re
-from parser_tools import find_token, find_end_of_inset, get_value,\
+from parser_tools import find_token, find_end_of, get_value,\
                          find_token_exact, del_token
 
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+    "Finds the matching \end_inset"
+    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
 def change_insetgraphics(file):
     lines = file.body
     i = 0
index 28a7743d32888b89de09a98c9c1dbab0fa5070f3..4a9cf720d456b9507b1453e18342e8f5964fc6ed 100644 (file)
 import re
 from os import access, F_OK
 import os.path
-from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
-                         get_paragraph, get_value, del_token, is_nonempty_line,\
-                         find_tokens, find_end_of, find_token_exact, find_tokens_exact,\
-                         find_re, get_layout
+from parser_tools import check_token, find_token, \
+                         get_value, del_token, is_nonempty_line, \
+                         find_tokens, find_end_of, find_beginning_of, find_token_exact, find_tokens_exact, \
+                         find_re, find_tokens_backwards
 from sys import stdin
 from string import replace, split, find, strip, join
 
 from lyx_0_12 import update_latexaccents
 
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+    tokens = split(line)
+    if len(tokens) > 1:
+        return tokens[1]
+    return default_layout
+
+
+def get_paragraph(lines, i, format):
+    "Finds the paragraph that contains line i."
+
+    if format < 225:
+        begin_layout = "\\layout"
+    else:
+        begin_layout = "\\begin_layout"
+    while i != -1:
+        i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
+        if i == -1: return -1
+        if check_token(lines[i], begin_layout):
+            return i
+        i = find_beginning_of_inset(lines, i)
+    return -1
+
+
+def find_beginning_of_inset(lines, i):
+    return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+def get_next_paragraph(lines, i, format):
+    "Finds the paragraph after the paragraph that contains line i."
+
+    if format < 225:
+        tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
+    elif format < 236:
+        tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_document"]
+    else:
+        tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"]
+    while i != -1:
+        i = find_tokens(lines, tokens, i)
+        if not check_token(lines[i], "\\begin_inset"):
+            return i
+        i = find_end_of_inset(lines, i)
+    return -1
+
+
+def find_end_of_inset(lines, i):
+    "Finds the matching \end_inset"
+    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
 ##
 # Remove \color default
 #
index 78f703a7629693b209b6b88d5fe1fde1c4382d14..b2ed93ab47ae07770af3c73f183a451576527f3d 100644 (file)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 import re
-from parser_tools import find_token, find_token_exact, find_tokens, find_end_of_inset, get_value
+from parser_tools import find_token, find_token_exact, find_tokens, find_end_of, get_value
 from string import replace
 
 
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
 ##
 #  Notes: Framed/Shaded
 #
index 379f961bb325a15a73e1eb998fffbd81f9168e39..e459cedd48f801d91b73f0bf853c17ec69ff346c 100644 (file)
@@ -111,13 +111,6 @@ def get_value(lines, token, start, end = 0):
         return ""
 
 
-def get_layout(line, default_layout):
-    tokens = string.split(line)
-    if len(tokens) > 1:
-        return tokens[1]
-    return default_layout
-
-
 def del_token(lines, token, start, end):
     k = find_token_exact(lines, token, start, end)
     if k == -1:
@@ -127,37 +120,6 @@ def del_token(lines, token, start, end):
         return end - 1
 
 
-# Finds the paragraph that contains line i.
-def get_paragraph(lines, i, format):
-    if format < 225:
-        begin_layout = "\\layout"
-    else:
-        begin_layout = "\\begin_layout"
-    while i != -1:
-        i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
-        if i == -1: return -1
-        if check_token(lines[i], begin_layout):
-            return i
-        i = find_beginning_of_inset(lines, i)
-    return -1
-
-
-# Finds the paragraph after the paragraph that contains line i.
-def get_next_paragraph(lines, i, format):
-    if format < 225:
-        tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
-    elif format < 236:
-        tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_document"]
-    else:
-        tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"]
-    while i != -1:
-        i = find_tokens(lines, tokens, i)
-        if not check_token(lines[i], "\\begin_inset"):
-            return i
-        i = find_end_of_inset(lines, i)
-    return -1
-
-
 def find_end_of(lines, i, start_token, end_token):
     count = 1
     n = len(lines)
@@ -186,36 +148,6 @@ def find_beginning_of(lines, i, start_token, end_token):
     return -1
 
 
-# Finds the matching \end_inset
-def find_end_of_inset(lines, i):
-    return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
-
-
-# Finds the matching \end_inset
-def find_beginning_of_inset(lines, i):
-    return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
-
-
-def find_end_of_tabular(lines, i):
-    return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
-
-
-def get_tabular_lines(lines, i):
-    result = []
-    i = i+1
-    j = find_end_of_tabular(lines, i)
-    if j == -1:
-        return []
-
-    while i <= j:
-        if check_token(lines[i], "\\begin_inset"):
-            i = find_end_of_inset(lines, i)+1
-        else:
-            result.append(i)
-            i = i+1
-    return result
-
-
 def is_nonempty_line(line):
     return line != " "*len(line)