]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/r.js
1 /*! `r` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
7 Description: R is a free software environment for statistical computing and graphics.
8 Author: Joe Cheng <joe@rstudio.org>
9 Contributors: Konrad Rudolph <konrad.rudolph@gmail.com>
10 Website: https://www.r-project.org
11 Category: common,scientific
14 /** @type LanguageFn */
16 const regex
= hljs
.regex
;
17 // Identifiers in R cannot start with `_`, but they can start with `.` if it
18 // is not immediately followed by a digit.
19 // R also supports quoted identifiers, which are near-arbitrary sequences
20 // delimited by backticks (`…`), which may contain escape sequences. These are
21 // handled in a separate mode. See `test/markup/r/names.txt` for examples.
22 // FIXME: Support Unicode identifiers.
23 const IDENT_RE
= /(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/;
24 const NUMBER_TYPES_RE
= regex
.either(
25 // Special case: only hexadecimal binary powers can contain fractions
26 /0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/,
27 // Hexadecimal numbers without fraction and optional binary power
28 /0[xX][0-9a-fA-F]+(?:[pP][+-]?\d+)?[Li]?/,
30 /(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[Li]?/
32 const OPERATORS_RE
= /[=!<>:]=|\|\||&&|:::?|<-|<<-|->>|->|\|>|[-+*\/?!$&|:<=>@^~]|\*\*/;
33 const PUNCTUATION_RE
= regex
.either(
48 'function if in break next repeat else for while',
50 'NULL NA TRUE FALSE Inf NaN NA_integer_|10 NA_real_|10 '
51 + 'NA_character_|10 NA_complex_|10',
54 'LETTERS letters month.abb month.name pi T F '
55 // Primitive functions
56 // These are all the functions in `base` that are implemented as a
57 // `.Primitive`, minus those functions that are also keywords.
58 + 'abs acos acosh all any anyNA Arg as.call as.character '
59 + 'as.complex as.double as.environment as.integer as.logical '
60 + 'as.null.default as.numeric as.raw asin asinh atan atanh attr '
61 + 'attributes baseenv browser c call ceiling class Conj cos cosh '
62 + 'cospi cummax cummin cumprod cumsum digamma dim dimnames '
63 + 'emptyenv exp expression floor forceAndCall gamma gc.time '
64 + 'globalenv Im interactive invisible is.array is.atomic is.call '
65 + 'is.character is.complex is.double is.environment is.expression '
66 + 'is.finite is.function is.infinite is.integer is.language '
67 + 'is.list is.logical is.matrix is.na is.name is.nan is.null '
68 + 'is.numeric is.object is.pairlist is.raw is.recursive is.single '
69 + 'is.symbol lazyLoadDBfetch length lgamma list log max min '
70 + 'missing Mod names nargs nzchar oldClass on.exit pos.to.env '
71 + 'proc.time prod quote range Re rep retracemem return round '
72 + 'seq_along seq_len seq.int sign signif sin sinh sinpi sqrt '
73 + 'standardGeneric substitute sum switch tan tanh tanpi tracemem '
74 + 'trigamma trunc unclass untracemem UseMethod xtfrm',
84 // Handle `@examples` separately to cause all subsequent code
85 // until the next `@`-tag on its own line to be kept as-is,
86 // preventing highlighting. This code is example R code, so nested
87 // doctags shouldn’t be treated as such. See
88 // `test/markup/r/roxygen.txt` for an example.
92 end: regex
.lookahead(regex
.either(
93 // end if another doc comment
94 /\n^#'\s*(?=@[a-zA-Z]+)/,
95 // or a line with no comment
102 // Handle `@param` to highlight the parameter name following
112 { match: /`(?:\\.|[^`\\])+`/ }
129 hljs
.HASH_COMMENT_MODE
,
133 contains: [ hljs
.BACKSLASH_ESCAPE
],
135 hljs
.END_SAME_AS_BEGIN({
136 begin: /[rR]"(-*)\(/,
139 hljs
.END_SAME_AS_BEGIN({
140 begin: /[rR]"(-*)\{/,
143 hljs
.END_SAME_AS_BEGIN({
144 begin: /[rR]"(-*)\[/,
147 hljs
.END_SAME_AS_BEGIN({
148 begin: /[rR]'(-*)\(/,
151 hljs
.END_SAME_AS_BEGIN({
152 begin: /[rR]'(-*)\{/,
155 hljs
.END_SAME_AS_BEGIN({
156 begin: /[rR]'(-*)\[/,
172 // Matching numbers immediately following punctuation and operators is
173 // tricky since we need to look at the character ahead of a number to
174 // ensure the number is not part of an identifier, and we cannot use
175 // negative look-behind assertions. So instead we explicitly handle all
176 // possible combinations of (operator|punctuation), number.
177 // TODO: replace with negative look-behind when available
178 // { begin: /(?<![a-zA-Z0-9._])0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/ },
179 // { begin: /(?<![a-zA-Z0-9._])0[xX][0-9a-fA-F]+([pP][+-]?\d+)?[Li]?/ },
180 // { begin: /(?<![a-zA-Z0-9._])(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[Li]?/ }
215 scope: { 2: 'number' },
217 /[^a-zA-Z0-9._]|^/, // not part of an identifier, or start of document
224 // Operators/punctuation when they're not directly followed by numbers
226 // Relevance boost for the most common assignment form.
227 scope: { 3: 'operator' },
240 { match: OPERATORS_RE
},
246 scope: 'punctuation',
248 match: PUNCTUATION_RE
252 // Escaped identifier
255 contains: [ { begin: /\\./ } ]
265 export default hljsGrammar
;