71 lines
17 KiB
Go
71 lines
17 KiB
Go
|
package r
|
||
|
|
||
|
import (
|
||
|
. "github.com/alecthomas/chroma" // nolint
|
||
|
"github.com/alecthomas/chroma/lexers/internal"
|
||
|
)
|
||
|
|
||
|
// R/S lexer.
|
||
|
var R = internal.Register(MustNewLexer(
|
||
|
&Config{
|
||
|
Name: "R",
|
||
|
Aliases: []string{"splus", "s", "r"},
|
||
|
Filenames: []string{"*.S", "*.R", "*.r", ".Rhistory", ".Rprofile", ".Renviron"},
|
||
|
MimeTypes: []string{"text/S-plus", "text/S", "text/x-r-source", "text/x-r", "text/x-R", "text/x-r-history", "text/x-r-profile"},
|
||
|
},
|
||
|
Rules{
|
||
|
"comments": {
|
||
|
{`#.*$`, CommentSingle, nil},
|
||
|
},
|
||
|
"valid_name": {
|
||
|
{`[a-zA-Z][\w.]*`, Text, nil},
|
||
|
{`\.[a-zA-Z_][\w.]*`, Text, nil},
|
||
|
},
|
||
|
"punctuation": {
|
||
|
{`\[{1,2}|\]{1,2}|\(|\)|;|,`, Punctuation, nil},
|
||
|
},
|
||
|
"keywords": {
|
||
|
{Words(``, `(?![\w. =])`, `Arg`, `Conj`, `Cstack_info`, `Encoding`, `FALSE`, `Filter`, `Find`, `I`, `ISOdate`, `ISOdatetime`, `Im`, `Inf`, `La.svd`, `Map`, `Math.Date`, `Math.POSIXt`, `Math.data.frame`, `Math.difftime`, `Math.factor`, `Mod`, `NA_character_`, `NA_complex_`, `NA_real_`, `NCOL`, `NROW`, `NULLNA_integer_`, `NaN`, `Negate`, `NextMethod`, `Ops.Date`, `Ops.POSIXt`, `Ops.data.frame`, `Ops.difftime`, `Ops.factor`, `Ops.numeric_version`, `Ops.ordered`, `Position`, `R.Version`, `R.home`, `R.version`, `R.version.string`, `RNGkind`, `RNGversion`, `R_system_version`, `Re`, `Recall`, `Reduce`, `Summary.Date`, `Summary.POSIXct`, `Summary.POSIXlt`, `Summary.data.frame`, `Summary.difftime`, `Summary.factor`, `Summary.numeric_version`, `Summary.ordered`, `Sys.Date`, `Sys.chmod`, `Sys.getenv`, `Sys.getlocale`, `Sys.getpid`, `Sys.glob`, `Sys.info`, `Sys.localeconv`, `Sys.readlink`, `Sys.setFileTime`, `Sys.setenv`, `Sys.setlocale`, `Sys.sleep`, `Sys.time`, `Sys.timezone`, `Sys.umask`, `Sys.unsetenv`, `Sys.which`, `TRUE`, `UseMethod`, `Vectorize`, `abbreviate`, `abs`, `acos`, `acosh`, `addNA`, `addTaskCallback`, `agrep`, `alist`, `all`, `all.equal`, `all.equal.POSIXct`, `all.equal.character`, `all.equal.default`, `all.equal.factor`, `all.equal.formula`, `all.equal.language`, `all.equal.list`, `all.equal.numeric`, `all.equal.raw`, `all.names`, `all.vars`, `any`, `anyDuplicated`, `anyDuplicated.array`, `anyDuplicated.data.frame`, `anyDuplicated.default`, `anyDuplicated.matrix`, `aperm`, `aperm.default`, `aperm.table`, `append`, `apply`, `args`, `arrayInd`, `as.Date`, `as.Date.POSIXct`, `as.Date.POSIXlt`, `as.Date.character`, `as.Date.date`, `as.Date.dates`, `as.Date.default`, `as.Date.factor`, `as.Date.numeric`, `as.POSIXct`, `as.POSIXct.Date`, `as.POSIXct.POSIXlt`, `as.POSIXct.date`, `as.POSIXct.dates`, `as.POSIXct.default`, `as.POSIXct.numeric`, `as.POSIXlt`, `as.POSIXlt.Date`, `as.POSIXlt.POSIXct`, `as.POSIXlt.character`, `as.POSIXlt.date`, `as.POSIXlt.dates`, `as.POSIXlt.default`, `as.POSIXlt.factor`, `as.POSIXlt.numeric`, `as.array`, `as.array.default`, `as.call`, `as.character`, `as.character.Date`, `as.character.POSIXt`, `as.character.condition`, `as.character.default`, `as.character.error`, `as.character.factor`, `as.character.hexmode`, `as.character.numeric_version`, `as.character.octmode`, `as.character.srcref`, `as.complex`, `as.data.frame`, `as.data.frame.AsIs`, `as.data.frame.Date`, `as.data.frame.POSIXct`, `as.data.frame.POSIXlt`, `as.data.frame.array`, `as.data.frame.character`, `as.data.frame.complex`, `as.data.frame.data.frame`, `as.data.frame.default`, `as.data.frame.difftime`, `as.data.frame.factor`, `as.data.frame.integer`, `as.data.frame.list`, `as.data.frame.logical`, `as.data.frame.matrix`, `as.data.frame.model.matrix`, `as.data.frame.numeric`, `as.data.frame.numeric_version`, `as.data.frame.ordered`, `as.data.frame.raw`, `as.data.frame.table`, `as.data.frame.ts`, `as.data.frame.vector`, `as.difftime`, `as.double`, `as.double.POSIXlt`, `as.double.difftime`, `as.environment`, `as.expression`, `as.expression.default`, `as.factor`, `as.function`, `as.function.default`, `as.hexmode`, `as.integer`, `as.list`, `as.list.Date`, `as.list.POSIXct`, `as.list.data.frame`, `as.list.default`, `as.list.environment`, `as.list.factor`, `as.list.function`, `as.list.numeric_version`, `as.logical`, `as.logical.factor`, `as.matrix`, `as.matrix.POSIXlt`, `as.matrix.data.frame`, `as.matrix.default`, `as.matrix.noquote`, `as.name`, `as.null`, `as.null.default`, `as.numeric`, `as.numeric_version`, `as.octmode`, `as.ordered`, `as.package_version`, `as.pairlist`, `as.qr`, `as.raw`, `as.single`, `as.single.default`, `as.symbol`, `as.table`, `as.table.default`, `as.vector`, `as.vector.factor`, `asNamespace`, `asS3`, `asS4`, `asin`, `asinh`, `assign`, `atan`, `atan2`, `atanh`, `attachNamespace`, `attr`, `attr.all.equal`, `attributes`, `autoload`, `autoloader`, `backsolve`, `baseenv`, `basename`, `besselI`, `besselJ`, `besselK`, `besselY`, `beta`, `bindingIsActive`, `bindingIsLocked`, `bindtextdomain`, `bitwAnd`, `bitwNot`, `bitwOr`
|
||
|
{`(if|else|for|while|repeat|in|next|break|return|switch|function)(?![\w.])`, KeywordReserved, nil},
|
||
|
{`(array|category|character|complex|double|function|integer|list|logical|matrix|numeric|vector|data.frame|c)(?![\w.])`, KeywordType, nil},
|
||
|
{`(library|require|attach|detach|source)(?![\w.])`, KeywordNamespace, nil},
|
||
|
},
|
||
|
"operators": {
|
||
|
{`<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?`, Operator, nil},
|
||
|
{`\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}`, Operator, nil},
|
||
|
},
|
||
|
"builtin_symbols": {
|
||
|
{`(NULL|NA(_(integer|real|complex|character)_)?|letters|LETTERS|Inf|TRUE|FALSE|NaN|pi|\.\.(\.|[0-9]+))(?![\w.])`, KeywordConstant, nil},
|
||
|
{`(T|F)\b`, NameBuiltinPseudo, nil},
|
||
|
},
|
||
|
"numbers": {
|
||
|
{`0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?`, LiteralNumberHex, nil},
|
||
|
{`[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)([eE][+-]?[0-9]+)?[Li]?`, LiteralNumber, nil},
|
||
|
},
|
||
|
"statements": {
|
||
|
Include("comments"),
|
||
|
{`\s+`, Text, nil},
|
||
|
{"`.*?`", LiteralStringBacktick, nil},
|
||
|
{`\'`, LiteralString, Push("string_squote")},
|
||
|
{`\"`, LiteralString, Push("string_dquote")},
|
||
|
Include("builtin_symbols"),
|
||
|
Include("numbers"),
|
||
|
Include("keywords"),
|
||
|
Include("punctuation"),
|
||
|
Include("operators"),
|
||
|
Include("valid_name"),
|
||
|
},
|
||
|
"root": {
|
||
|
Include("statements"),
|
||
|
{`\{|\}`, Punctuation, nil},
|
||
|
{`.`, Text, nil},
|
||
|
},
|
||
|
"string_squote": {
|
||
|
{`([^\'\\]|\\.)*\'`, LiteralString, Pop(1)},
|
||
|
},
|
||
|
"string_dquote": {
|
||
|
{`([^"\\]|\\.)*"`, LiteralString, Pop(1)},
|
||
|
},
|
||
|
},
|
||
|
))
|