Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
51db3d64
Commit
51db3d64
authored
Sep 10, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformatted with 4 spaces indent.
Got rid of most redundant \ continuation signs.
parent
a83a4559
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3398 additions
and
3426 deletions
+3398
-3426
Doc/partparse.py
Doc/partparse.py
+1699
-1713
Doc/tools/partparse.py
Doc/tools/partparse.py
+1699
-1713
No files found.
Doc/partparse.py
View file @
51db3d64
...
...
@@ -27,8 +27,8 @@ MODE_MATH = 4
MODE_DMATH
=
5
MODE_GOBBLEWHITE
=
6
the_modes
=
MODE_REGULAR
,
MODE_VERBATIM
,
MODE_CS_SCAN
,
MODE_COMMENT
,
\
MODE_MATH
,
MODE_DMATH
,
MODE_GOBBLEWHITE
the_modes
=
(
MODE_REGULAR
,
MODE_VERBATIM
,
MODE_CS_SCAN
,
MODE_COMMENT
,
MODE_MATH
,
MODE_DMATH
,
MODE_GOBBLEWHITE
)
# Show the neighbourhood of the scanned buffer
def
epsilon
(
buf
,
where
):
...
...
@@ -113,8 +113,8 @@ IGNORE = 13 # IGNORE this data
ENDENV
=
14
# TEMP END OF GROUP INDICATOR
IF
=
15
# IF-directive
# data = (flag,negate,[ch, ch, ch,...])
the_types
=
PLAIN
,
GROUP
,
CSNAME
,
COMMENT
,
DMATH
,
MATH
,
OTHER
,
ACTIVE
,
\
GOBBLEDWHITE
,
ENDLINE
,
DENDLINE
,
ENV
,
CSLINE
,
IGNORE
,
ENDENV
,
IF
the_types
=
(
PLAIN
,
GROUP
,
CSNAME
,
COMMENT
,
DMATH
,
MATH
,
OTHER
,
ACTIVE
,
GOBBLEDWHITE
,
ENDLINE
,
DENDLINE
,
ENV
,
CSLINE
,
IGNORE
,
ENDENV
,
IF
)
# class, just to display symbolic name
class
ChunkType
:
...
...
@@ -182,7 +182,7 @@ class Chunk:
chtype
=
chunk_type
(
chtype
)
self
.
chtype
=
chtype
if
type
(
where
)
!=
IntType
:
raise
TypeError
,
'
\
'
where
\
'
is not a number'
raise
TypeError
,
"'where' is not a number"
self
.
where
=
where
self
.
data
=
data
...
...
@@ -216,23 +216,23 @@ CC_COMMENT = 14
CC_INVALID
=
15
# and the names
cc_names
=
[
\
'CC_ESCAPE'
,
\
'CC_LBRACE'
,
\
'CC_RBRACE'
,
\
'CC_MATHSHIFT'
,
\
'CC_ALIGNMENT'
,
\
'CC_ENDLINE'
,
\
'CC_PARAMETER'
,
\
'CC_SUPERSCRIPT'
,
\
'CC_SUBSCRIPT'
,
\
'CC_IGNORE'
,
\
'CC_WHITE'
,
\
'CC_LETTER'
,
\
'CC_OTHER'
,
\
'CC_ACTIVE'
,
\
'CC_COMMENT'
,
\
'CC_INVALID'
,
\
cc_names
=
[
'CC_ESCAPE'
,
'CC_LBRACE'
,
'CC_RBRACE'
,
'CC_MATHSHIFT'
,
'CC_ALIGNMENT'
,
'CC_ENDLINE'
,
'CC_PARAMETER'
,
'CC_SUPERSCRIPT'
,
'CC_SUBSCRIPT'
,
'CC_IGNORE'
,
'CC_WHITE'
,
'CC_LETTER'
,
'CC_OTHER'
,
'CC_ACTIVE'
,
'CC_COMMENT'
,
'CC_INVALID'
,
]
# Show a list of catcode-name-symbols
...
...
@@ -248,8 +248,8 @@ def pc(code):
# Which catcodes make the parser stop parsing regular plaintext
regular_stopcodes
=
[
CC_ESCAPE
,
CC_LBRACE
,
CC_RBRACE
,
CC_MATHSHIFT
,
\
CC_ALIGNMENT
,
CC_PARAMETER
,
CC_SUPERSCRIPT
,
CC_SUBSCRIPT
,
\
regular_stopcodes
=
[
CC_ESCAPE
,
CC_LBRACE
,
CC_RBRACE
,
CC_MATHSHIFT
,
CC_ALIGNMENT
,
CC_PARAMETER
,
CC_SUPERSCRIPT
,
CC_SUBSCRIPT
,
CC_IGNORE
,
CC_ACTIVE
,
CC_COMMENT
,
CC_INVALID
,
CC_ENDLINE
]
# same for scanning a control sequence name
...
...
@@ -460,13 +460,13 @@ def parseit(buf, *rest):
# Note that handle_cs might call this routine
# recursively again...
#
do_ret
,
newpos
=
handlecs
(
buf
,
where
,
\
do_ret
,
newpos
=
handlecs
(
buf
,
where
,
curpmode
,
lvl
,
result
,
end
)
if
do_ret
!=
None
:
return
do_ret
elif
foundchar
in
my_cc
[
CC_COMMENT
]:
newpos
,
data
=
parseit
(
buf
,
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_COMMENT
),
where
+
1
,
lvl
)
result
.
append
(
chunk
(
COMMENT
,
where
,
data
))
...
...
@@ -475,23 +475,20 @@ def parseit(buf, *rest):
# scanning are called with recursion-level 0
# again, in order to check for bad mathend
#
if
where
+
1
!=
end
and
\
buf
[
where
+
1
]
in
\
my_cc
[
CC_MATHSHIFT
]:
if
where
+
1
!=
end
and
buf
[
where
+
1
]
in
my_cc
[
CC_MATHSHIFT
]:
#
# double mathshift, e.g. '$$'
#
if
curpmode
==
mode
(
MODE_REGULAR
):
newpos
,
data
=
parseit
(
buf
,
\
mode
(
MODE_DMATH
),
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_DMATH
),
where
+
2
,
0
)
result
.
append
(
chunk
(
DMATH
,
\
result
.
append
(
chunk
(
DMATH
,
where
,
data
))
elif
curpmode
==
mode
(
MODE_MATH
):
raise
error
,
'wrong math delimiiter'
+
lin
()
+
epsilon
(
buf
,
where
)
elif
lvl
!=
1
:
raise
error
,
'bad mathend.'
+
\
lle
(
lvl
,
buf
,
where
)
raise
error
,
'bad mathend.'
+
lle
(
lvl
,
buf
,
where
)
else
:
return
where
+
2
,
result
else
:
...
...
@@ -499,16 +496,15 @@ def parseit(buf, *rest):
# single math shift, e.g. '$'
#
if
curpmode
==
mode
(
MODE_REGULAR
):
newpos
,
data
=
parseit
(
buf
,
\
mode
(
MODE_MATH
),
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_MATH
),
where
+
1
,
0
)
result
.
append
(
chunk
(
MATH
,
\
result
.
append
(
chunk
(
MATH
,
where
,
data
))
elif
curpmode
==
mode
(
MODE_DMATH
):
raise
error
,
'wrong math delimiiter'
+
lin
()
+
epsilon
(
buf
,
where
)
elif
lvl
!=
1
:
raise
error
,
'bad mathend.'
+
\
lv
(
lvl
,
buf
,
where
)
raise
error
,
'bad mathend.'
+
lv
(
lvl
,
buf
,
where
)
else
:
return
where
+
1
,
result
...
...
@@ -535,13 +531,10 @@ def parseit(buf, *rest):
lineno
=
lineno
+
1
savedwhere
=
where
newpos
,
dummy
=
parseit
(
buf
,
mode
(
MODE_GOBBLEWHITE
),
where
+
1
,
lvl
)
if
newpos
!=
end
and
buf
[
newpos
]
in
\
my_cc
[
CC_ENDLINE
]:
result
.
append
(
chunk
(
DENDLINE
,
\
savedwhere
,
foundchar
))
if
newpos
!=
end
and
buf
[
newpos
]
in
my_cc
[
CC_ENDLINE
]:
result
.
append
(
chunk
(
DENDLINE
,
savedwhere
,
foundchar
))
else
:
result
.
append
(
chunk
(
ENDLINE
,
\
savedwhere
,
foundchar
))
result
.
append
(
chunk
(
ENDLINE
,
savedwhere
,
foundchar
))
else
:
result
.
append
(
chunk
(
OTHER
,
where
,
foundchar
))
newpos
=
where
+
1
...
...
@@ -568,8 +561,7 @@ def parseit(buf, *rest):
if
buf
[
pos
]
==
'
\
n
'
:
lineno
=
lineno
+
1
spos
=
pos
+
1
pos2
,
dummy
=
parseit
(
buf
,
\
mode
(
MODE_GOBBLEWHITE
),
spos
,
lvl
)
pos2
,
dummy
=
parseit
(
buf
,
mode
(
MODE_GOBBLEWHITE
),
spos
,
lvl
)
return
pos2
,
(
start
,
pos
)
elif
parsemode
==
mode
(
MODE_GOBBLEWHITE
):
...
...
@@ -855,7 +847,7 @@ themselves = ('{', '}', '.', '@', ' ', '\n') + wordsselves
inargsselves
=
(
','
,
'['
,
']'
,
'('
,
')'
)
# this is how *I* would show the difference between emph and strong
# code 1 means: fold to uppercase
markcmds
=
{
'code'
:
(
''
,
''
),
'var'
:
1
,
'emph'
:
(
'_'
,
'_'
),
\
markcmds
=
{
'code'
:
(
''
,
''
),
'var'
:
1
,
'emph'
:
(
'_'
,
'_'
),
'strong'
:
(
'*'
,
'*'
)}
# recognise patter {\FONTCHANGE-CMD TEXT} to \MAPPED-FC-CMD{TEXT}
...
...
@@ -1063,8 +1055,7 @@ def do_funcdesc(length, buf, pp, i):
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
hist
.
inargs
=
save
del
save
the_args
=
[
chunk
(
PLAIN
,
wh
,
'()'
[
0
])]
+
\
pp
[
i
:
newi
]
+
\
the_args
=
[
chunk
(
PLAIN
,
wh
,
'()'
[
0
])]
+
pp
[
i
:
newi
]
+
\
[
chunk
(
PLAIN
,
wh
,
'()'
[
1
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1294,38 +1285,37 @@ def changeit(buf, pp):
length
=
length
+
len
(
data
)
if
envname
==
'verbatim'
:
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'example'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'example'
),
chunk
(
GROUP
,
ch
.
where
,
[])]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'itemize'
:
if
hist
.
itemizenesting
>
len
(
itemizesymbols
):
raise
error
,
'too deep itemize nesting'
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
\
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
itemizesymbols
[
hist
.
itemizenesting
])]
hist
.
itemizenesting
=
hist
.
itemizenesting
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'itemize'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'itemize'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'enumerate'
:
if
hist
.
enumeratenesting
>
len
(
enumeratesymbols
):
raise
error
,
'too deep enumerate nesting'
ingroupch
=
[
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
=
[
chunk
(
PLAIN
,
ch
.
where
,
enumeratesymbols
[
hist
.
enumeratenesting
])]
hist
.
enumeratenesting
=
hist
.
enumeratenesting
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'enumerate'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'enumerate'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'description'
:
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
'b'
)]
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'table'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'table'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
(
envname
==
'tableiii'
)
or
\
(
envname
==
'tableii'
):
elif
(
envname
==
'tableiii'
)
or
(
envname
==
'tableii'
):
if
(
envname
==
'tableii'
):
ltable
=
2
else
:
...
...
@@ -1359,8 +1349,8 @@ def changeit(buf, pp):
itembody
=
[]
for
count
in
range
(
ltable
):
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
emphgroup
=
[
\
chunk
(
CSNAME
,
wh
,
'emph'
),
\
emphgroup
=
[
chunk
(
CSNAME
,
wh
,
'emph'
),
chunk
(
GROUP
,
0
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1368,8 +1358,7 @@ def changeit(buf, pp):
itemarg
=
emphgroup
elif
count
==
ltable
-
1
:
itembody
=
itembody
+
\
[
chunk
(
PLAIN
,
wh
,
' --- '
)]
+
\
emphgroup
[
chunk
(
PLAIN
,
wh
,
' --- '
)]
+
emphgroup
else
:
itembody
=
emphgroup
newcode
.
append
(
chunk
(
GROUP
,
wh
,
itemarg
))
...
...
@@ -1410,44 +1399,44 @@ def changeit(buf, pp):
i
,
length
=
i
-
1
,
length
-
1
if
envname
==
'verbatim'
:
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'example'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'itemize'
:
hist
.
itemizenesting
=
hist
.
itemizenesting
-
1
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'itemize'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'enumerate'
:
hist
.
enumeratenesting
=
hist
.
enumeratenesting
-
1
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'enumerate'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'description'
:
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'table'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
(
envname
==
'tableiii'
)
or
(
envname
==
'tableii'
):
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'table'
)])]
i
,
length
=
i
+
2
,
length
+
2
pp
.
insert
(
i
,
chunk
(
DENDLINE
,
ch
.
where
,
'
\
n
'
))
i
,
length
=
i
+
1
,
length
+
1
elif
envname
in
(
'funcdesc'
,
'excdesc'
,
'datadesc'
):
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
else
:
...
...
@@ -1461,7 +1450,7 @@ def changeit(buf, pp):
if
(
i
<
length
)
and
\
(
pp
[
i
].
chtype
==
chunk_type
(
GROUP
)):
cp
=
pp
[
i
].
data
pp
[
i
:
i
+
1
]
=
cp
+
[
\
pp
[
i
:
i
+
1
]
=
cp
+
[
chunk
(
PLAIN
,
ch
.
where
,
']'
)]
length
=
length
+
len
(
cp
)
elif
s
(
buf
,
ch
.
data
)
in
ignoredcommands
:
...
...
@@ -1560,10 +1549,10 @@ def changeit(buf, pp):
# what in tt-font
if
command
in
regindices
:
arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
't'
),
\
arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
't'
),
chunk
(
GROUP
,
ch
.
where
,
arg
)]
else
:
cat_arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
'r'
),
\
cat_arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
'r'
),
chunk
(
GROUP
,
ch
.
where
,
cat_arg
)]
ingroupch
=
arg
+
\
...
...
@@ -1609,9 +1598,8 @@ def changeit(buf, pp):
## dumpit(buf, wobj.write, pp[i-1:i+5])
## print '--->' + wobj.data + '<----'
if
not
hist
.
inenv
:
raise
error
,
\
'no environment for lineiii'
if
(
hist
.
inenv
[
0
]
!=
'tableiii'
)
and
\
raise
error
,
'no environment for lineiii'
if
(
hist
.
inenv
[
0
]
!=
'tableiii'
)
and
\
(
hist
.
inenv
[
0
]
!=
'tableii'
):
raise
error
,
\
'wrong command ('
+
\
...
...
@@ -1621,8 +1609,8 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'item'
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
ingroupch
=
[
chunk
(
CSNAME
,
0
,
\
hist
.
itemargmacro
),
\
ingroupch
=
[
chunk
(
CSNAME
,
0
,
hist
.
itemargmacro
),
chunk
(
GROUP
,
0
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1658,11 +1646,10 @@ def changeit(buf, pp):
afternodenamecmd
=
next_command_p
(
length
,
buf
,
pp
,
newi
,
'nodename'
)
if
afternodenamecmd
<
0
:
cp1
=
crcopy
(
pp
[
i
:
newi
])
pp
[
i
:
newi
]
=
[
\
chunk
(
GROUP
,
ch
.
where
,
\
pp
[
i
:
newi
]
=
[
chunk
(
GROUP
,
ch
.
where
,
pp
[
i
:
newi
])]
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
\
i
+
1
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
i
+
1
text
=
flattext
(
buf
,
cp1
)
text
=
invent_node_names
(
text
)
else
:
...
...
@@ -1671,11 +1658,10 @@ def changeit(buf, pp):
del
pp
[
newi
:
endarg
]
length
=
length
-
(
endarg
-
newi
)
pp
[
i
:
newi
]
=
[
\
chunk
(
GROUP
,
ch
.
where
,
\
pp
[
i
:
newi
]
=
[
chunk
(
GROUP
,
ch
.
where
,
pp
[
i
:
newi
])]
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
\
i
+
1
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
i
+
1
text
=
flattext
(
buf
,
cp1
)
if
text
[
-
1
]
==
'.'
:
text
=
text
[:
-
1
]
...
...
@@ -1686,34 +1672,34 @@ def changeit(buf, pp):
else
:
hist
.
nodenames
.
append
(
text
)
text
=
rm_commas_etc
(
text
)
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'node'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
text
+
', , ,'
)
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'node'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
text
+
', , ,'
)
])]
i
,
length
=
newi
+
2
,
length
+
2
elif
s
(
buf
,
ch
.
data
)
==
'funcline'
:
# fold it to a very short environment
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_funcdesc
(
length
,
buf
,
pp
,
i
)
elif
s
(
buf
,
ch
.
data
)
==
'dataline'
:
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_datadesc
(
length
,
buf
,
pp
,
i
)
elif
s
(
buf
,
ch
.
data
)
==
'excline'
:
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_excdesc
(
length
,
buf
,
pp
,
i
)
...
...
@@ -1742,8 +1728,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(built-in function)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1760,8 +1746,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(object)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1778,8 +1764,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(operator)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1796,8 +1782,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(built-in)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1818,8 +1804,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(standard)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1832,7 +1818,7 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
ingroupch
=
[
chunk
(
CSNAME
,
wh
,
'code'
),
\
ingroupch
=
[
chunk
(
CSNAME
,
wh
,
'code'
),
chunk
(
GROUP
,
wh
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
...
...
@@ -1871,11 +1857,11 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
\
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
))
i
,
length
=
i
+
1
,
length
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp21
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -1901,21 +1887,21 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
\
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp13
))
i
,
length
=
i
+
1
,
length
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp23
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp23
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp21
)]
i
,
length
=
i
+
2
,
length
+
2
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp33
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp31
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp33
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp31
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp32
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -1962,21 +1948,21 @@ def changeit(buf, pp):
spacech
+
cp23
+
\
spacech
+
cp24
+
\
commach
+
cp21
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
ingroupch
=
cp33
+
\
spacech
+
cp34
+
\
commach
+
cp31
+
\
spacech
+
cp32
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
ingroupch
=
cp44
+
\
commach
+
cp41
+
\
spacech
+
cp42
+
\
spacech
+
cp43
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -2050,7 +2036,7 @@ def dumpit(buf, wm, pp):
elif
ch
.
chtype
==
chunk_type
(
CSLINE
):
if
i
>=
2
and
pp
[
i
-
2
].
chtype
not
in
\
(
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
(
pp
[
i
-
2
].
chtype
!=
chunk_type
(
PLAIN
)
\
and
(
pp
[
i
-
2
].
chtype
!=
chunk_type
(
PLAIN
)
or
s
(
buf
,
pp
[
i
-
2
].
data
)[
-
1
]
!=
'
\
n
'
):
wm
(
'
\
n
'
)
...
...
@@ -2078,9 +2064,9 @@ def dumpit(buf, wm, pp):
text
=
text
[
pos
+
1
:]
wm
(
text
)
if
i
>=
length
or
\
pp
[
i
].
chtype
not
in
(
chunk_type
(
CSLINE
),
\
pp
[
i
].
chtype
not
in
(
chunk_type
(
CSLINE
),
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
(
pp
[
i
].
chtype
!=
chunk_type
(
PLAIN
)
\
and
(
pp
[
i
].
chtype
!=
chunk_type
(
PLAIN
)
or
s
(
buf
,
pp
[
i
].
data
)[
0
]
!=
'
\
n
'
):
wm
(
'
\
n
'
)
...
...
@@ -2092,7 +2078,7 @@ def dumpit(buf, wm, pp):
regex
.
match
(
'^[
\
t
]*$'
,
s
(
buf
,
ch
.
data
))
<
0
:
if
i
>=
2
and
pp
[
i
-
2
].
chtype
not
in
\
(
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
not
(
pp
[
i
-
2
].
chtype
==
chunk_type
(
PLAIN
)
\
and
not
(
pp
[
i
-
2
].
chtype
==
chunk_type
(
PLAIN
)
and
regex
.
match
(
'
\
\
(.
\
\
|
\
n
\
\
)*[
\
t
]*
\
n
$'
,
s
(
buf
,
pp
[
i
-
2
].
data
))
>=
0
):
print
'ADDING NEWLINE'
wm
(
'
\
n
'
)
...
...
Doc/tools/partparse.py
View file @
51db3d64
...
...
@@ -27,8 +27,8 @@ MODE_MATH = 4
MODE_DMATH
=
5
MODE_GOBBLEWHITE
=
6
the_modes
=
MODE_REGULAR
,
MODE_VERBATIM
,
MODE_CS_SCAN
,
MODE_COMMENT
,
\
MODE_MATH
,
MODE_DMATH
,
MODE_GOBBLEWHITE
the_modes
=
(
MODE_REGULAR
,
MODE_VERBATIM
,
MODE_CS_SCAN
,
MODE_COMMENT
,
MODE_MATH
,
MODE_DMATH
,
MODE_GOBBLEWHITE
)
# Show the neighbourhood of the scanned buffer
def
epsilon
(
buf
,
where
):
...
...
@@ -113,8 +113,8 @@ IGNORE = 13 # IGNORE this data
ENDENV
=
14
# TEMP END OF GROUP INDICATOR
IF
=
15
# IF-directive
# data = (flag,negate,[ch, ch, ch,...])
the_types
=
PLAIN
,
GROUP
,
CSNAME
,
COMMENT
,
DMATH
,
MATH
,
OTHER
,
ACTIVE
,
\
GOBBLEDWHITE
,
ENDLINE
,
DENDLINE
,
ENV
,
CSLINE
,
IGNORE
,
ENDENV
,
IF
the_types
=
(
PLAIN
,
GROUP
,
CSNAME
,
COMMENT
,
DMATH
,
MATH
,
OTHER
,
ACTIVE
,
GOBBLEDWHITE
,
ENDLINE
,
DENDLINE
,
ENV
,
CSLINE
,
IGNORE
,
ENDENV
,
IF
)
# class, just to display symbolic name
class
ChunkType
:
...
...
@@ -182,7 +182,7 @@ class Chunk:
chtype
=
chunk_type
(
chtype
)
self
.
chtype
=
chtype
if
type
(
where
)
!=
IntType
:
raise
TypeError
,
'
\
'
where
\
'
is not a number'
raise
TypeError
,
"'where' is not a number"
self
.
where
=
where
self
.
data
=
data
...
...
@@ -216,23 +216,23 @@ CC_COMMENT = 14
CC_INVALID
=
15
# and the names
cc_names
=
[
\
'CC_ESCAPE'
,
\
'CC_LBRACE'
,
\
'CC_RBRACE'
,
\
'CC_MATHSHIFT'
,
\
'CC_ALIGNMENT'
,
\
'CC_ENDLINE'
,
\
'CC_PARAMETER'
,
\
'CC_SUPERSCRIPT'
,
\
'CC_SUBSCRIPT'
,
\
'CC_IGNORE'
,
\
'CC_WHITE'
,
\
'CC_LETTER'
,
\
'CC_OTHER'
,
\
'CC_ACTIVE'
,
\
'CC_COMMENT'
,
\
'CC_INVALID'
,
\
cc_names
=
[
'CC_ESCAPE'
,
'CC_LBRACE'
,
'CC_RBRACE'
,
'CC_MATHSHIFT'
,
'CC_ALIGNMENT'
,
'CC_ENDLINE'
,
'CC_PARAMETER'
,
'CC_SUPERSCRIPT'
,
'CC_SUBSCRIPT'
,
'CC_IGNORE'
,
'CC_WHITE'
,
'CC_LETTER'
,
'CC_OTHER'
,
'CC_ACTIVE'
,
'CC_COMMENT'
,
'CC_INVALID'
,
]
# Show a list of catcode-name-symbols
...
...
@@ -248,8 +248,8 @@ def pc(code):
# Which catcodes make the parser stop parsing regular plaintext
regular_stopcodes
=
[
CC_ESCAPE
,
CC_LBRACE
,
CC_RBRACE
,
CC_MATHSHIFT
,
\
CC_ALIGNMENT
,
CC_PARAMETER
,
CC_SUPERSCRIPT
,
CC_SUBSCRIPT
,
\
regular_stopcodes
=
[
CC_ESCAPE
,
CC_LBRACE
,
CC_RBRACE
,
CC_MATHSHIFT
,
CC_ALIGNMENT
,
CC_PARAMETER
,
CC_SUPERSCRIPT
,
CC_SUBSCRIPT
,
CC_IGNORE
,
CC_ACTIVE
,
CC_COMMENT
,
CC_INVALID
,
CC_ENDLINE
]
# same for scanning a control sequence name
...
...
@@ -460,13 +460,13 @@ def parseit(buf, *rest):
# Note that handle_cs might call this routine
# recursively again...
#
do_ret
,
newpos
=
handlecs
(
buf
,
where
,
\
do_ret
,
newpos
=
handlecs
(
buf
,
where
,
curpmode
,
lvl
,
result
,
end
)
if
do_ret
!=
None
:
return
do_ret
elif
foundchar
in
my_cc
[
CC_COMMENT
]:
newpos
,
data
=
parseit
(
buf
,
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_COMMENT
),
where
+
1
,
lvl
)
result
.
append
(
chunk
(
COMMENT
,
where
,
data
))
...
...
@@ -475,23 +475,20 @@ def parseit(buf, *rest):
# scanning are called with recursion-level 0
# again, in order to check for bad mathend
#
if
where
+
1
!=
end
and
\
buf
[
where
+
1
]
in
\
my_cc
[
CC_MATHSHIFT
]:
if
where
+
1
!=
end
and
buf
[
where
+
1
]
in
my_cc
[
CC_MATHSHIFT
]:
#
# double mathshift, e.g. '$$'
#
if
curpmode
==
mode
(
MODE_REGULAR
):
newpos
,
data
=
parseit
(
buf
,
\
mode
(
MODE_DMATH
),
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_DMATH
),
where
+
2
,
0
)
result
.
append
(
chunk
(
DMATH
,
\
result
.
append
(
chunk
(
DMATH
,
where
,
data
))
elif
curpmode
==
mode
(
MODE_MATH
):
raise
error
,
'wrong math delimiiter'
+
lin
()
+
epsilon
(
buf
,
where
)
elif
lvl
!=
1
:
raise
error
,
'bad mathend.'
+
\
lle
(
lvl
,
buf
,
where
)
raise
error
,
'bad mathend.'
+
lle
(
lvl
,
buf
,
where
)
else
:
return
where
+
2
,
result
else
:
...
...
@@ -499,16 +496,15 @@ def parseit(buf, *rest):
# single math shift, e.g. '$'
#
if
curpmode
==
mode
(
MODE_REGULAR
):
newpos
,
data
=
parseit
(
buf
,
\
mode
(
MODE_MATH
),
\
newpos
,
data
=
parseit
(
buf
,
mode
(
MODE_MATH
),
where
+
1
,
0
)
result
.
append
(
chunk
(
MATH
,
\
result
.
append
(
chunk
(
MATH
,
where
,
data
))
elif
curpmode
==
mode
(
MODE_DMATH
):
raise
error
,
'wrong math delimiiter'
+
lin
()
+
epsilon
(
buf
,
where
)
elif
lvl
!=
1
:
raise
error
,
'bad mathend.'
+
\
lv
(
lvl
,
buf
,
where
)
raise
error
,
'bad mathend.'
+
lv
(
lvl
,
buf
,
where
)
else
:
return
where
+
1
,
result
...
...
@@ -535,13 +531,10 @@ def parseit(buf, *rest):
lineno
=
lineno
+
1
savedwhere
=
where
newpos
,
dummy
=
parseit
(
buf
,
mode
(
MODE_GOBBLEWHITE
),
where
+
1
,
lvl
)
if
newpos
!=
end
and
buf
[
newpos
]
in
\
my_cc
[
CC_ENDLINE
]:
result
.
append
(
chunk
(
DENDLINE
,
\
savedwhere
,
foundchar
))
if
newpos
!=
end
and
buf
[
newpos
]
in
my_cc
[
CC_ENDLINE
]:
result
.
append
(
chunk
(
DENDLINE
,
savedwhere
,
foundchar
))
else
:
result
.
append
(
chunk
(
ENDLINE
,
\
savedwhere
,
foundchar
))
result
.
append
(
chunk
(
ENDLINE
,
savedwhere
,
foundchar
))
else
:
result
.
append
(
chunk
(
OTHER
,
where
,
foundchar
))
newpos
=
where
+
1
...
...
@@ -568,8 +561,7 @@ def parseit(buf, *rest):
if
buf
[
pos
]
==
'
\
n
'
:
lineno
=
lineno
+
1
spos
=
pos
+
1
pos2
,
dummy
=
parseit
(
buf
,
\
mode
(
MODE_GOBBLEWHITE
),
spos
,
lvl
)
pos2
,
dummy
=
parseit
(
buf
,
mode
(
MODE_GOBBLEWHITE
),
spos
,
lvl
)
return
pos2
,
(
start
,
pos
)
elif
parsemode
==
mode
(
MODE_GOBBLEWHITE
):
...
...
@@ -855,7 +847,7 @@ themselves = ('{', '}', '.', '@', ' ', '\n') + wordsselves
inargsselves
=
(
','
,
'['
,
']'
,
'('
,
')'
)
# this is how *I* would show the difference between emph and strong
# code 1 means: fold to uppercase
markcmds
=
{
'code'
:
(
''
,
''
),
'var'
:
1
,
'emph'
:
(
'_'
,
'_'
),
\
markcmds
=
{
'code'
:
(
''
,
''
),
'var'
:
1
,
'emph'
:
(
'_'
,
'_'
),
'strong'
:
(
'*'
,
'*'
)}
# recognise patter {\FONTCHANGE-CMD TEXT} to \MAPPED-FC-CMD{TEXT}
...
...
@@ -1063,8 +1055,7 @@ def do_funcdesc(length, buf, pp, i):
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
hist
.
inargs
=
save
del
save
the_args
=
[
chunk
(
PLAIN
,
wh
,
'()'
[
0
])]
+
\
pp
[
i
:
newi
]
+
\
the_args
=
[
chunk
(
PLAIN
,
wh
,
'()'
[
0
])]
+
pp
[
i
:
newi
]
+
\
[
chunk
(
PLAIN
,
wh
,
'()'
[
1
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1294,38 +1285,37 @@ def changeit(buf, pp):
length
=
length
+
len
(
data
)
if
envname
==
'verbatim'
:
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'example'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'example'
),
chunk
(
GROUP
,
ch
.
where
,
[])]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'itemize'
:
if
hist
.
itemizenesting
>
len
(
itemizesymbols
):
raise
error
,
'too deep itemize nesting'
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
\
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
itemizesymbols
[
hist
.
itemizenesting
])]
hist
.
itemizenesting
=
hist
.
itemizenesting
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'itemize'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'itemize'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'enumerate'
:
if
hist
.
enumeratenesting
>
len
(
enumeratesymbols
):
raise
error
,
'too deep enumerate nesting'
ingroupch
=
[
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
=
[
chunk
(
PLAIN
,
ch
.
where
,
enumeratesymbols
[
hist
.
enumeratenesting
])]
hist
.
enumeratenesting
=
hist
.
enumeratenesting
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'enumerate'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'enumerate'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
envname
==
'description'
:
ingroupch
=
[
chunk
(
CSNAME
,
ch
.
where
,
'b'
)]
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'table'
),
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'table'
),
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
length
,
i
=
length
+
2
,
i
+
2
elif
(
envname
==
'tableiii'
)
or
\
(
envname
==
'tableii'
):
elif
(
envname
==
'tableiii'
)
or
(
envname
==
'tableii'
):
if
(
envname
==
'tableii'
):
ltable
=
2
else
:
...
...
@@ -1359,8 +1349,8 @@ def changeit(buf, pp):
itembody
=
[]
for
count
in
range
(
ltable
):
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
emphgroup
=
[
\
chunk
(
CSNAME
,
wh
,
'emph'
),
\
emphgroup
=
[
chunk
(
CSNAME
,
wh
,
'emph'
),
chunk
(
GROUP
,
0
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1368,8 +1358,7 @@ def changeit(buf, pp):
itemarg
=
emphgroup
elif
count
==
ltable
-
1
:
itembody
=
itembody
+
\
[
chunk
(
PLAIN
,
wh
,
' --- '
)]
+
\
emphgroup
[
chunk
(
PLAIN
,
wh
,
' --- '
)]
+
emphgroup
else
:
itembody
=
emphgroup
newcode
.
append
(
chunk
(
GROUP
,
wh
,
itemarg
))
...
...
@@ -1410,44 +1399,44 @@ def changeit(buf, pp):
i
,
length
=
i
-
1
,
length
-
1
if
envname
==
'verbatim'
:
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'example'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'itemize'
:
hist
.
itemizenesting
=
hist
.
itemizenesting
-
1
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'itemize'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'enumerate'
:
hist
.
enumeratenesting
=
hist
.
enumeratenesting
-
1
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'enumerate'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
envname
==
'description'
:
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'table'
)])]
i
,
length
=
i
+
2
,
length
+
2
elif
(
envname
==
'tableiii'
)
or
(
envname
==
'tableii'
):
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'table'
)])]
i
,
length
=
i
+
2
,
length
+
2
pp
.
insert
(
i
,
chunk
(
DENDLINE
,
ch
.
where
,
'
\
n
'
))
i
,
length
=
i
+
1
,
length
+
1
elif
envname
in
(
'funcdesc'
,
'excdesc'
,
'datadesc'
):
pp
[
i
:
i
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
else
:
...
...
@@ -1461,7 +1450,7 @@ def changeit(buf, pp):
if
(
i
<
length
)
and
\
(
pp
[
i
].
chtype
==
chunk_type
(
GROUP
)):
cp
=
pp
[
i
].
data
pp
[
i
:
i
+
1
]
=
cp
+
[
\
pp
[
i
:
i
+
1
]
=
cp
+
[
chunk
(
PLAIN
,
ch
.
where
,
']'
)]
length
=
length
+
len
(
cp
)
elif
s
(
buf
,
ch
.
data
)
in
ignoredcommands
:
...
...
@@ -1560,10 +1549,10 @@ def changeit(buf, pp):
# what in tt-font
if
command
in
regindices
:
arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
't'
),
\
arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
't'
),
chunk
(
GROUP
,
ch
.
where
,
arg
)]
else
:
cat_arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
'r'
),
\
cat_arg
=
[
chunk
(
CSNAME
,
ch
.
where
,
'r'
),
chunk
(
GROUP
,
ch
.
where
,
cat_arg
)]
ingroupch
=
arg
+
\
...
...
@@ -1609,9 +1598,8 @@ def changeit(buf, pp):
## dumpit(buf, wobj.write, pp[i-1:i+5])
## print '--->' + wobj.data + '<----'
if
not
hist
.
inenv
:
raise
error
,
\
'no environment for lineiii'
if
(
hist
.
inenv
[
0
]
!=
'tableiii'
)
and
\
raise
error
,
'no environment for lineiii'
if
(
hist
.
inenv
[
0
]
!=
'tableiii'
)
and
\
(
hist
.
inenv
[
0
]
!=
'tableii'
):
raise
error
,
\
'wrong command ('
+
\
...
...
@@ -1621,8 +1609,8 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'item'
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
ingroupch
=
[
chunk
(
CSNAME
,
0
,
\
hist
.
itemargmacro
),
\
ingroupch
=
[
chunk
(
CSNAME
,
0
,
hist
.
itemargmacro
),
chunk
(
GROUP
,
0
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
length
=
length
-
(
newi
-
i
)
...
...
@@ -1658,11 +1646,10 @@ def changeit(buf, pp):
afternodenamecmd
=
next_command_p
(
length
,
buf
,
pp
,
newi
,
'nodename'
)
if
afternodenamecmd
<
0
:
cp1
=
crcopy
(
pp
[
i
:
newi
])
pp
[
i
:
newi
]
=
[
\
chunk
(
GROUP
,
ch
.
where
,
\
pp
[
i
:
newi
]
=
[
chunk
(
GROUP
,
ch
.
where
,
pp
[
i
:
newi
])]
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
\
i
+
1
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
i
+
1
text
=
flattext
(
buf
,
cp1
)
text
=
invent_node_names
(
text
)
else
:
...
...
@@ -1671,11 +1658,10 @@ def changeit(buf, pp):
del
pp
[
newi
:
endarg
]
length
=
length
-
(
endarg
-
newi
)
pp
[
i
:
newi
]
=
[
\
chunk
(
GROUP
,
ch
.
where
,
\
pp
[
i
:
newi
]
=
[
chunk
(
GROUP
,
ch
.
where
,
pp
[
i
:
newi
])]
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
\
i
+
1
length
,
newi
=
length
-
(
newi
-
i
)
+
1
,
i
+
1
text
=
flattext
(
buf
,
cp1
)
if
text
[
-
1
]
==
'.'
:
text
=
text
[:
-
1
]
...
...
@@ -1686,34 +1672,34 @@ def changeit(buf, pp):
else
:
hist
.
nodenames
.
append
(
text
)
text
=
rm_commas_etc
(
text
)
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'node'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
text
+
', , ,'
)
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'node'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
text
+
', , ,'
)
])]
i
,
length
=
newi
+
2
,
length
+
2
elif
s
(
buf
,
ch
.
data
)
==
'funcline'
:
# fold it to a very short environment
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_funcdesc
(
length
,
buf
,
pp
,
i
)
elif
s
(
buf
,
ch
.
data
)
==
'dataline'
:
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_datadesc
(
length
,
buf
,
pp
,
i
)
elif
s
(
buf
,
ch
.
data
)
==
'excline'
:
pp
[
i
-
1
:
i
-
1
]
=
[
\
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
\
chunk
(
GROUP
,
ch
.
where
,
[
\
pp
[
i
-
1
:
i
-
1
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'end'
),
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
hist
.
command
)])]
i
,
length
=
i
+
2
,
length
+
2
length
,
i
=
do_excdesc
(
length
,
buf
,
pp
,
i
)
...
...
@@ -1742,8 +1728,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(built-in function)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1760,8 +1746,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(object)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1778,8 +1764,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(operator)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1796,8 +1782,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(built-in)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1818,8 +1804,8 @@ def changeit(buf, pp):
ingroupch
.
append
(
chunk
(
PLAIN
,
ch
.
where
,
' '
))
ingroupch
.
append
(
chunk
(
CSNAME
,
ch
.
where
,
'r'
))
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
\
chunk
(
PLAIN
,
ch
.
where
,
\
ingroupch
.
append
(
chunk
(
GROUP
,
ch
.
where
,
[
chunk
(
PLAIN
,
ch
.
where
,
'(standard)'
)]))
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
ingroupch
))
...
...
@@ -1832,7 +1818,7 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
length
,
newi
=
getnextarg
(
length
,
buf
,
pp
,
i
)
ingroupch
=
[
chunk
(
CSNAME
,
wh
,
'code'
),
\
ingroupch
=
[
chunk
(
CSNAME
,
wh
,
'code'
),
chunk
(
GROUP
,
wh
,
pp
[
i
:
newi
])]
del
pp
[
i
:
newi
]
...
...
@@ -1871,11 +1857,11 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
\
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
))
i
,
length
=
i
+
1
,
length
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp21
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -1901,21 +1887,21 @@ def changeit(buf, pp):
ch
.
chtype
=
chunk_type
(
CSLINE
)
ch
.
data
=
'cindex'
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
\
pp
.
insert
(
i
,
chunk
(
GROUP
,
ch
.
where
,
cp11
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp12
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp13
))
i
,
length
=
i
+
1
,
length
+
1
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp23
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp22
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp23
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp21
)]
i
,
length
=
i
+
2
,
length
+
2
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
\
chunk
(
GROUP
,
ch
.
where
,
cp33
+
[
\
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp31
\
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
\
pp
[
i
:
i
]
=
[
chunk
(
CSLINE
,
ch
.
where
,
'cindex'
),
chunk
(
GROUP
,
ch
.
where
,
cp33
+
[
chunk
(
PLAIN
,
ch
.
where
,
', '
)]
+
cp31
+
[
chunk
(
PLAIN
,
ch
.
where
,
' '
)]
+
cp32
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -1962,21 +1948,21 @@ def changeit(buf, pp):
spacech
+
cp23
+
\
spacech
+
cp24
+
\
commach
+
cp21
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
ingroupch
=
cp33
+
\
spacech
+
cp34
+
\
commach
+
cp31
+
\
spacech
+
cp32
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
ingroupch
=
cp44
+
\
commach
+
cp41
+
\
spacech
+
cp42
+
\
spacech
+
cp43
pp
[
i
:
i
]
=
cindexch
+
[
\
pp
[
i
:
i
]
=
cindexch
+
[
chunk
(
GROUP
,
ch
.
where
,
ingroupch
)]
i
,
length
=
i
+
2
,
length
+
2
...
...
@@ -2050,7 +2036,7 @@ def dumpit(buf, wm, pp):
elif
ch
.
chtype
==
chunk_type
(
CSLINE
):
if
i
>=
2
and
pp
[
i
-
2
].
chtype
not
in
\
(
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
(
pp
[
i
-
2
].
chtype
!=
chunk_type
(
PLAIN
)
\
and
(
pp
[
i
-
2
].
chtype
!=
chunk_type
(
PLAIN
)
or
s
(
buf
,
pp
[
i
-
2
].
data
)[
-
1
]
!=
'
\
n
'
):
wm
(
'
\
n
'
)
...
...
@@ -2078,9 +2064,9 @@ def dumpit(buf, wm, pp):
text
=
text
[
pos
+
1
:]
wm
(
text
)
if
i
>=
length
or
\
pp
[
i
].
chtype
not
in
(
chunk_type
(
CSLINE
),
\
pp
[
i
].
chtype
not
in
(
chunk_type
(
CSLINE
),
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
(
pp
[
i
].
chtype
!=
chunk_type
(
PLAIN
)
\
and
(
pp
[
i
].
chtype
!=
chunk_type
(
PLAIN
)
or
s
(
buf
,
pp
[
i
].
data
)[
0
]
!=
'
\
n
'
):
wm
(
'
\
n
'
)
...
...
@@ -2092,7 +2078,7 @@ def dumpit(buf, wm, pp):
regex
.
match
(
'^[
\
t
]*$'
,
s
(
buf
,
ch
.
data
))
<
0
:
if
i
>=
2
and
pp
[
i
-
2
].
chtype
not
in
\
(
chunk_type
(
ENDLINE
),
chunk_type
(
DENDLINE
))
\
and
not
(
pp
[
i
-
2
].
chtype
==
chunk_type
(
PLAIN
)
\
and
not
(
pp
[
i
-
2
].
chtype
==
chunk_type
(
PLAIN
)
and
regex
.
match
(
'
\
\
(.
\
\
|
\
n
\
\
)*[
\
t
]*
\
n
$'
,
s
(
buf
,
pp
[
i
-
2
].
data
))
>=
0
):
print
'ADDING NEWLINE'
wm
(
'
\
n
'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment