gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24527 - monkey/trunk/seaspider


From: gnunet
Subject: [GNUnet-SVN] r24527 - monkey/trunk/seaspider
Date: Thu, 25 Oct 2012 05:01:56 +0200

Author: teichm
Date: 2012-10-25 05:01:56 +0200 (Thu, 25 Oct 2012)
New Revision: 24527

Modified:
   monkey/trunk/seaspider/seasp2_convert
Log:
seasp2_convert now parses Begin-Exp...End-Exp code and some performance 
improvements done

Modified: monkey/trunk/seaspider/seasp2_convert
===================================================================
--- monkey/trunk/seaspider/seasp2_convert       2012-10-25 00:23:54 UTC (rev 
24526)
+++ monkey/trunk/seaspider/seasp2_convert       2012-10-25 03:01:56 UTC (rev 
24527)
@@ -3,6 +3,7 @@
 import sqlite3
 import argparse
 import os
+import re
 from collections import deque
 
 
@@ -69,6 +70,7 @@
        scope_end = []
        scope_end.append(32767)
        parameters = deque()
+       expr_list = []
        prevtype = ""
        seafile_lineno = 0
 
@@ -88,35 +90,43 @@
        while lines:
                for line in lines:
                        seafile_lineno += 1
-                       try:
-                               (rowtype, remainder) = line.split(': ', 1)
-                       except ValueError:
-                               rowtype = "wrong line format: " + line
+                       if prevtype == 'Begin-Expression':
+                               if re.match(re.escape("End-Expression: " + 
rowfile + ':' + str(lineno) + ' ' + str(iscall)), line):
+                                       vals = (rowfile, ' '.join(expr_list), 
lineno, scope_end[-1], iscall)
+                                       sql_cur.execute('INSERT INTO Expression 
VALUES (NULL,?,?,?,?,?)', vals)
+                                       prevtype = 'End-Expression'
+                               expr_list.append(line.strip())
+                               continue
+
+                       m = re.match(r"([A-Za-z-]+): ([^:]+):(\d+) (.+)", line)
+                       if not m or m.lastindex < 4:
+                               print 'unknown entry type: ', filename, ' on 
line ', seafile_lineno
+                               prevtype = ''
+                               continue
+                       rowtype = m.group(1)
+                       rowfile = m.group(2)
+
                        if rowtype == 'SystemGlobal':
-                               (rowfile, rowglob) = remainder.split(':', 1)
-                               (lineno, globalvar) = rowglob.split(' ', 1)
+                               globalvar = m.group(4)
                                vals = (cfilename, globalvar, 0, 32767, 0)
                                sql_cur.execute('INSERT INTO Expression VALUES 
(NULL,?,?,?,?,?)', vals)
                        elif rowtype == 'Global':
-                               (rowfile, rowglob) = remainder.split(':', 1)
-                               (lineno, globalvar) = rowglob.split(' ', 1)
-                               lineno = int(lineno)
+                               lineno = int(m.group(3))
+                               globalvar = m.group(4)
                                vals = (rowfile, globalvar, lineno, 32767, 0)
                                sql_cur.execute('INSERT INTO Expression VALUES 
(NULL,?,?,?,?,?)', vals)
                        elif rowtype == 'Function':
                                pass
-#                              print 'nothing to do for entry type Function'
+#                              print 'nothing to do yet for entry type 
Function'
                        elif rowtype == 'Parameter':
-                               if prevtype == 'Function' or prevtype == 
'Parameter':
-                                       (rowfile, rowpar) = 
remainder.split(':', 1)
-                                       (lineno, para) = rowpar.split(' ', 1)
-                                       lineno = int(lineno)
-                                       parameters.append((rowfile, para, 
lineno))
+                               if prevtype != 'Function' and prevtype != 
'Parameter':
+                                       print 'Parameter can only follow 
Function or another Parameter: ', filename, ' on line ', seafile_lineno
+                               lineno = int(m.group(3))
+                               para = m.group(4)
+                               parameters.append((rowfile, para, lineno))
                        elif rowtype == 'Scope':
-                               (rowfile, scoperange) = remainder.split(':', 1)
-                               (scope_begin, scope_end_tmp) = 
scoperange.split(' ', 1)
-                               scope_begin = int(scope_begin)
-                               scope_end.append(int(scope_end_tmp) + 1)
+                               scope_begin = int(m.group(3))
+                               scope_end.append(int(m.group(4)) + 1)
                                while prevtype == 'Parameter':
                                        try:
                                                (rowfile, para, lineno) = 
parameters.popleft()
@@ -124,16 +134,14 @@
                                                break
                                        vals = (rowfile, para, lineno, 
scope_end[-1], 0)
                                        sql_cur.execute('INSERT INTO Expression 
VALUES (NULL,?,?,?,?,?)', vals)
-#                              print 'entered new scope: ', scope_begin, '-', 
scope_end[-1]
-                       elif rowtype == 'Expression':
-                               (rowfile, rowexpr) = remainder.split(':', 1)
-                               (lineno, iscall, expression) = rowexpr.split(' 
', 2)
-                               lineno = int(lineno)
-                               iscall = int(iscall)
+                       elif rowtype == 'Begin-Expression':
+                               lineno = int(m.group(3))
+                               iscall = int(m.group(4)[0])
                                if lineno > scope_end[-1]:
                                        scope_end.pop()
-                               vals = (rowfile, expression, lineno, 
scope_end[-1], iscall)
-                               sql_cur.execute('INSERT INTO Expression VALUES 
(NULL,?,?,?,?,?)', vals)
+                               del expr_list[:]
+                               tmp = (m.group(4)[1:]).strip()
+                               if len(tmp) > 0: expr_list.append(tmp)
                        else:
                                print 'unknown entry type: ', filename, ' on 
line ', seafile_lineno
                        prevtype = rowtype




reply via email to

[Prev in Thread] Current Thread [Next in Thread]