1package s
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Sas lexer.
9var Sas = internal.Register(MustNewLazyLexer(
10	&Config{
11		Name:            "SAS",
12		Aliases:         []string{"sas"},
13		Filenames:       []string{"*.SAS", "*.sas"},
14		MimeTypes:       []string{"text/x-sas", "text/sas", "application/x-sas"},
15		CaseInsensitive: true,
16	},
17	sasRules,
18))
19
20func sasRules() Rules {
21	return Rules{
22		"root": {
23			Include("comments"),
24			Include("proc-data"),
25			Include("cards-datalines"),
26			Include("logs"),
27			Include("general"),
28			{`.`, Text, nil},
29			{`\\\n`, Text, nil},
30			{`\n`, Text, nil},
31		},
32		"comments": {
33			{`^\s*\*.*?;`, Comment, nil},
34			{`/\*.*?\*/`, Comment, nil},
35			{`^\s*\*(.|\n)*?;`, CommentMultiline, nil},
36			{`/[*](.|\n)*?[*]/`, CommentMultiline, nil},
37		},
38		"proc-data": {
39			{`(^|;)\s*(proc \w+|data|run|quit)[\s;]`, KeywordReserved, nil},
40		},
41		"cards-datalines": {
42			{`^\s*(datalines|cards)\s*;\s*$`, Keyword, Push("data")},
43		},
44		"data": {
45			{`(.|\n)*^\s*;\s*$`, Other, Pop(1)},
46		},
47		"logs": {
48			{`\n?^\s*%?put `, Keyword, Push("log-messages")},
49		},
50		"log-messages": {
51			{`NOTE(:|-).*`, Generic, Pop(1)},
52			{`WARNING(:|-).*`, GenericEmph, Pop(1)},
53			{`ERROR(:|-).*`, GenericError, Pop(1)},
54			Include("general"),
55		},
56		"general": {
57			Include("keywords"),
58			Include("vars-strings"),
59			Include("special"),
60			Include("numbers"),
61		},
62		"keywords": {
63			{Words(`\b`, `\b`, `abort`, `array`, `attrib`, `by`, `call`, `cards`, `cards4`, `catname`, `continue`, `datalines`, `datalines4`, `delete`, `delim`, `delimiter`, `display`, `dm`, `drop`, `endsas`, `error`, `file`, `filename`, `footnote`, `format`, `goto`, `in`, `infile`, `informat`, `input`, `keep`, `label`, `leave`, `length`, `libname`, `link`, `list`, `lostcard`, `merge`, `missing`, `modify`, `options`, `output`, `out`, `page`, `put`, `redirect`, `remove`, `rename`, `replace`, `retain`, `return`, `select`, `set`, `skip`, `startsas`, `stop`, `title`, `update`, `waitsas`, `where`, `window`, `x`, `systask`), Keyword, nil},
64			{Words(`\b`, `\b`, `add`, `and`, `alter`, `as`, `cascade`, `check`, `create`, `delete`, `describe`, `distinct`, `drop`, `foreign`, `from`, `group`, `having`, `index`, `insert`, `into`, `in`, `key`, `like`, `message`, `modify`, `msgtype`, `not`, `null`, `on`, `or`, `order`, `primary`, `references`, `reset`, `restrict`, `select`, `set`, `table`, `unique`, `update`, `validate`, `view`, `where`), Keyword, nil},
65			{Words(`\b`, `\b`, `do`, `if`, `then`, `else`, `end`, `until`, `while`), Keyword, nil},
66			{Words(`%`, `\b`, `bquote`, `nrbquote`, `cmpres`, `qcmpres`, `compstor`, `datatyp`, `display`, `do`, `else`, `end`, `eval`, `global`, `goto`, `if`, `index`, `input`, `keydef`, `label`, `left`, `length`, `let`, `local`, `lowcase`, `macro`, `mend`, `nrquote`, `nrstr`, `put`, `qleft`, `qlowcase`, `qscan`, `qsubstr`, `qsysfunc`, `qtrim`, `quote`, `qupcase`, `scan`, `str`, `substr`, `superq`, `syscall`, `sysevalf`, `sysexec`, `sysfunc`, `sysget`, `syslput`, `sysprod`, `sysrc`, `sysrput`, `then`, `to`, `trim`, `unquote`, `until`, `upcase`, `verify`, `while`, `window`), NameBuiltin, nil},
67			{Words(`\b`, `\(`, `abs`, `addr`, `airy`, `arcos`, `arsin`, `atan`, `attrc`, `attrn`, `band`, `betainv`, `blshift`, `bnot`, `bor`, `brshift`, `bxor`, `byte`, `cdf`, `ceil`, `cexist`, `cinv`, `close`, `cnonct`, `collate`, `compbl`, `compound`, `compress`, `cos`, `cosh`, `css`, `curobs`, `cv`, `daccdb`, `daccdbsl`, `daccsl`, `daccsyd`, `dacctab`, `dairy`, `date`, `datejul`, `datepart`, `datetime`, `day`, `dclose`, `depdb`, `depdbsl`, `depsl`, `depsyd`, `deptab`, `dequote`, `dhms`, `dif`, `digamma`, `dim`, `dinfo`, `dnum`, `dopen`, `doptname`, `doptnum`, `dread`, `dropnote`, `dsname`, `erf`, `erfc`, `exist`, `exp`, `fappend`, `fclose`, `fcol`, `fdelete`, `fetch`, `fetchobs`, `fexist`, `fget`, `fileexist`, `filename`, `fileref`, `finfo`, `finv`, `fipname`, `fipnamel`, `fipstate`, `floor`, `fnonct`, `fnote`, `fopen`, `foptname`, `foptnum`, `fpoint`, `fpos`, `fput`, `fread`, `frewind`, `frlen`, `fsep`, `fuzz`, `fwrite`, `gaminv`, `gamma`, `getoption`, `getvarc`, `getvarn`, `hbound`, `hms`, `hosthelp`, `hour`, `ibessel`, `index`, `indexc`, `indexw`, `input`, `inputc`, `inputn`, `int`, `intck`, `intnx`, `intrr`, `irr`, `jbessel`, `juldate`, `kurtosis`, `lag`, `lbound`, `left`, `length`, `lgamma`, `libname`, `libref`, `log`, `log10`, `log2`, `logpdf`, `logpmf`, `logsdf`, `lowcase`, `max`, `mdy`, `mean`, `min`, `minute`, `mod`, `month`, `mopen`, `mort`, `n`, `netpv`, `nmiss`, `normal`, `note`, `npv`, `open`, `ordinal`, `pathname`, `pdf`, `peek`, `peekc`, `pmf`, `point`, `poisson`, `poke`, `probbeta`, `probbnml`, `probchi`, `probf`, `probgam`, `probhypr`, `probit`, `probnegb`, `probnorm`, `probt`, `put`, `putc`, `putn`, `qtr`, `quote`, `ranbin`, `rancau`, `ranexp`, `rangam`, `range`, `rank`, `rannor`, `ranpoi`, `rantbl`, `rantri`, `ranuni`, `repeat`, `resolve`, `reverse`, `rewind`, `right`, `round`, `saving`, `scan`, `sdf`, `second`, `sign`, `sin`, `sinh`, `skewness`, `soundex`, `spedis`, `sqrt`, `std`, `stderr`, `stfips`, `stname`, `stnamel`, `substr`, `sum`, `symget`, `sysget`, `sysmsg`, `sysprod`, `sysrc`, `system`, `tan`, `tanh`, `time`, `timepart`, `tinv`, `tnonct`, `today`, `translate`, `tranwrd`, `trigamma`, `trim`, `trimn`, `trunc`, `uniform`, `upcase`, `uss`, `var`, `varfmt`, `varinfmt`, `varlabel`, `varlen`, `varname`, `varnum`, `varray`, `varrayx`, `vartype`, `verify`, `vformat`, `vformatd`, `vformatdx`, `vformatn`, `vformatnx`, `vformatw`, `vformatwx`, `vformatx`, `vinarray`, `vinarrayx`, `vinformat`, `vinformatd`, `vinformatdx`, `vinformatn`, `vinformatnx`, `vinformatw`, `vinformatwx`, `vinformatx`, `vlabel`, `vlabelx`, `vlength`, `vlengthx`, `vname`, `vnamex`, `vtype`, `vtypex`, `weekday`, `year`, `yyq`, `zipfips`, `zipname`, `zipnamel`, `zipstate`), NameBuiltin, nil},
68		},
69		"vars-strings": {
70			{`&[a-z_]\w{0,31}\.?`, NameVariable, nil},
71			{`%[a-z_]\w{0,31}`, NameFunction, nil},
72			{`\'`, LiteralString, Push("string_squote")},
73			{`"`, LiteralString, Push("string_dquote")},
74		},
75		"string_squote": {
76			{`'`, LiteralString, Pop(1)},
77			{`\\\\|\\"|\\\n`, LiteralStringEscape, nil},
78			{`[^$\'\\]+`, LiteralString, nil},
79			{`[$\'\\]`, LiteralString, nil},
80		},
81		"string_dquote": {
82			{`"`, LiteralString, Pop(1)},
83			{`\\\\|\\"|\\\n`, LiteralStringEscape, nil},
84			{`&`, NameVariable, Push("validvar")},
85			{`[^$&"\\]+`, LiteralString, nil},
86			{`[$"\\]`, LiteralString, nil},
87		},
88		"validvar": {
89			{`[a-z_]\w{0,31}\.?`, NameVariable, Pop(1)},
90		},
91		"numbers": {
92			{`\b[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)(E[+-]?[0-9]+)?i?\b`, LiteralNumber, nil},
93		},
94		"special": {
95			{`(null|missing|_all_|_automatic_|_character_|_n_|_infile_|_name_|_null_|_numeric_|_user_|_webout_)`, KeywordConstant, nil},
96		},
97	}
98}
99