summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-05-12 23:33:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-05-12 23:33:28 (GMT)
commit62aa994633dbf87a4e7e03c9ec13ce9fc7dfca0f (patch)
tree0a34d65280ccdf39c9a181071361c6f328608167 /Tools/scripts
parentb539d05cbe6aaf5bafe923fb77b13a6c022676e9 (diff)
downloadcpython-62aa994633dbf87a4e7e03c9ec13ce9fc7dfca0f.zip
cpython-62aa994633dbf87a4e7e03c9ec13ce9fc7dfca0f.tar.gz
cpython-62aa994633dbf87a4e7e03c9ec13ce9fc7dfca0f.tar.bz2
* Added separate checks for matching braces.
* Added more LaTex cmds from the docs. * Blocked forward-slash warnings with delimiters-only option. * Put help message on shorter line to fit an 80 char screen.
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/texcheck.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/Tools/scripts/texcheck.py b/Tools/scripts/texcheck.py
index 5264b24..c276596 100644
--- a/Tools/scripts/texcheck.py
+++ b/Tools/scripts/texcheck.py
@@ -14,8 +14,8 @@ Command line usage:
python texcheck.py [-h] [-k keyword] foobar.tex
Options:
- -m Munge parenthesis and brackets. [0,n) would normally mismatch.
- -k keyword: Keyword is a valid LaTeX command. Do not include the backslash.
+ -m Munge parenthesis and brackets. [0,n) would normally mismatch.
+ -k keyword: Keyword is a valid LaTeX command. Do not include the backslash.
-f: Forward-slash warnings suppressed.
-d: Delimiter check only (useful for non-LaTeX files).
-h: Help
@@ -52,6 +52,11 @@ cmdstr = r"""
\refmodindex \seerfc \makeindex \makemodindex \renewcommand
\indexname \appendix \protect \indexiv \mbox \textasciitilde
\platform \seeurl \leftmargin \labelwidth \localmoduletable
+ \LaTeX \copyright \memberline \backslash \pi \centerline
+ \caption \vspace \textwidth \menuselection \textless
+ \makevar \csimplemacro \menuselection \bfcode \sub \release
+ \email \kwindex \refexmodindex \filenq \e \menuselection
+ \exindex \linev \newsgroup \verbatim \setshortversion
"""
def matchclose(c_lineno, c_symbol, openers, pairmap):
@@ -85,8 +90,6 @@ def checkit(source, opts, morecmds=[]):
for cmd in morecmds:
validcmds.add('\\' + cmd)
- openers = [] # Stack of pending open delimiters
-
if '-m' in opts:
pairmap = {']':'[(', ')':'(['} # Munged openers
else:
@@ -94,6 +97,10 @@ def checkit(source, opts, morecmds=[]):
openpunct = sets.Set('([') # Set of valid openers
delimiters = re.compile(r'\\(begin|end){([_a-zA-Z]+)}|([()\[\]])')
+ braces = re.compile(r'({)|(})')
+
+ openers = [] # Stack of pending open delimiters
+ bracestack = [] # Stack of pending open braces
tablestart = re.compile(r'\\begin{(?:long)?table([iv]+)}')
tableline = re.compile(r'\\line([iv]+){')
@@ -107,7 +114,7 @@ def checkit(source, opts, morecmds=[]):
for lineno, line in izip(count(startline), islice(source, startline-1, None)):
line = line.rstrip()
- if '-f' not in opts and '/' in line:
+ if '/' in line and '-f' not in opts and '-d' not in opts:
# Warn whenever forward slashes encountered
line = line.rstrip()
print 'Warning, forward slash on line %d: %s' % (lineno, line)
@@ -123,7 +130,7 @@ def checkit(source, opts, morecmds=[]):
if cmd not in validcmds:
print r'Warning, unknown tex cmd on line %d: \%s' % (lineno, cmd)
- # Check balancing of open/close markers (parens, brackets, etc)
+ # Check balancing of open/close parenthesis and brackets
for begend, name, punct in delimiters.findall(line):
if '-v' in opts:
print lineno, '|', begend, name, punct,
@@ -138,6 +145,18 @@ def checkit(source, opts, morecmds=[]):
if '-v' in opts:
print ' --> ', openers
+ # Balance opening and closing braces
+ for open, close in braces.findall(line):
+ if open == '{':
+ bracestack.append(lineno)
+ if close == '}':
+ try:
+ bracestack.pop()
+ except IndexError:
+ print r'Warning, unmatched } on line %s.' % (lineno,)
+ if '-v' in opts:
+ print ' --> ', bracestack
+
# Check table levels (make sure lineii only inside tableii)
m = tablestart.search(line)
if m:
@@ -152,6 +171,8 @@ def checkit(source, opts, morecmds=[]):
lastline = lineno
for lineno, symbol in openers:
print "Unmatched open delimiter '%s' on line %d" % (symbol, lineno)
+ for lineno in bracestack:
+ print "Unmatched { on line %d" % (lineno,)
print 'Done checking %d lines.' % (lastline,)
return 0