Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b819bdf

Browse files
committed
handle a few new things
1 parent 26a9d37 commit b819bdf

2 files changed

Lines changed: 66 additions & 30 deletions

File tree

Doc/partparse.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def getnextarg(length, buf, pp, item):
788788
item = item+1
789789
return length, item
790790
else:
791+
ch = pp[item]
791792
try:
792793
str = `s(buf, ch.data)`
793794
except TypeError:
@@ -852,9 +853,9 @@ def init(self):
852853
return self
853854
def write(self, data):
854855
self.data = self.data + data
855-
856+
856857
# ignore these commands
857-
ignoredcommands = ('bcode', 'ecode', 'optional')
858+
ignoredcommands = ('bcode', 'ecode')
858859
# map commands like these to themselves as plaintext
859860
wordsselves = ('UNIX', 'ABC', 'C', 'ASCII', 'EOF')
860861
# \{ --> {, \} --> }, etc
@@ -1080,7 +1081,7 @@ def do_funcdesc(length, buf, pp, i):
10801081
idxsi = hist.indexsubitem # words
10811082
command = ''
10821083
cat_class = ''
1083-
if idxsi and idxsi[-1] in ('method', 'attribute'):
1084+
if idxsi and idxsi[-1] in ('method', 'protocol'):
10841085
command = 'defmethod'
10851086
cat_class = string.join(idxsi[:-1])
10861087
elif len(idxsi) == 2 and idxsi[1] == 'function':
@@ -1170,9 +1171,9 @@ def do_datadesc(length, buf, pp, i):
11701171
command = ''
11711172
cat_class = ''
11721173
class_class = ''
1173-
if idxsi[-1] == 'attribute':
1174+
if idxsi[-1] in ('attribute', 'option'):
11741175
command = 'defcv'
1175-
cat_class = 'attribute'
1176+
cat_class = idxsi[-1]
11761177
class_class = string.join(idxsi[:-1])
11771178
elif len(idxsi) == 3 and idxsi[:2] == ['in', 'module']:
11781179
command = 'defcv'
@@ -1332,7 +1333,12 @@ def changeit(buf, pp):
13321333
chunk(GROUP, ch.where, ingroupch)]
13331334
length, i = length+2, i+2
13341335

1335-
elif envname == 'tableiii':
1336+
elif (envname == 'tableiii') or \
1337+
(envname == 'tableii'):
1338+
if (envname == 'tableii'):
1339+
ltable = 2
1340+
else:
1341+
ltable = 3
13361342
wh = ch.where
13371343
newcode = []
13381344

@@ -1359,7 +1365,8 @@ def changeit(buf, pp):
13591365
del pp[i:newi]
13601366
length = length - (newi-i)
13611367

