Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/sas.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.sas 

3 ~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for SAS. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12from pygments.lexer import RegexLexer, include, words 

13from pygments.token import Comment, Keyword, Name, Number, String, Text, \ 

14 Other, Generic 

15 

16__all__ = ['SASLexer'] 

17 

18 

19class SASLexer(RegexLexer): 

20 """ 

21 For SAS files. 

22 

23 .. versionadded:: 2.2 

24 """ 

25 # Syntax from syntax/sas.vim by James Kidd <james.kidd@covance.com> 

26 

27 name = 'SAS' 

28 aliases = ['sas'] 

29 filenames = ['*.SAS', '*.sas'] 

30 mimetypes = ['text/x-sas', 'text/sas', 'application/x-sas'] 

31 flags = re.IGNORECASE | re.MULTILINE 

32 

33 builtins_macros = ( 

34 "bquote", "nrbquote", "cmpres", "qcmpres", "compstor", "datatyp", 

35 "display", "do", "else", "end", "eval", "global", "goto", "if", 

36 "index", "input", "keydef", "label", "left", "length", "let", 

37 "local", "lowcase", "macro", "mend", "nrquote", 

38 "nrstr", "put", "qleft", "qlowcase", "qscan", 

39 "qsubstr", "qsysfunc", "qtrim", "quote", "qupcase", "scan", 

40 "str", "substr", "superq", "syscall", "sysevalf", "sysexec", 

41 "sysfunc", "sysget", "syslput", "sysprod", "sysrc", "sysrput", 

42 "then", "to", "trim", "unquote", "until", "upcase", "verify", 

43 "while", "window" 

44 ) 

45 

46 builtins_conditionals = ( 

47 "do", "if", "then", "else", "end", "until", "while" 

48 ) 

49 

50 builtins_statements = ( 

51 "abort", "array", "attrib", "by", "call", "cards", "cards4", 

52 "catname", "continue", "datalines", "datalines4", "delete", "delim", 

53 "delimiter", "display", "dm", "drop", "endsas", "error", "file", 

54 "filename", "footnote", "format", "goto", "in", "infile", "informat", 

55 "input", "keep", "label", "leave", "length", "libname", "link", 

56 "list", "lostcard", "merge", "missing", "modify", "options", "output", 

57 "out", "page", "put", "redirect", "remove", "rename", "replace", 

58 "retain", "return", "select", "set", "skip", "startsas", "stop", 

59 "title", "update", "waitsas", "where", "window", "x", "systask" 

60 ) 

61 

62 builtins_sql = ( 

63 "add", "and", "alter", "as", "cascade", "check", "create", 

64 "delete", "describe", "distinct", "drop", "foreign", "from", 

65 "group", "having", "index", "insert", "into", "in", "key", "like", 

66 "message", "modify", "msgtype", "not", "null", "on", "or", 

67 "order", "primary", "references", "reset", "restrict", "select", 

68 "set", "table", "unique", "update", "validate", "view", "where" 

69 ) 

70 

71 builtins_functions = ( 

72 "abs", "addr", "airy", "arcos", "arsin", "atan", "attrc", 

73 "attrn", "band", "betainv", "blshift", "bnot", "bor", 

74 "brshift", "bxor", "byte", "cdf", "ceil", "cexist", "cinv", 

75 "close", "cnonct", "collate", "compbl", "compound", 

76 "compress", "cos", "cosh", "css", "curobs", "cv", "daccdb", 

77 "daccdbsl", "daccsl", "daccsyd", "dacctab", "dairy", "date", 

78 "datejul", "datepart", "datetime", "day", "dclose", "depdb", 

79 "depdbsl", "depsl", "depsyd", 

80 "deptab", "dequote", "dhms", "dif", "digamma", 

81 "dim", "dinfo", "dnum", "dopen", "doptname", "doptnum", 

82 "dread", "dropnote", "dsname", "erf", "erfc", "exist", "exp", 

83 "fappend", "fclose", "fcol", "fdelete", "fetch", "fetchobs", 

84 "fexist", "fget", "fileexist", "filename", "fileref", 

85 "finfo", "finv", "fipname", "fipnamel", "fipstate", "floor", 

86 "fnonct", "fnote", "fopen", "foptname", "foptnum", "fpoint", 

87 "fpos", "fput", "fread", "frewind", "frlen", "fsep", "fuzz", 

88 "fwrite", "gaminv", "gamma", "getoption", "getvarc", "getvarn", 

89 "hbound", "hms", "hosthelp", "hour", "ibessel", "index", 

90 "indexc", "indexw", "input", "inputc", "inputn", "int", 

91 "intck", "intnx", "intrr", "irr", "jbessel", "juldate", 

92 "kurtosis", "lag", "lbound", "left", "length", "lgamma", 

93 "libname", "libref", "log", "log10", "log2", "logpdf", "logpmf", 

94 "logsdf", "lowcase", "max", "mdy", "mean", "min", "minute", 

95 "mod", "month", "mopen", "mort", "n", "netpv", "nmiss", 

96 "normal", "note", "npv", "open", "ordinal", "pathname", 

97 "pdf", "peek", "peekc", "pmf", "point", "poisson", "poke", 

98 "probbeta", "probbnml", "probchi", "probf", "probgam", 

99 "probhypr", "probit", "probnegb", "probnorm", "probt", 

100 "put", "putc", "putn", "qtr", "quote", "ranbin", "rancau", 

101 "ranexp", "rangam", "range", "rank", "rannor", "ranpoi", 

102 "rantbl", "rantri", "ranuni", "repeat", "resolve", "reverse", 

103 "rewind", "right", "round", "saving", "scan", "sdf", "second", 

104 "sign", "sin", "sinh", "skewness", "soundex", "spedis", 

105 "sqrt", "std", "stderr", "stfips", "stname", "stnamel", 

106 "substr", "sum", "symget", "sysget", "sysmsg", "sysprod", 

107 "sysrc", "system", "tan", "tanh", "time", "timepart", "tinv", 

108 "tnonct", "today", "translate", "tranwrd", "trigamma", 

109 "trim", "trimn", "trunc", "uniform", "upcase", "uss", "var", 

110 "varfmt", "varinfmt", "varlabel", "varlen", "varname", 

111 "varnum", "varray", "varrayx", "vartype", "verify", "vformat", 

112 "vformatd", "vformatdx", "vformatn", "vformatnx", "vformatw", 

113 "vformatwx", "vformatx", "vinarray", "vinarrayx", "vinformat", 

114 "vinformatd", "vinformatdx", "vinformatn", "vinformatnx", 

115 "vinformatw", "vinformatwx", "vinformatx", "vlabel", 

116 "vlabelx", "vlength", "vlengthx", "vname", "vnamex", "vtype", 

117 "vtypex", "weekday", "year", "yyq", "zipfips", "zipname", 

118 "zipnamel", "zipstate" 

119 ) 

120 

121 tokens = { 

122 'root': [ 

123 include('comments'), 

124 include('proc-data'), 

125 include('cards-datalines'), 

126 include('logs'), 

127 include('general'), 

128 (r'.', Text), 

129 ], 

130 # SAS is multi-line regardless, but * is ended by ; 

131 'comments': [ 

132 (r'^\s*\*.*?;', Comment), 

133 (r'/\*.*?\*/', Comment), 

134 (r'^\s*\*(.|\n)*?;', Comment.Multiline), 

135 (r'/[*](.|\n)*?[*]/', Comment.Multiline), 

136 ], 

137 # Special highlight for proc, data, quit, run 

138 'proc-data': [ 

139 (r'(^|;)\s*(proc \w+|data|run|quit)[\s;]', 

140 Keyword.Reserved), 

141 ], 

142 # Special highlight cards and datalines 

143 'cards-datalines': [ 

144 (r'^\s*(datalines|cards)\s*;\s*$', Keyword, 'data'), 

145 ], 

146 'data': [ 

147 (r'(.|\n)*^\s*;\s*$', Other, '#pop'), 

148 ], 

149 # Special highlight for put NOTE|ERROR|WARNING (order matters) 

150 'logs': [ 

151 (r'\n?^\s*%?put ', Keyword, 'log-messages'), 

152 ], 

153 'log-messages': [ 

154 (r'NOTE(:|-).*', Generic, '#pop'), 

155 (r'WARNING(:|-).*', Generic.Emph, '#pop'), 

156 (r'ERROR(:|-).*', Generic.Error, '#pop'), 

157 include('general'), 

158 ], 

159 'general': [ 

160 include('keywords'), 

161 include('vars-strings'), 

162 include('special'), 

163 include('numbers'), 

164 ], 

165 # Keywords, statements, functions, macros 

166 'keywords': [ 

167 (words(builtins_statements, 

168 prefix = r'\b', 

169 suffix = r'\b'), 

170 Keyword), 

171 (words(builtins_sql, 

172 prefix = r'\b', 

173 suffix = r'\b'), 

174 Keyword), 

175 (words(builtins_conditionals, 

176 prefix = r'\b', 

177 suffix = r'\b'), 

178 Keyword), 

179 (words(builtins_macros, 

180 prefix = r'%', 

181 suffix = r'\b'), 

182 Name.Builtin), 

183 (words(builtins_functions, 

184 prefix = r'\b', 

185 suffix = r'\('), 

186 Name.Builtin), 

187 ], 

188 # Strings and user-defined variables and macros (order matters) 

189 'vars-strings': [ 

190 (r'&[a-z_]\w{0,31}\.?', Name.Variable), 

191 (r'%[a-z_]\w{0,31}', Name.Function), 

192 (r'\'', String, 'string_squote'), 

193 (r'"', String, 'string_dquote'), 

194 ], 

195 'string_squote': [ 

196 ('\'', String, '#pop'), 

197 (r'\\\\|\\"|\\\n', String.Escape), 

198 # AFAIK, macro variables are not evaluated in single quotes 

199 # (r'&', Name.Variable, 'validvar'), 

200 (r'[^$\'\\]+', String), 

201 (r'[$\'\\]', String), 

202 ], 

203 'string_dquote': [ 

204 (r'"', String, '#pop'), 

205 (r'\\\\|\\"|\\\n', String.Escape), 

206 (r'&', Name.Variable, 'validvar'), 

207 (r'[^$&"\\]+', String), 

208 (r'[$"\\]', String), 

209 ], 

210 'validvar': [ 

211 (r'[a-z_]\w{0,31}\.?', Name.Variable, '#pop'), 

212 ], 

213 # SAS numbers and special variables 

214 'numbers': [ 

215 (r'\b[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)(E[+-]?[0-9]+)?i?\b', 

216 Number), 

217 ], 

218 'special': [ 

219 (r'(null|missing|_all_|_automatic_|_character_|_n_|' 

220 r'_infile_|_name_|_null_|_numeric_|_user_|_webout_)', 

221 Keyword.Constant), 

222 ], 

223 # 'operators': [ 

224 # (r'(-|=|<=|>=|<|>|<>|&|!=|' 

225 # r'\||\*|\+|\^|/|!|~|~=)', Operator) 

226 # ], 

227 }