summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2008-07-26 15:41:24 +0200
committergbrandl <devnull@localhost>2008-07-26 15:41:24 +0200
commitb3386b73f66d1ddeedbcf5e02343e00c903182d3 (patch)
tree7f16e6a50cd0cdea7b16a69415652583c3406adb
parent606090106ed34fd6296631345a79e713a4e04ec9 (diff)
parentee945e89d09d0225db3de3c3314709113df4bc76 (diff)
downloadpygments-b3386b73f66d1ddeedbcf5e02343e00c903182d3.tar.gz
Merge from http://code.timhatch.com/hg/pygments-tim.
-rw-r--r--CHANGES3
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/other.py192
-rw-r--r--pygments/lexers/text.py4
-rw-r--r--tests/examplefiles/test.plot333
-rw-r--r--tests/test_basic_api.py7
6 files changed, 525 insertions, 15 deletions
diff --git a/CHANGES b/CHANGES
index 33598abe..f2d984aa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ Version 0.11
* Cheetah/Spitfire templates, thanks to Matt Good
* Lighttpd config files
* Nginix config files
+ * Gnuplot plotting scripts
- Added "Visual Studio" style.
@@ -24,7 +25,7 @@ Version 0.11
- Support roman/sans/mono style defs and use them in the LaTeX
formatter.
-- The raw token formatter is no longer registered to ``*.raw``
+- The RawTokenFormatter is no longer registered to ``*.raw``
and it's documented that tokenization with this lexer may
raise exceptions.
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 3b272ea1..ec195588 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -55,6 +55,7 @@ LEXERS = {
'GenshiLexer': ('pygments.lexers.templates', 'Genshi', ('genshi', 'kid', 'xml+genshi', 'xml+kid'), ('*.kid',), ('application/x-genshi', 'application/x-kid')),
'GenshiTextLexer': ('pygments.lexers.templates', 'Genshi Text', ('genshitext',), (), ('application/x-genshi-text', 'text/x-genshi')),
'GettextLexer': ('pygments.lexers.text', 'Gettext Catalog', ('pot', 'po'), ('*.pot', '*.po'), ('application/x-gettext', 'text/x-gettext', 'text/gettext')),
+ 'GnuplotLexer': ('pygments.lexers.other', 'Gnuplot', ('gnuplot',), ('*.plot', '*.plt'), ('text/x-gnuplot',)),
'GroffLexer': ('pygments.lexers.text', 'Groff', ('groff', 'nroff', 'man'), ('*.[1234567]', '*.man'), ('application/x-troff', 'text/troff')),
'HaskellLexer': ('pygments.lexers.functional', 'Haskell', ('haskell', 'hs'), ('*.hs',), ('text/x-haskell',)),
'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja'), (), ('text/html+django', 'text/html+jinja')),
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index c35fc548..e2a18069 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -20,7 +20,7 @@ from pygments.util import shebang_matches
__all__ = ['SqlLexer', 'MySqlLexer', 'BrainfuckLexer', 'BashLexer',
'BatchLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer',
- 'SmalltalkLexer', 'TcshLexer', 'LogtalkLexer']
+ 'SmalltalkLexer', 'TcshLexer', 'LogtalkLexer', 'GnuplotLexer']
class SqlLexer(RegexLexer):
@@ -660,7 +660,8 @@ class LogtalkLexer(RegexLexer):
# DCGs and term expansion
(r'(expand_term|(goal|term)_expansion|phrase)(?=[(])', Keyword),
# Entity
- (r'(abolish|c(reate|urrent))_(object|protocol|category)(?=[(])', Keyword),
+ (r'(abolish|c(reate|urrent))_(object|protocol|category)(?=[(])',
+ Keyword),
(r'(object|protocol|category)_property(?=[(])', Keyword),
# Entity relations
(r'complements_object(?=[(])', Keyword),
@@ -682,7 +683,8 @@ class LogtalkLexer(RegexLexer):
# All solutions
(r'((bag|set)of|f(ind|or)all)(?=[(])', Keyword),
# Multi-threading meta-predicates
- (r'threaded(_(call|once|ignore|exit|peek|wait|notify))?(?=[(])', Keyword),
+ (r'threaded(_(call|once|ignore|exit|peek|wait|notify))?(?=[(])',
+ Keyword),
# Term unification
(r'unify_with_occurs_check(?=[(])', Keyword),
# Term creation and decomposition
@@ -694,13 +696,15 @@ class LogtalkLexer(RegexLexer):
# Other arithmetic functors
(r'(cos|atan|exp|log|s(in|qrt))(?=[(])', Keyword),
# Term testing
- (r'(var|atom(ic)?|integer|float|compound|n(onvar|umber))(?=[(])', Keyword),
+ (r'(var|atom(ic)?|integer|float|compound|n(onvar|umber))(?=[(])',
+ Keyword),
# Stream selection and control
(r'(curren|se)t_(in|out)put(?=[(])', Keyword),
(r'(open|close)(?=[(])', Keyword),
(r'flush_output(?=[(])', Keyword),
(r'(at_end_of_stream|flush_output)\b', Keyword),
- (r'(stream_property|at_end_of_stream|set_stream_position)(?=[(])', Keyword),
+ (r'(stream_property|at_end_of_stream|set_stream_position)(?=[(])',
+ Keyword),
# Character and byte input/output
(r'(nl|(get|peek|put)_(byte|c(har|ode)))(?=[(])', Keyword),
(r'\bnl\b', Keyword),
@@ -776,8 +780,8 @@ class LogtalkLexer(RegexLexer):
(r'e(ncoding|xport)(?=[(])', Keyword, 'root'),
(r'in(fo|itialization)(?=[(])', Keyword, 'root'),
(r'(dynamic|synchronized|threaded)[.]', Keyword, 'root'),
- (r'(alias|d(ynamic|iscontiguous)|m(eta_predicate|ode|ultifile)|'
- r'synchronized)(?=[(])', Keyword, 'root'),
+ (r'(alias|d(ynamic|iscontiguous)|m(eta_predicate|ode|ultifile)'
+ r'|synchronized)(?=[(])', Keyword, 'root'),
(r'op(?=[(])', Keyword, 'root'),
(r'(calls|use(s|_module))(?=[(])', Keyword, 'root'),
(r'[a-z][a-zA-Z0-9_]*(?=[(])', Text, 'root'),
@@ -785,7 +789,8 @@ class LogtalkLexer(RegexLexer):
],
'entityrelations': [
- (r'(extends|i(nstantiates|mp(lements|orts))|specializes)(?=[(])', Keyword),
+ (r'(extends|i(nstantiates|mp(lements|orts))|specializes)(?=[(])',
+ Keyword),
# Numbers
(r"0'.", Number),
(r'0b[01]+', Number),
@@ -800,13 +805,182 @@ class LogtalkLexer(RegexLexer):
# Strings
(r'"(\\\\|\\"|[^"])*"', String),
# End of entity-opening directive
- (r'([)]\.\n)', Text, 'root'),
+ (r'([)]\.)', Text, 'root'),
# Scope operator
(r'(::)', Operator),
# Ponctuation
(r'[()\[\],.|]', Text),
+ # Comments
+ (r'%.*?\n', Comment),
+ (r'/\*(.|\n)*?\*/',Comment),
# Whitespace
(r'\n', Text),
(r'\s+', Text),
]
}
+
+
+def _shortened(word):
+ dpos = word.find('$')
+ return '|'.join(word[:dpos] + word[dpos+1:i] + r'\b'
+ for i in range(len(word), dpos, -1))
+def _shortened_many(*words):
+ return '|'.join(map(_shortened, words))
+
+class GnuplotLexer(RegexLexer):
+ """
+ For `Gnuplot <http://gnuplot.info/>`_ plotting scripts.
+
+ *New in Pygments 0.11.*
+ """
+
+ name = 'Gnuplot'
+ aliases = ['gnuplot']
+ filenames = ['*.plot', '*.plt']
+ mimetypes = ['text/x-gnuplot']
+
+ tokens = {
+ 'root': [
+ include('whitespace'),
+ (_shortened('bi$nd'), Keyword, 'bind'),
+ (_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'),
+ (_shortened('f$it'), Keyword, 'fit'),
+ (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'),
+ (r'else\b', Keyword),
+ (_shortened('pa$use'), Keyword, 'pause'),
+ (_shortened_many('p$lot', 'rep$lot'), Keyword, 'plot'),
+ (_shortened('sa$ve'), Keyword, 'save'),
+ (_shortened('se$t'), Keyword, ('genericargs', 'optionarg')),
+ (_shortened_many('sh$ow', 'uns$et'),
+ Keyword, ('noargs', 'optionarg')),
+ (_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear',
+ 'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int',
+ 'pwd$', 're$read', 'res$et', 'scr$eendump',
+ 'she$ll', 'sy$stem', 'up$date'),
+ Keyword, 'genericargs'),
+ (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
+ 'she$ll', 'test$'),
+ Keyword, 'noargs'),
+ ('([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(=)',
+ bygroups(Name.Variable, Text, Operator), 'genericargs'),
+ ('([a-zA-Z_][a-zA-Z0-9_]*)(\s*\(.*?\)\s*)(=)',
+ bygroups(Name.Function, Text, Operator), 'genericargs'),
+ (r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
+ (r';', Keyword),
+ ],
+ 'comment': [
+ (r'[^\\\n]', Comment),
+ (r'\\\n', Comment),
+ (r'\\', Comment),
+ # don't add the newline to the Comment token
+ ('', Comment, '#pop'),
+ ],
+ 'whitespace': [
+ ('#', Comment, 'comment'),
+ (r'[ \t\v\f]+', Text),
+ ],
+ 'noargs': [
+ include('whitespace'),
+ # semicolon and newline end the argument list
+ (r';', Punctuation, '#pop'),
+ (r'\n', Text, '#pop'),
+ ],
+ 'dqstring': [
+ (r'"', String, '#pop'),
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
+ (r'[^\\"\n]+', String), # all other characters
+ (r'\\\n', String), # line continuation
+ (r'\\', String), # stray backslash
+ (r'\n', String, '#pop'), # newline ends the string too
+ ],
+ 'sqstring': [
+ (r"''", String), # escaped single quote
+ (r"'", String, '#pop'),
+ (r"[^\\'\n]+", String), # all other characters
+ (r'\\\n', String), # line continuation
+ (r'\\', String), # normal backslash
+ (r'\n', String, '#pop'), # newline ends the string too
+ ],
+ 'genericargs': [
+ include('noargs'),
+ (r'"', String, 'dqstring'),
+ (r"'", String, 'sqstring'),
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
+ (r'(\d+\.\d*|\.\d+)', Number.Float),
+ (r'-?\d+', Number.Integer),
+ ('[,.~!%^&*+=|?:<>/-]', Operator),
+ ('[{}()\[\]]', Punctuation),
+ (r'(eq|ne)\b', Operator.Word),
+ (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\()',
+ bygroups(Name.Function, Text, Punctuation)),
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
+ (r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
+ (r'\\\n', Text),
+ ],
+ 'optionarg': [
+ include('whitespace'),
+ (_shortened_many(
+ "a$ll","an$gles","ar$row","au$toscale","b$ars","bor$der",
+ "box$width","cl$abel","c$lip","cn$trparam","co$ntour","da$ta",
+ "data$file","dg$rid3d","du$mmy","enc$oding","dec$imalsign",
+ "fit$","font$path","fo$rmat","fu$nction","fu$nctions","g$rid",
+ "hid$den3d","his$torysize","is$osamples","k$ey","keyt$itle",
+ "la$bel","li$nestyle","ls$","loa$dpath","loc$ale","log$scale",
+ "mac$ros","map$ping","map$ping3d","mar$gin","lmar$gin",
+ "rmar$gin","tmar$gin","bmar$gin","mo$use","multi$plot",
+ "mxt$ics","nomxt$ics","mx2t$ics","nomx2t$ics","myt$ics",
+ "nomyt$ics","my2t$ics","nomy2t$ics","mzt$ics","nomzt$ics",
+ "mcbt$ics","nomcbt$ics","of$fsets","or$igin","o$utput",
+ "pa$rametric","pm$3d","pal$ette","colorb$ox","p$lot",
+ "poi$ntsize","pol$ar","pr$int","obj$ect","sa$mples","si$ze",
+ "st$yle","su$rface","table$","t$erminal","termo$ptions","ti$cs",
+ "ticsc$ale","ticsl$evel","timef$mt","tim$estamp","tit$le",
+ "v$ariables","ve$rsion","vi$ew","xyp$lane","xda$ta","x2da$ta",
+ "yda$ta","y2da$ta","zda$ta","cbda$ta","xl$abel","x2l$abel",
+ "yl$abel","y2l$abel","zl$abel","cbl$abel","xti$cs","noxti$cs",
+ "x2ti$cs","nox2ti$cs","yti$cs","noyti$cs","y2ti$cs","noy2ti$cs",
+ "zti$cs","nozti$cs","cbti$cs","nocbti$cs","xdti$cs","noxdti$cs",
+ "x2dti$cs","nox2dti$cs","ydti$cs","noydti$cs","y2dti$cs",
+ "noy2dti$cs","zdti$cs","nozdti$cs","cbdti$cs","nocbdti$cs",
+ "xmti$cs","noxmti$cs","x2mti$cs","nox2mti$cs","ymti$cs",
+ "noymti$cs","y2mti$cs","noy2mti$cs","zmti$cs","nozmti$cs",
+ "cbmti$cs","nocbmti$cs","xr$ange","x2r$ange","yr$ange",
+ "y2r$ange","zr$ange","cbr$ange","rr$ange","tr$ange","ur$ange",
+ "vr$ange","xzeroa$xis","x2zeroa$xis","yzeroa$xis","y2zeroa$xis",
+ "zzeroa$xis","zeroa$xis","z$ero"), Name.Builtin, '#pop'),
+ ],
+ 'bind': [
+ ('!', Keyword, '#pop'),
+ (_shortened('all$windows'), Name.Builtin),
+ include('genericargs'),
+ ],
+ 'quit': [
+ (r'gnuplot\b', Keyword),
+ include('noargs'),
+ ],
+ 'fit': [
+ (r'via\b', Name.Builtin),
+ include('plot'),
+ ],
+ 'if': [
+ (r'\)', Punctuation, '#pop'),
+ include('genericargs'),
+ ],
+ 'pause': [
+ (r'(mouse|any|button1|button2|button3)\b', Name.Builtin),
+ (_shortened('key$press'), Name.Builtin),
+ include('genericargs'),
+ ],
+ 'plot': [
+ (_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex',
+ 'mat$rix', 's$mooth', 'thru$', 't$itle',
+ 'not$itle', 'u$sing', 'w$ith'),
+ Name.Builtin),
+ include('genericargs'),
+ ],
+ 'save': [
+ (_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'),
+ Name.Builtin),
+ include('genericargs'),
+ ],
+ }
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index 0826f1a5..8fae4d61 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -1408,7 +1408,7 @@ class LighttpdConfLexer(RegexLexer):
"""
Lexer for `Lighttpd <http://lighttpd.net/>`_ configuration files.
- *New in Pygments 0.11*
+ *New in Pygments 0.11.*
"""
name = 'Lighttpd configuration file'
aliases = ['lighty', 'lighttpd']
@@ -1435,7 +1435,7 @@ class NginxConfLexer(RegexLexer):
"""
Lexer for `Nginx <http://nginx.net/>`_ configuration files.
- *New in Pygments 0.11*
+ *New in Pygments 0.11.*
"""
name = 'Nginx configuration file'
aliases = ['nginx']
diff --git a/tests/examplefiles/test.plot b/tests/examplefiles/test.plot
new file mode 100644
index 00000000..cef0f908
--- /dev/null
+++ b/tests/examplefiles/test.plot
@@ -0,0 +1,333 @@
+#
+# $Id: prob2.dem,v 1.9 2006/06/14 03:24:09 sfeam Exp $
+#
+# Demo Statistical Approximations version 1.1
+#
+# Copyright (c) 1991, Jos van der Woude, jvdwoude@hut.nl
+
+# History:
+# -- --- 1991 Jos van der Woude: 1st version
+# 06 Jun 2006 Dan Sebald: Added plot methods for better visual effect.
+
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print " Statistical Approximations, version 1.1"
+print ""
+print " Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print ""
+print " NOTE: contains 10 plots and consequently takes some time to run"
+print " Press Ctrl-C to exit right now"
+print ""
+pause -1 " Press Return to start demo ..."
+
+load "stat.inc"
+rnd(x) = floor(x+0.5)
+r_xmin = -1
+r_sigma = 4.0
+
+# Binomial PDF using normal approximation
+n = 25; p = 0.15
+mu = n * p
+sigma = sqrt(n * p * (1.0 - p))
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * binom(floor((n+1)*p), n, p) #mode of binomial PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "binomial PDF using normal approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot binom(rnd(x), n, p) with histeps, normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Binomial PDF using poisson approximation
+n = 50; p = 0.1
+mu = n * p
+sigma = sqrt(mu)
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * binom(floor((n+1)*p), n, p) #mode of binomial PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample (xmax - xmin + 3)
+set title "binomial PDF using poisson approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot binom(x, n, p) with histeps, poisson(x, mu) with histeps
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Geometric PDF using gamma approximation
+p = 0.3
+mu = (1.0 - p) / p
+sigma = sqrt(mu / p)
+lambda = p
+rho = 1.0 - p
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * p
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "geometric PDF using gamma approximation"
+set arrow from mu, 0 to mu, gmm(mu, rho, lambda) nohead
+set arrow from mu, gmm(mu + sigma, rho, lambda) \
+ to mu + sigma, gmm(mu + sigma, rho, lambda) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, gmm(mu + sigma, rho, lambda)
+plot geometric(rnd(x),p) with histeps, gmm(x, rho, lambda)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Geometric PDF using normal approximation
+p = 0.3
+mu = (1.0 - p) / p
+sigma = sqrt(mu / p)
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * p
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "geometric PDF using normal approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot geometric(rnd(x),p) with histeps, normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Hypergeometric PDF using binomial approximation
+nn = 75; mm = 25; n = 10
+p = real(mm) / nn
+mu = n * p
+sigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * hypgeo(floor(mu), nn, mm, n) #mode of binom PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample (xmax - xmin + 3)
+set title "hypergeometric PDF using binomial approximation"
+set arrow from mu, 0 to mu, binom(floor(mu), n, p) nohead
+set arrow from mu, binom(floor(mu + sigma), n, p) \
+ to mu + sigma, binom(floor(mu + sigma), n, p) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, binom(floor(mu + sigma), n, p)
+plot hypgeo(x, nn, mm, n) with histeps, binom(x, n, p) with histeps
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Hypergeometric PDF using normal approximation
+nn = 75; mm = 25; n = 10
+p = real(mm) / nn
+mu = n * p
+sigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * hypgeo(floor(mu), nn, mm, n) #mode of binom PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "hypergeometric PDF using normal approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot hypgeo(rnd(x), nn, mm, n) with histeps, normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Negative binomial PDF using gamma approximation
+r = 8; p = 0.6
+mu = r * (1.0 - p) / p
+sigma = sqrt(mu / p)
+lambda = p
+rho = r * (1.0 - p)
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * gmm((rho - 1) / lambda, rho, lambda) #mode of gamma PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "negative binomial PDF using gamma approximation"
+set arrow from mu, 0 to mu, gmm(mu, rho, lambda) nohead
+set arrow from mu, gmm(mu + sigma, rho, lambda) \
+ to mu + sigma, gmm(mu + sigma, rho, lambda) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, gmm(mu + sigma, rho, lambda)
+plot negbin(rnd(x), r, p) with histeps, gmm(x, rho, lambda)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Negative binomial PDF using normal approximation
+r = 8; p = 0.4
+mu = r * (1.0 - p) / p
+sigma = sqrt(mu / p)
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * negbin(floor((r-1)*(1-p)/p), r, p) #mode of gamma PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "negative binomial PDF using normal approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot negbin(rnd(x), r, p) with histeps, normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Normal PDF using logistic approximation
+mu = 1.0; sigma = 1.5
+a = mu
+lambda = pi / (sqrt(3.0) * sigma)
+xmin = mu - r_sigma * sigma
+xmax = mu + r_sigma * sigma
+ymax = 1.1 * logistic(mu, a, lambda) #mode of logistic PDF used
+set key box
+unset zeroaxis
+set xrange [xmin: xmax]
+set yrange [0 : ymax]
+set xlabel "x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%.1f"
+set format y "%.2f"
+set sample 200
+set title "normal PDF using logistic approximation"
+set arrow from mu,0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot logistic(x, a, lambda), normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+unset arrow
+unset label
+
+# Poisson PDF using normal approximation
+mu = 5.0
+sigma = sqrt(mu)
+xmin = floor(mu - r_sigma * sigma)
+xmin = xmin < r_xmin ? r_xmin : xmin
+xmax = ceil(mu + r_sigma * sigma)
+ymax = 1.1 * poisson(mu, mu) #mode of poisson PDF used
+set key box
+unset zeroaxis
+set xrange [xmin - 1 : xmax + 1]
+set yrange [0 : ymax]
+set xlabel "k, x ->"
+set ylabel "probability density ->"
+set ytics 0, ymax / 10.0, ymax
+set format x "%2.0f"
+set format y "%3.2f"
+set sample 200
+set title "poisson PDF using normal approximation"
+set arrow from mu, 0 to mu, normal(mu, mu, sigma) nohead
+set arrow from mu, normal(mu + sigma, mu, sigma) \
+ to mu + sigma, normal(mu + sigma, mu, sigma) nohead
+set label "mu" at mu + 0.5, ymax / 10
+set label "sigma" at mu + 0.5 + sigma, normal(mu + sigma, mu, sigma)
+plot poisson(rnd(x), mu) with histeps, normal(x, mu, sigma)
+pause -1 "Hit return to continue"
+reset
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index ab348cbc..50dbd943 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -15,6 +15,7 @@ import random
from pygments import lexers, formatters, filters, format
from pygments.token import _TokenType, Text
from pygments.lexer import RegexLexer
+from pygments.formatters.img import FontNotFound
test_content = [chr(i) for i in xrange(33, 128)] * 5
random.shuffle(test_content)
@@ -133,7 +134,7 @@ class FormattersTest(unittest.TestCase):
try:
inst = formatter(opt1="val1")
- except ImportError:
+ except (ImportError, FontNotFound):
continue
inst.get_style_defs()
inst.format(ts, out)
@@ -168,8 +169,8 @@ class FormattersTest(unittest.TestCase):
for formatter, info in formatters.FORMATTERS.iteritems():
try:
inst = formatter(encoding=None)
- except ImportError:
- # some dependency not installed
+ except (ImportError, FontNotFound):
+ # some dependency or font not installed
continue
out = format(tokens, inst)
if formatter.unicodeoutput: