Skip to content

Commit 7347958

Browse files
committed
support of multiple commands on the same line in *.vis file
1 parent 1fe84b5 commit 7347958

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

HTMLVisualizer.py

+32-31
Original file line numberDiff line numberDiff line change
@@ -226,37 +226,38 @@ def printPage(self, file, destination):
226226
self.ln_subs = {}
227227

228228
if (index + 1) in self.vis_lines:
229-
command = self.vis_lines[index + 1]
230-
if command['command'] == 'comment':
231-
prefix = ""
232-
if len(line) > 0:
233-
prefix = 3*" "
234-
# put comment at the end of the current line
235-
clm = len(oline) + 1
236-
self.add2lnSubs(clm, len(command['value']), prefix + command['value'])
237-
238-
elif command['command'] == 'fold':
239-
fold = True
240-
fold_start = index + 1
241-
fold_end = command['endline']
242-
fold_text = self.pretokenize(command['value'])
243-
folded = command['folded']
244-
elif command['command'] == 'highlight':
245-
v_keyword = command['keyword']
246-
if v_keyword in self.src_keywords and (index + 1) in self.src_keywords[ v_keyword ]:
247-
clm = self.src_keywords[ v_keyword ][ index + 1 ]
248-
for clm_item in clm:
249-
self.add2lnSubs(clm_item, len(v_keyword), self.highlightBox(v_keyword))
250-
comment = self.highlightLabel( self.pretokenize(command['value']) )
251-
self.add2lnSubs(len(oline)+1, len(comment), comment)
252-
elif command['command'] == 'needinfo':
253-
v_keyword = command['keyword']
254-
if v_keyword in self.src_keywords and (index + 1) in self.src_keywords[ v_keyword ]:
255-
clm = self.src_keywords[ v_keyword ][ index + 1 ]
256-
for clm_item in clm:
257-
self.add2lnSubs(clm_item, len(v_keyword), self.needinfoBox(v_keyword, command['attrs']))
258-
comment = self.needinfoLabel( self.pretokenize(command['value']) )
259-
self.add2lnSubs(len(oline)+1, len(comment), comment)
229+
commands = self.vis_lines[index + 1]
230+
for command in commands:
231+
if command['command'] == 'comment':
232+
prefix = ""
233+
if len(line) > 0:
234+
prefix = 3*" "
235+
# put comment at the end of the current line
236+
clm = len(oline) + 1
237+
self.add2lnSubs(clm, len(command['value']), prefix + command['value'])
238+
239+
elif command['command'] == 'fold':
240+
fold = True
241+
fold_start = index + 1
242+
fold_end = command['endline']
243+
fold_text = self.pretokenize(command['value'])
244+
folded = command['folded']
245+
elif command['command'] == 'highlight':
246+
v_keyword = command['keyword']
247+
if v_keyword in self.src_keywords and (index + 1) in self.src_keywords[ v_keyword ]:
248+
clm = self.src_keywords[ v_keyword ][ index + 1 ]
249+
for clm_item in clm:
250+
self.add2lnSubs(clm_item, len(v_keyword), self.highlightBox(v_keyword))
251+
comment = self.highlightLabel( self.pretokenize(command['value']) )
252+
self.add2lnSubs(len(oline)+1, len(comment), comment)
253+
elif command['command'] == 'needinfo':
254+
v_keyword = command['keyword']
255+
if v_keyword in self.src_keywords and (index + 1) in self.src_keywords[ v_keyword ]:
256+
clm = self.src_keywords[ v_keyword ][ index + 1 ]
257+
for clm_item in clm:
258+
self.add2lnSubs(clm_item, len(v_keyword), self.needinfoBox(v_keyword, command['attrs']))
259+
comment = self.needinfoLabel( self.pretokenize(command['value']) )
260+
self.add2lnSubs(len(oline)+1, len(comment), comment)
260261

261262
for keyword in self.keyworddb:
262263
if keyword in line:

VisualizationParser.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ class VisualizationParser(object):
44

55
def __init__(self, file):
66
self.file = file
7+
self.lines = {}
78
self.parse()
89

10+
def addCommand(self, line_number, command):
11+
if line_number not in self.lines:
12+
self.lines[line_number] = [command]
13+
else:
14+
self.lines[line_number].append(command)
15+
916
def parse(self):
1017
vis_content = ""
1118
with open(self.file, "r") as file:
1219
vis_content = file.read()
1320

14-
self.lines = {}
1521
line_counter = 0
1622
for line in vis_content.split("\n"):
1723
line_counter = line_counter + 1
@@ -36,12 +42,15 @@ def parse(self):
3642
sys.stderr.write("line %s: '%s' not recognized, wrong format" % (line_counter, line))
3743
continue
3844

39-
self.lines[ int(items[0]) ] = {'command': items[1], 'endline': int(items[2]), 'folded': int(items[3]), 'value': ":".join(items[4:])}
45+
self.addCommand(int(items[0]), {'command': items[1], 'endline': int(items[2]), 'folded': int(items[3]), 'value': ":".join(items[4:])})
46+
#self.lines[ int(items[0]) ] = {'command': items[1], 'endline': int(items[2]), 'folded': int(items[3]), 'value': ":".join(items[4:])}
4047
elif command == 'highlight':
4148
if len(items) < 3:
4249
sys.stderr.write("line %s: '%s' not recognized, wrong format" % (line_counter, line))
4350
continue
44-
self.lines[ int(items[0]) ] = {'command': items[1], 'keyword': items[2], 'value': items[3:][0]}
51+
52+
self.addCommand(int(items[0]), {'command': items[1], 'keyword': items[2], 'value': items[3:][0]})
53+
#self.lines[ int(items[0]) ] = {'command': items[1], 'keyword': items[2], 'value': items[3:][0]}
4554
elif command.startswith('needinfo', 0, 8):
4655
if len(items) < 3:
4756
sys.stderr.write("line %s: '%s' not recognized, wrong format" % (line_counter, line))
@@ -60,9 +69,11 @@ def parse(self):
6069

6170
attrs_db[ pair[0] ] = pair[1]
6271

63-
self.lines[ int(items[0]) ] = {'command': 'needinfo', 'keyword': items[2], 'value': items[3:][0], 'attrs': attrs_db }
72+
self.addCommand( int(items[0]), {'command': 'needinfo', 'keyword': items[2], 'value': items[3:][0], 'attrs': attrs_db } )
73+
#self.lines[ int(items[0]) ] = {'command': 'needinfo', 'keyword': items[2], 'value': items[3:][0], 'attrs': attrs_db }
6474
else:
65-
self.lines[ int(items[0]) ] = {'command': items[1], 'value': "// " + ":".join(items[2:])}
75+
self.addCommand( int(items[0]), {'command': items[1], 'value': "// " + ":".join(items[2:])} )
76+
#self.lines[ int(items[0]) ] = {'command': items[1], 'value': "// " + ":".join(items[2:])}
6677

6778
def getCommands(self):
6879
return self.lines

0 commit comments

Comments
 (0)