1362-
for count in range(3):
1368+
itembody = []
1369+
for count in range(ltable):
13631370
length, newi = getnextarg(length, buf, pp, i)
13641371
emphgroup = [\
13651372
chunk(CSNAME, wh, 'emph'), \
@@ -1368,7 +1375,7 @@ def changeit(buf, pp):
13681375
length = length - (newi-i)
13691376
if count == 0:
13701377
itemarg = emphgroup
1371-
elif count == 2:
1378+
elif count == ltable-1:
13721379
itembody = itembody + \
13731380
[chunk(PLAIN, wh, ' --- ')] + \
13741381
emphgroup
@@ -1437,7 +1444,7 @@ def changeit(buf, pp):
14371444
chunk(GROUP, ch.where, [\
14381445
chunk(PLAIN, ch.where, 'table')])]
14391446
i, length = i+2, length+2
1440-
elif envname == 'tableiii':
1447+
elif (envname == 'tableiii') or (envname == 'tableii'):
14411448
pp[i:i] = [\
14421449
chunk(CSLINE, ch.where, 'end'), \
14431450
chunk(GROUP, ch.where, [\
@@ -1457,7 +1464,16 @@ def changeit(buf, pp):
14571464

14581465
elif ch.chtype == chunk_type(CSNAME):
14591466
# control name transformations
1460-
if s(buf, ch.data) in ignoredcommands:
1467+
if s(buf, ch.data) == 'optional':
1468+
pp[i-1].chtype = chunk_type (PLAIN)
1469+
pp[i-1].data = '['
1470+
if (i < length) and \
1471+
(pp[i].chtype == chunk_type(GROUP)):
1472+
cp=pp[i].data
1473+
pp[i:i+1]=cp + [\
1474+
chunk(PLAIN, ch.where, ']')]
1475+
length = length+len(cp)
1476+
elif s(buf, ch.data) in ignoredcommands:
14611477
del pp[i-1]
14621478
i, length = i-1, length-1
14631479
elif s(buf, ch.data) == '@' and \
@@ -1503,7 +1519,7 @@ def changeit(buf, pp):
15031519
length = length - (newi-i)
15041520
length, newi = getnextarg(length, buf, pp, i)
15051521
text = flattext(buf, pp[i:newi])
1506-
if text[0] != '(' or text[-1] != ')':
1522+
if text[:1] != '(' or text[-1:] != ')':
15071523
raise error, 'expected indexsubitme enclosed in braces'
15081524
words = string.split(text[1:-1])
15091525
hist.indexsubitem = words
@@ -1527,7 +1543,7 @@ def changeit(buf, pp):
15271543

15281544
cat_class = ''
15291545
if len(idxsi) >= 2 and idxsi[1] in \
1530-
('method', 'function'):
1546+
('method', 'function', 'protocol'):
15311547
command = 'findex'
15321548
elif len(idxsi) >= 2 and idxsi[1] in \
15331549
('exception', 'object'):
@@ -1590,7 +1606,8 @@ def changeit(buf, pp):
15901606
# \e --> \
15911607
ch.data = '\\'
15921608
ch.chtype = chunk_type(PLAIN)
1593-
elif s(buf, ch.data) == 'lineiii':
1609+
elif (s(buf, ch.data) == 'lineiii') or\
1610+
(s(buf, ch.data) == 'lineii'):
15941611
# This is the most tricky one
15951612
# \lineiii{a1}{a2}[{a3}] -->
15961613
# @item @<cts. of itemargmacro>{a1}
@@ -1603,10 +1620,11 @@ def changeit(buf, pp):
16031620
if not hist.inenv:
16041621
raise error, \
16051622
'no environment for lineiii'
1606-
if hist.inenv[0] != 'tableiii':
1623+
if (hist.inenv[0] != 'tableiii') and\
1624+
(hist.inenv[0] != 'tableii'):
16071625
raise error, \
16081626
'wrong command (' + \
1609-
`'lineiii'` + \
1627+
s(buf, ch.data)+ \
16101628
') in wrong environment (' \
16111629
+ `hist.inenv[0]` + ')'
16121630
ch.chtype = chunk_type(CSLINE)

Doc/tools/partparse.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def getnextarg(length, buf, pp, item):
788788
item = item+1
789789
return length, item
790790
else:
791+
ch = pp[item]
791792
try:
792793
str = `s(buf, ch.data)`
793794
except TypeError:
@@ -852,9 +853,9 @@ def init(self):
852853
return self
853854
def write(self, data):
854855
self.data = self.data + data
855-
856+
856857
# ignore these commands
857-
ignoredcommands = ('bcode', 'ecode', 'optional')
858+
ignoredcommands = ('bcode', 'ecode')
858859
# map commands like these to themselves as plaintext
859860
wordsselves = ('UNIX', 'ABC', 'C', 'ASCII', 'EOF')
860861
# \{ --> {, \} --> }, etc
@@ -1080,7 +1081,7 @@ def do_funcdesc(length, buf, pp, i):
10801081
idxsi = hist.indexsubitem # words
10811082
command = ''
10821083
cat_class = ''
1083-
if idxsi and idxsi[-1] in ('method', 'attribute'):
1084+
if idxsi and idxsi[-1] in ('method', 'protocol'):
10841085
command = 'defmethod'
10851086
cat_class = string.join(idxsi[:-1])
10861087
elif len(idxsi) == 2 and idxsi[1] == 'function':
@@ -1170,9 +1171,9 @@ def do_datadesc(length, buf, pp, i):
11701171
command = ''
11711172
cat_class = ''
11721173
class_class = ''
1173-
if idxsi[-1] == 'attribute':
1174+
if idxsi[-1] in ('attribute', 'option'):
11741175
command = 'defcv'
1175-
cat_class = 'attribute'
1176+
cat_class = idxsi[-1]
11761177
class_class = string.join(idxsi[:-1])
11771178
elif len(idxsi) == 3 and idxsi[:2] == ['in', 'module']:
11781179
command = 'defcv'
@@ -1332,7 +1333,12 @@ def changeit(buf, pp):
13321333
chunk(GROUP, ch.where, ingroupch)]
13331334
length, i = length+2, i+2
13341335

1335-
elif envname == 'tableiii':
1336+
elif (envname == 'tableiii') or \
1337+
(envname == 'tableii'):
1338+
if (envname == 'tableii'):
1339+
ltable = 2
1340+
else:
1341+
ltable = 3
13361342
wh = ch.where
13371343
newcode = []
13381344

@@ -1359,7 +1365,8 @@ def changeit(buf, pp):
13591365
del pp[i:newi]
13601366
length = length - (newi-i)
13611367

1362-
for count in range(3):
1368+
itembody = []
1369+
for count in range(ltable):
13631370
length, newi = getnextarg(length, buf, pp, i)
13641371
emphgroup = [\
13651372
chunk(CSNAME, wh, 'emph'), \
@@ -1368,7 +1375,7 @@ def changeit(buf, pp):
13681375
length = length - (newi-i)
13691376
if count == 0:
13701377
itemarg = emphgroup
1371-
elif count == 2:
1378+
elif count == ltable-1:
13721379
itembody = itembody + \
13731380
[chunk(PLAIN, wh, ' --- ')] + \
13741381
emphgroup
@@ -1437,7 +1444,7 @@ def changeit(buf, pp):
14371444
chunk(GROUP, ch.where, [\
14381445
chunk(PLAIN, ch.where, 'table')])]
14391446
i, length = i+2, length+2
1440-
elif envname == 'tableiii':
1447+
elif (envname == 'tableiii') or (envname == 'tableii'):
14411448
pp[i:i] = [\
14421449
chunk(CSLINE, ch.where, 'end'), \
14431450
chunk(GROUP, ch.where, [\
@@ -1457,7 +1464,16 @@ def changeit(buf, pp):
14571464

14581465
elif ch.chtype == chunk_type(CSNAME):
14591466
# control name transformations
1460-
if s(buf, ch.data) in ignoredcommands:
1467+
if s(buf, ch.data) == 'optional':
1468+
pp[i-1].chtype = chunk_type (PLAIN)
1469+
pp[i-1].data = '['
1470+
if (i < length) and \
1471+
(pp[i].chtype == chunk_type(GROUP)):
1472+
cp=pp[i].data
1473+
pp[i:i+1]=cp + [\
1474+
chunk(PLAIN, ch.where, ']')]
1475+
length = length+len(cp)
1476+
elif s(buf, ch.data) in ignoredcommands:
14611477
del pp[i-1]
14621478
i, length = i-1, length-1
14631479
elif s(buf, ch.data) == '@' and \
@@ -1503,7 +1519,7 @@ def changeit(buf, pp):
15031519
length = length - (newi-i)
15041520
length, newi = getnextarg(length, buf, pp, i)
15051521
text = flattext(buf, pp[i:newi])
1506-
if text[0] != '(' or text[-1] != ')':
1522+
if text[:1] != '(' or text[-1:] != ')':
15071523
raise error, 'expected indexsubitme enclosed in braces'
15081524
words = string.split(text[1:-1])
15091525
hist.indexsubitem = words
@@ -1527,7 +1543,7 @@ def changeit(buf, pp):
15271543

15281544
cat_class = ''
15291545
if len(idxsi) >= 2 and idxsi[1] in \
1530-
('method', 'function'):
1546+
('method', 'function', 'protocol'):
15311547
command = 'findex'
15321548
elif len(idxsi) >= 2 and idxsi[1] in \
15331549
('exception', 'object'):
@@ -1590,7 +1606,8 @@ def changeit(buf, pp):
15901606
# \e --> \
15911607
ch.data = '\\'
15921608
ch.chtype = chunk_type(PLAIN)
1593-
elif s(buf, ch.data) == 'lineiii':
1609+
elif (s(buf, ch.data) == 'lineiii') or\
1610+
(s(buf, ch.data) == 'lineii'):
15941611
# This is the most tricky one
15951612
# \lineiii{a1}{a2}[{a3}] -->
15961613
# @item @<cts. of itemargmacro>{a1}
@@ -1603,10 +1620,11 @@ def changeit(buf, pp):
16031620
if not hist.inenv:
16041621
raise error, \
16051622
'no environment for lineiii'
1606-
if hist.inenv[0] != 'tableiii':
1623+
if (hist.inenv[0] != 'tableiii') and\
1624+
(hist.inenv[0] != 'tableii'):
16071625
raise error, \
16081626
'wrong command (' + \
1609-
`'lineiii'` + \
1627+
s(buf, ch.data)+ \
16101628
') in wrong environment (' \
16111629
+ `hist.inenv[0]` + ')'
16121630
ch.chtype = chunk_type(CSLINE)

0 commit comments

Comments
 (0)