summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey B. Arnold <jeffrey.arnold@gmail.com>2012-09-17 00:04:36 -0400
committerJeffrey B. Arnold <jeffrey.arnold@gmail.com>2012-09-17 00:04:36 -0400
commitd9a3a5c8a7cc568ea8b971153773967a44178d2a (patch)
treeb79b37f6e0856926e90d49ba27f53637c59d182a
parent92628028f2c489950c358b803b49235a9f328c5b (diff)
parentfbed153cb98976256d5707d902a9c91599c7b152 (diff)
downloadpygments-d9a3a5c8a7cc568ea8b971153773967a44178d2a.tar.gz
merge with
-rw-r--r--AUTHORS2
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/math.py42
-rw-r--r--tests/examplefiles/example.Rd78
4 files changed, 121 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index 7aab1883..49cf4d67 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,7 +9,7 @@ Other contributors, listed alphabetically, are:
* Kumar Appaiah -- Debian control lexer
* Ali Afshar -- image formatter
* Andreas Amann -- AppleScript lexer
-* Jeffrey Arnold -- R/S lexer, BUGS lexers
+* Jeffrey Arnold -- R/S, Rd and BUGS lexers
* Jeremy Ashkenas -- CoffeeScript lexer
* Stefan Matthias Aust -- Smalltalk lexer
* Ben Bangert -- Mako lexers
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index ad44fd4b..a0301055 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -219,6 +219,7 @@ LEXERS = {
'RagelObjectiveCLexer': ('pygments.lexers.parsers', 'Ragel in Objective C Host', ('ragel-objc',), ('*.rl',), ()),
'RagelRubyLexer': ('pygments.lexers.parsers', 'Ragel in Ruby Host', ('ragel-ruby', 'ragel-rb'), ('*.rl',), ()),
'RawTokenLexer': ('pygments.lexers.special', 'Raw token data', ('raw',), (), ('application/x-pygments-tokens',)),
+ 'RdLexer': ('pygments.lexers.math', 'Rd', ('rd',), ('*.Rd',), ('text/x-r-doc',)),
'RebolLexer': ('pygments.lexers.other', 'REBOL', ('rebol',), ('*.r', '*.r3'), ('text/x-rebol',)),
'RedcodeLexer': ('pygments.lexers.other', 'Redcode', ('redcode',), ('*.cw',), ()),
'RhtmlLexer': ('pygments.lexers.templates', 'RHTML', ('rhtml', 'html+erb', 'html+ruby'), ('*.rhtml',), ('text/html+ruby',)),
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py
index 5d732519..06221489 100644
--- a/pygments/lexers/math.py
+++ b/pygments/lexers/math.py
@@ -21,7 +21,8 @@ from pygments.lexers import _scilab_builtins
__all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
- 'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer']
+ 'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
+ 'RdLexer']
class JuliaLexer(RegexLexer):
@@ -1383,3 +1384,42 @@ class StanLexer(RegexLexer):
else:
return 0.0
+
+
+class RdLexer(RegexLexer):
+ """ Pygments Lexer for R documentation (Rd) files
+
+ This is a very minimal implementation, highlighting little more
+ than the macros. A description of Rd syntax is found in `Writing R
+ Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_
+ and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_.
+
+ """
+ name = 'Rd'
+ aliases = ['rd']
+ filenames = ['*.Rd']
+ mimetypes = ['text/x-r-doc']
+
+
+ # To account for verbatim / LaTeX-like / and R-like areas
+ # would require parsing.
+ tokens = {
+ 'root' : [
+ # catch escaped brackets and percent sign
+ (r'\\[\\{}%]', String.Escape),
+ # comments
+ (r'%.*$', Comment),
+ # special macros with no arguments
+ (r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
+ # macros
+ (r'\\[a-zA-Z]+\b', Keyword),
+ # special preprocessor macros
+ (r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
+ # Non escaped brackets
+ (r'[{}]', Name.Builtin),
+ # everything else
+ (r'.', Text),
+ ]
+ }
+
+
diff --git a/tests/examplefiles/example.Rd b/tests/examplefiles/example.Rd
new file mode 100644
index 00000000..2b8de0b8
--- /dev/null
+++ b/tests/examplefiles/example.Rd
@@ -0,0 +1,78 @@
+\name{foo}
+\alias{foo}
+% I'm a comment
+\title{The foo function}
+
+\description{It doesn't do much}
+
+\usage{
+foo(x, y)
+}
+
+\arguments{
+ \item{x}{A number}
+ \item{y}{Another number}
+}
+\details{
+ I just adds \code{x} and \code{y},
+}
+\value{\code{numeric}. The sum of \code{x} and \code{y}.}
+\references{
+ \href{http://en.wikipedia.org/wiki/Sum}{Sum}
+}
+\author{
+ Anonymous
+}
+\note{
+ Lorem ipsum \dots \R \emph{emp}, \strong{strong}, \bold{bold},
+ \sQuote{single quotes}, \dQuote{double quotes}, \code{code},
+ \preformatted{x <- 2 + 2}, \kbd{type this}, \samp{literal seq},
+ \pkg{base}, \file{foo.txt}, \email{email@hostname},
+ \url{http://cran.r-project.org/}, \var{foo}, \env{HOME},
+ \option{-d}, \dfn{something new}, \acronym{GNU}.
+
+ Escaped symbols: \\ \{ \} \% not comment. \\NotAMacro.
+
+ \tabular{rlll}{
+ [,1] \tab alpha \tab numeric \tab A (ppb)\cr
+ [,2] \tab bravo \tab integer \tab B \cr
+ [,3] \tab charlie \tab character \tab C \cr
+ }
+ \enumerate{
+ \item delta
+ \item echo
+ }
+ \itemize{
+ \item foxtrot
+ \item golf
+ }
+
+ \deqn{p(x; \mu, \sigma^2) = \frac{1}{\sigma \sqrt{2 \pi}} \exp \frac{-(x - \mu)^2}{2 \sigma}{%
+ p(\mu; x) = 1/\sigma (2 \pi)^(-1/2) exp( -(x - \mu)^2 / (2 \sigma)) }
+ for \eqn{x = 0, 1, 2, \ldots}.
+
+ \if{latex}{\out{\beta}}\ifelse{html}{\out{&beta;}}{beta}
+
+#ifdef unix
+Now windows
+#endif
+#ifndef windows
+Using windows
+#endif
+
+}
+\section{Misc}{
+ Stuff.
+}
+
+\seealso{
+ \code{\link{sum}}
+}
+\examples{
+x <- 1
+y <- 2
+z <- foo(x, y)
+\dontrun{plot(z)}
+\dontshow{log(x)}
+}
+\keyword{arith}