rouge 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/demos/ada +26 -0
  3. data/lib/rouge/demos/cuda +11 -0
  4. data/lib/rouge/demos/gdscript +18 -0
  5. data/lib/rouge/demos/hocon +8 -0
  6. data/lib/rouge/demos/mason +22 -0
  7. data/lib/rouge/demos/opentype_feature_file +6 -0
  8. data/lib/rouge/demos/reasonml +12 -0
  9. data/lib/rouge/demos/sas +13 -0
  10. data/lib/rouge/formatters/tex.rb +3 -0
  11. data/lib/rouge/guessers/disambiguation.rb +4 -0
  12. data/lib/rouge/lexers/ada.rb +162 -0
  13. data/lib/rouge/lexers/cuda.rb +35 -0
  14. data/lib/rouge/lexers/escape.rb +3 -0
  15. data/lib/rouge/lexers/gdscript.rb +171 -0
  16. data/lib/rouge/lexers/gherkin.rb +4 -2
  17. data/lib/rouge/lexers/graphql.rb +10 -3
  18. data/lib/rouge/lexers/handlebars.rb +14 -3
  19. data/lib/rouge/lexers/hocon.rb +86 -0
  20. data/lib/rouge/lexers/html.rb +2 -2
  21. data/lib/rouge/lexers/igorpro.rb +1 -1
  22. data/lib/rouge/lexers/json.rb +43 -5
  23. data/lib/rouge/lexers/mason.rb +115 -0
  24. data/lib/rouge/lexers/ocaml.rb +12 -48
  25. data/lib/rouge/lexers/ocaml/common.rb +53 -0
  26. data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
  27. data/lib/rouge/lexers/php.rb +31 -9
  28. data/lib/rouge/lexers/php/builtins.rb +181 -174
  29. data/lib/rouge/lexers/reasonml.rb +65 -0
  30. data/lib/rouge/lexers/rust.rb +12 -9
  31. data/lib/rouge/lexers/sas.rb +563 -0
  32. data/lib/rouge/lexers/smarty.rb +10 -10
  33. data/lib/rouge/tex_theme_renderer.rb +3 -0
  34. data/lib/rouge/themes/magritte.rb +1 -1
  35. data/lib/rouge/themes/thankful_eyes.rb +1 -1
  36. data/lib/rouge/themes/tulip.rb +1 -1
  37. data/lib/rouge/version.rb +1 -1
  38. data/rouge.gemspec +0 -1
  39. metadata +19 -2
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'ocaml/common.rb'
7
+
8
+ class ReasonML < OCamlCommon
9
+ title "ReasonML"
10
+ desc 'New syntax on top of OCaml ecosystem (reasonml.github.io)'
11
+ tag 'reasonml'
12
+ filenames '*.re', '*.rei'
13
+ mimetypes 'text/x-reasonml'
14
+
15
+ def self.keywords
16
+ @keywords ||= super + Set.new(%w(
17
+ switch
18
+ ))
19
+ end
20
+
21
+ state :root do
22
+ rule %r/\s+/m, Text
23
+ rule %r/false|true|[(][)]|\[\]/, Name::Builtin::Pseudo
24
+ rule %r/#{@@upper_id}(?=\s*[.])/, Name::Namespace, :dotted
25
+ rule %r/`#{@@id}/, Name::Tag
26
+ rule @@upper_id, Name::Class
27
+ rule %r/[\/][*](?![\/])/, Comment, :comment
28
+ rule @@id do |m|
29
+ match = m[0]
30
+ if self.class.keywords.include? match
31
+ token Keyword
32
+ elsif self.class.word_operators.include? match
33
+ token Operator::Word
34
+ elsif self.class.primitives.include? match
35
+ token Keyword::Type
36
+ else
37
+ token Name
38
+ end
39
+ end
40
+
41
+ rule %r/[(){}\[\];]+/, Punctuation
42
+ rule @@operator, Operator
43
+
44
+ rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
45
+ rule %r/0x\h[\h_]*/i, Num::Hex
46
+ rule %r/0o[0-7][0-7_]*/i, Num::Oct
47
+ rule %r/0b[01][01_]*/i, Num::Bin
48
+ rule %r/\d[\d_]*/, Num::Integer
49
+
50
+ rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
51
+ rule %r/'[^'\/]'/, Str::Char
52
+ rule %r/'/, Keyword
53
+ rule %r/"/, Str::Double, :string
54
+ rule %r/[~?]#{@@id}/, Name::Variable
55
+ end
56
+
57
+ state :comment do
58
+ rule %r|[^/*)]+|, Comment
59
+ rule %r|[/][*]|, Comment, :push
60
+ rule %r|[*][/]|, Comment, :pop!
61
+ rule %r|[*/]|, Comment
62
+ end
63
+ end
64
+ end
65
+ end
@@ -22,7 +22,7 @@ module Rouge
22
22
 
23
23
  def self.keywords
24
24
  @keywords ||= %w(
25
- as assert break const copy do drop else enum extern fail false
25
+ as assert async await break const copy do drop else enum extern fail false
26
26
  fn for if impl let log loop match mod move mut priv pub pure
27
27
  ref return self static struct true trait type unsafe use where
28
28
  while box
@@ -49,6 +49,7 @@ module Rouge
49
49
 
50
50
  start {
51
51
  @macro_delims = { ']' => 0, ')' => 0, '}' => 0 }
52
+ push :bol
52
53
  }
53
54
 
54
55
  delim_map = { '[' => ']', '(' => ')', '{' => '}' }
@@ -60,20 +61,21 @@ module Rouge
60
61
  )x
61
62
  size = /8|16|32|64/
62
63
 
63
- state :start_line do
64
+ # Although not officially part of Rust, the rustdoc tool allows code in
65
+ # comments to begin with `#`. Code like this will be evaluated but not
66
+ # included in the HTML output produced by rustdoc. So that code intended
67
+ # for these comments can be higlighted with Rouge, the Rust lexer needs
68
+ # to check if the beginning of the line begins with a `# `.
69
+ state :bol do
64
70
  mixin :whitespace
65
- rule %r/\s+/, Text
66
- rule %r/#\[/ do
67
- token Name::Decorator; push :attribute
68
- end
71
+ rule %r/#\s[^\n]*/, Comment::Special
69
72
  rule(//) { pop! }
70
- rule %r/#\s[^\n]*/, Comment::Preproc
71
73
  end
72
74
 
73
75
  state :attribute do
74
76
  mixin :whitespace
75
77
  mixin :has_literals
76
- rule %r/[(,)=]/, Name::Decorator
78
+ rule %r/[(,)=:]/, Name::Decorator
77
79
  rule %r/\]/, Name::Decorator, :pop!
78
80
  rule id, Name::Decorator
79
81
  end
@@ -85,8 +87,9 @@ module Rouge
85
87
  end
86
88
 
87
89
  state :root do
88
- rule %r/\n/, Text, :start_line
90
+ rule %r/\n/, Text, :bol
89
91
  mixin :whitespace
92
+ rule %r/#!?\[/, Name::Decorator, :attribute
90
93
  rule %r/\b(?:#{Rust.keywords.join('|')})\b/, Keyword
91
94
  mixin :has_literals
92
95
 
@@ -0,0 +1,563 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class SAS < RegexLexer
6
+ title "SAS"
7
+ desc "SAS (Statistical Analysis Software)"
8
+ tag 'sas'
9
+ filenames '*.sas'
10
+ mimetypes 'application/x-sas', 'application/x-stat-sas', 'application/x-sas-syntax'
11
+
12
+ def self.data_step_statements
13
+ # from Data step statements - SAS 9.4 Statements reference
14
+ # http://support.sas.com/documentation/cdl/en/lestmtsref/68024/PDF/default/lestmtsref.pdf
15
+ @data_step_statements ||= Set.new %w(
16
+ ABORT ARRAY ATTRIB BY CALL CARDS CARDS4 CATNAME CHECKPOINT
17
+ EXECUTE_ALWAYS CONTINUE DATA DATALINES DATALINES4 DELETE DESCRIBE
18
+ DISPLAY DM DO UNTIL WHILE DROP END ENDSAS ERROR EXECUTE FILE FILENAME
19
+ FOOTNOTE FORMAT GO TO IF THEN ELSE INFILE INFORMAT INPUT
20
+ KEEP LABEL LEAVE LENGTH LIBNAME LINK LIST LOCK LOSTCARD MERGE
21
+ MISSING MODIFY OPTIONS OUTPUT PAGE PUT PUTLOG REDIRECT REMOVE RENAME
22
+ REPLACE RESETLINE RETAIN RETURN RUN SASFILE SELECT SET SKIP STOP
23
+ SYSECHO TITLE UPDATE WHERE WINDOW X
24
+ )
25
+ # label:
26
+ # Sum
27
+ end
28
+
29
+ def self.sas_functions
30
+ # from SAS 9.4 Functions and CALL Routines reference
31
+ # http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/PDF/default/lefunctionsref.pdf
32
+ @sas_functions ||= Set.new %w(
33
+ ABS ADDR ADDRLONG AIRY ALLCOMB ALLPERM ANYALNUM ANYALPHA ANYCNTRL
34
+ ANYDIGIT ANYFIRST ANYGRAPH ANYLOWER ANYNAME ANYPRINT ANYPUNCT
35
+ ANYSPACE ANYUPPER ANYXDIGIT ARCOS ARCOSH ARSIN ARSINH ARTANH ATAN
36
+ ATAN2 ATTRC ATTRN BAND BETA BETAINV BLACKCLPRC BLACKPTPRC
37
+ BLKSHCLPRC BLKSHPTPRC BLSHIFT BNOT BOR BRSHIFT BXOR BYTE CAT CATQ
38
+ CATS CATT CATX CDF CEIL CEILZ CEXIST CHAR CHOOSEC CHOOSEN CINV
39
+ CLOSE CMISS CNONCT COALESCE COALESCEC COLLATE COMB COMPARE COMPBL
40
+ COMPFUZZ COMPGED COMPLEV COMPOUND COMPRESS CONSTANT CONVX CONVXP
41
+ COS COSH COT COUNT COUNTC COUNTW CSC CSS CUMIPMT CUMPRINC CUROBS
42
+ CV DACCDB DACCDBSL DACCSL DACCSYD DACCTAB DAIRY DATDIF DATE
43
+ DATEJUL DATEPART DATETIME DAY DCLOSE DCREATE DEPDB DEPDBSL DEPSL
44
+ DEPSYD DEPTAB DEQUOTE DEVIANCE DHMS DIF DIGAMMA DIM DINFO DIVIDE
45
+ DNUM DOPEN DOPTNAME DOPTNUM DOSUBL DREAD DROPNOTE DSNAME
46
+ DSNCATLGD DUR DURP EFFRATE ENVLEN ERF ERFC EUCLID EXIST EXP FACT
47
+ FAPPEND FCLOSE FCOL FCOPY FDELETE FETCH FETCHOBS FEXIST FGET
48
+ FILEEXIST FILENAME FILEREF FINANCE FIND FINDC FINDW FINFO FINV
49
+ FIPNAME FIPNAMEL FIPSTATE FIRST FLOOR FLOORZ FMTINFO FNONCT FNOTE
50
+ FOPEN FOPTNAME FOPTNUM FPOINT FPOS FPUT FREAD FREWIND FRLEN FSEP
51
+ FUZZ FWRITE GAMINV GAMMA GARKHCLPRC GARKHPTPRC GCD GEODIST
52
+ GEOMEAN GEOMEANZ GETOPTION GETVARC GETVARN GRAYCODE HARMEAN
53
+ HARMEANZ HBOUND HMS HOLIDAY HOLIDAYCK HOLIDAYCOUNT HOLIDAYNAME
54
+ HOLIDAYNX HOLIDAYNY HOLIDAYTEST HOUR HTMLDECODE HTMLENCODE
55
+ IBESSEL IFC IFN INDEX INDEXC INDEXW INPUT INPUTC INPUTN INT
56
+ INTCINDEX INTCK INTCYCLE INTFIT INTFMT INTGET INTINDEX INTNX
57
+ INTRR INTSEAS INTSHIFT INTTEST INTZ IORCMSG IPMT IQR IRR JBESSEL
58
+ JULDATE JULDATE7 KURTOSIS LAG LARGEST LBOUND LCM LCOMB LEFT
59
+ LENGTH LENGTHC LENGTHM LENGTHN LEXCOMB LEXCOMBI LEXPERK LEXPERM
60
+ LFACT LGAMMA LIBNAME LIBREF LOG LOG1PX LOG10 LOG2 LOGBETA LOGCDF
61
+ LOGISTIC LOGPDF LOGSDF LOWCASE LPERM LPNORM MAD MARGRCLPRC
62
+ MARGRPTPRC MAX MD5 MDY MEAN MEDIAN MIN MINUTE MISSING MOD
63
+ MODEXIST MODULE MODULEC MODULEN MODZ MONTH MOPEN MORT MSPLINT
64
+ MVALID N NETPV NLITERAL NMISS NOMRATE NORMAL NOTALNUM NOTALPHA
65
+ NOTCNTRL NOTDIGIT NOTE NOTFIRST NOTGRAPH NOTLOWER NOTNAME
66
+ NOTPRINT NOTPUNCT NOTSPACE NOTUPPER NOTXDIGIT NPV NVALID NWKDOM
67
+ OPEN ORDINAL PATHNAME PCTL PDF PEEK PEEKC PEEKCLONG PEEKLONG PERM
68
+ PMT POINT POISSON PPMT PROBBETA PROBBNML PROBBNRM PROBCHI PROBF
69
+ PROBGAM PROBHYPR PROBIT PROBMC PROBNEGB PROBNORM PROBT PROPCASE
70
+ PRXCHANGE PRXMATCH PRXPAREN PRXPARSE PRXPOSN PTRLONGADD PUT PUTC
71
+ PUTN PVP QTR QUANTILE QUOTE RANBIN RANCAU RAND RANEXP RANGAM
72
+ RANGE RANK RANNOR RANPOI RANTBL RANTRI RANUNI RENAME REPEAT
73
+ RESOLVE REVERSE REWIND RIGHT RMS ROUND ROUNDE ROUNDZ SAVING
74
+ SAVINGS SCAN SDF SEC SECOND SHA256 SHA256HEX SHA256HMACHEX SIGN
75
+ SIN SINH SKEWNESS SLEEP SMALLEST SOAPWEB SOAPWEBMETA
76
+ SOAPWIPSERVICE SOAPWIPSRS SOAPWS SOAPWSMETA SOUNDEX SPEDIS SQRT
77
+ SQUANTILE STD STDERR STFIPS STNAME STNAMEL STRIP SUBPAD SUBSTR
78
+ SUBSTRN SUM SUMABS SYMEXIST SYMGET SYMGLOBL SYMLOCAL SYSEXIST
79
+ SYSGET SYSMSG SYSPARM SYSPROCESSID SYSPROCESSNAME SYSPROD SYSRC
80
+ SYSTEM TAN TANH TIME TIMEPART TIMEVALUE TINV TNONCT TODAY
81
+ TRANSLATE TRANSTRN TRANWRD TRIGAMMA TRIM TRIMN TRUNC TSO TYPEOF
82
+ TZONEID TZONENAME TZONEOFF TZONES2U TZONEU2S UNIFORM UPCASE
83
+ URLDECODE URLENCODE USS UUIDGEN VAR VARFMT VARINFMT VARLABEL
84
+ VARLEN VARNAME VARNUM VARRAY VARRAYX VARTYPE VERIFY VFORMAT
85
+ VFORMATD VFORMATDX VFORMATN VFORMATNX VFORMATW VFORMATWX VFORMATX
86
+ VINARRAY VINARRAYX VINFORMAT VINFORMATD VINFORMATDX VINFORMATN
87
+ VINFORMATNX VINFORMATW VINFORMATWX VINFORMATX VLABEL VLABELX
88
+ VLENGTH VLENGTHX VNAME VNAMEX VTYPE VTYPEX VVALUE VVALUEX WEEK
89
+ WEEKDAY WHICHC WHICHN WTO YEAR YIELDP YRDIF YYQ ZIPCITY
90
+ ZIPCITYDISTANCE ZIPFIPS ZIPNAME ZIPNAMEL ZIPSTATE
91
+ )
92
+ end
93
+
94
+ def self.sas_macro_statements
95
+ # from SAS 9.4 Macro Language Reference
96
+ # Chapter 12
97
+ @sas_macro_statements ||= Set.new %w(
98
+ %COPY %DISPLAY %GLOBAL %INPUT %LET %MACRO %PUT %SYMDEL %SYSCALL
99
+ %SYSEXEC %SYSLPUT %SYSMACDELETE %SYSMSTORECLEAR %SYSRPUT %WINDOW
100
+ %ABORT %DO %TO %UNTIL %WHILE %END %GOTO %IF %THEN %ELSE %LOCAL
101
+ %RETURN
102
+ %INCLUDE %LIST %RUN
103
+ )
104
+ # Omitted:
105
+ # %label: Identifies the destination of a %GOTO statement.
106
+ # %MEND
107
+ end
108
+
109
+ def self.sas_macro_functions
110
+ # from SAS 9.4 Macro Language Reference
111
+ # Chapter 12
112
+
113
+ @sas_macro_functions ||= Set.new %w(
114
+ %BQUOTE %NRBQUOTE %EVAL %INDEX %LENGTH %QUOTE %NRQUOTE %SCAN
115
+ %QSCAN %STR %NRSTR %SUBSTR %QSUBSTR %SUPERQ %SYMEXIST %SYMGLOBL
116
+ %SYMLOCAL %SYSEVALF %SYSFUNC %QSYSFUNC %SYSGET %SYSMACEXEC
117
+ %SYSMACEXIST %SYSMEXECDEPTH %SYSMEXECNAME %SYSPROD %UNQUOTE
118
+ %UPCASE %QUPCASE
119
+ )
120
+ end
121
+
122
+ def self.sas_auto_macro_vars
123
+ # from SAS 9.4 Macro Language Reference
124
+ # Chapter 12
125
+
126
+ @sas_auto_macro_vars ||= Set.new %w(
127
+ &SYSADDRBITS &SYSBUFFR &SYSCC &SYSCHARWIDTH &SYSCMD &SYSDATASTEPPHASE &SYSDATE
128
+ &SYSDATE9 &SYSDAY &SYSDEVIC &SYSDMG &SYSDSN &SYSENCODING &SYSENDIAN &SYSENV
129
+ &SYSERR &SYSERRORTEXT &SYSFILRC &SYSHOSTINFOLONG &SYSHOSTNAME &SYSINDEX
130
+ &SYSINFO &SYSJOBID &SYSLAST &SYSLCKRC &SYSLIBRC &SYSLOGAPPLNAME &SYSMACRONAME
131
+ &SYSMENV &SYSMSG &SYSNCPU &SYSNOBS &SYSODSESCAPECHAR &SYSODSPATH &SYSPARM
132
+ &SYSPBUFF &SYSPRINTTOLIST &SYSPRINTTOLOG &SYSPROCESSID &SYSPROCESSMODE
133
+ &SYSPROCESSNAME &SYSPROCNAME &SYSRC &SYSSCP &SYSSCPL &SYSSITE &SYSSIZEOFLONG
134
+ &SYSSIZEOFPTR &SYSSIZEOFUNICODE &SYSSTARTID &SYSSTARTNAME &SYSTCPIPHOSTNAME
135
+ &SYSTIME &SYSTIMEZONE &SYSTIMEZONEIDENT &SYSTIMEZONEOFFSET &SYSUSERID &SYSVER
136
+ &SYSVLONG &SYSVLONG4 &SYSWARNINGTEXT
137
+ )
138
+ end
139
+
140
+ def self.proc_keywords
141
+ # Create a hash with keywords for common PROCs, keyed by PROC name
142
+ @proc_keywords ||= {}
143
+
144
+ @proc_keywords["SQL"] ||= Set.new %w(
145
+ ALTER TABLE CONNECT CREATE INDEX VIEW DELETE DESCRIBE DISCONNECT DROP EXECUTE
146
+ INSERT RESET SELECT UPDATE VALIDATE ADD CONSTRAINT DROP FOREIGN KEY PRIMARY
147
+ MODIFY LIKE AS ORDER BY USING FROM INTO SET VALUES RESET DISTINCT UNIQUE
148
+ WHERE GROUP HAVING LEFT RIGHT INNER JOIN ON
149
+ )
150
+ # from SAS 9.4 SQL Procedure User's Guide
151
+
152
+ @proc_keywords["MEANS"] ||= Set.new %w(
153
+ BY CLASS FREQ ID OUTPUT OUT TYPES VAR WAYS WEIGHT
154
+ ATTRIB FORMAT LABEL WHERE
155
+ DESCENDING NOTSORTED
156
+ NOTHREADS NOTRAP PCTLDEF SUMSIZE THREADS CLASSDATA COMPLETETYPES
157
+ EXCLUSIVE MISSING FW MAXDEC NONOBS NOPRINT ORDER FORMATTED FREQ
158
+ UNFORMATTED PRINT PRINTALLTYPES PRINTIDVARS STACKODSOUTPUT
159
+ CHARTYPE DESCENDTYPES IDMIN
160
+ ALPHA EXCLNPWGT QMARKERS QMETHOD QNTLDEF VARDEF
161
+ CLM CSS CV KURTOSIS KURT LCLM MAX MEAN MIN MODE N
162
+ NMISS RANGE SKEWNESS SKEW STDDEV STD STDERR SUM SUMWGT UCLM USS VAR
163
+ MEDIAN P50 Q1 P25 Q3 P75 P1 P90 P5 P95 P10 P99 P20 P30 P40 P60 P70
164
+ P80 QRANGE
165
+ PROBT PRT T
166
+ ASCENDING GROUPINTERNAL MLF PRELOADFMT
167
+ MAXID AUTOLABEL AUTONAME KEEPLEN LEVELS NOINHERIT
168
+ )
169
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
170
+
171
+ @proc_keywords["DATASETS"] ||= Set.new %w(
172
+ AGE APPEND ATTRIB AUDIT CHANGE CONTENTS COPY DELETE EXCHANGE
173
+ EXCLUDE FORMAT IC CREATE DELETE REACTIVATE INDEX CENTILES INFORMAT
174
+ INITIATE LABEL LOG MODIFY REBUILD RENAME REPAIR RESUME SAVE SELECT
175
+ SUSPEND TERMINATE USER_VAR XATTR ADD OPTIONS REMOVE SET
176
+ )
177
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
178
+
179
+ @proc_keywords["SORT"] ||= Set.new %w(
180
+ BY DESCENDING KEY ASCENDING ASC DESC DATECOPY FORCE OVERWRITE
181
+ PRESORTED SORTSIZE TAGSORT DUPOUT OUT UNIQUEOUT NODUPKEY NOUNIQUEKEY
182
+ NOTHREADS THREADS EQUALS NOEQUALS
183
+ ATTRIB FORMAT LABEL WHERE
184
+ )
185
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
186
+
187
+ @proc_keywords["PRINT"] ||= Set.new %w(
188
+ BY DESCENDING NOTSORTED PAGEBY SUMBY ID STYLE SUM VAR CONTENTS DATA
189
+ GRANDTOTAL_LABEL HEADING LABEL SPLIT SUMLABEL NOSUMLABEL
190
+ BLANKLINE COUNT DOUBLE N NOOBS OBS ROUND
191
+ ROWS UNIFORM WIDTH
192
+ ATTRIB FORMAT LABEL WHERE
193
+ )
194
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
195
+
196
+ @proc_keywords["APPEND"] ||= Set.new %w(
197
+ BASE APPENDVER DATA ENCRYPTKEY FORCE GETSORT NOWARN
198
+ ATTRIB FORMAT LABEL WHERE
199
+ )
200
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
201
+
202
+ @proc_keywords["TRANSPOSE"] ||= Set.new %w(
203
+ DELIMITER LABEL LET NAME OUT PREFIX SUFFIX BY DESCENDING NOTSORTED
204
+ COPY ID IDLABEL VAR INDB
205
+ ATTRIB FORMAT LABEL WHERE
206
+ )
207
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
208
+
209
+ @proc_keywords["FREQ"] ||= Set.new %w(
210
+ BY EXACT OUTPUT TABLES TEST WEIGHT
211
+ COMPRESS DATA FORMCHAR NLEVELS NOPRINT ORDER PAGE FORMATTED FREQ
212
+ INTERNAL
213
+ AGREE BARNARD BINOMIAL BIN CHISQ COMOR EQOR ZELEN FISHER JT KAPPA
214
+ KENTB TAUB LRCHI MCNEM MEASURES MHCHI OR ODDSRATIO PCHI PCORR RELRISK
215
+ RISKDIFF SCORR SMDCR SMDRC STUTC TAUC TREND WTKAP WTKAPPA
216
+ OUT AJCHI ALL BDCHI CMH CMH1 CMH2 CMHCOR CMHGA CMHRMS COCHQ CONTGY
217
+ CRAMV EQKAP EQWKP GAMMA GS GAILSIMON LAMCR LAMDAS LAMRC LGOR LGRRC1
218
+ LGRRC2 MHOR MHRRC1 MHRRC2 N NMISS PHI PLCORR RDIF1 RDIF2 RISKDIFF1
219
+ RISKDIFF2 RRC1 RELRISK1 RRC2 RELRISK2 RSK1 RISK1 RSK11 RISK11 RSK12
220
+ RISK12 RSK21 RISK21 RSK22 RISK22 TSYMM BOWKER U UCR URC
221
+ CELLCHI2 CUMCOL DEVIATION EXPECTED MISSPRINT PEARSONREF PRINTWKTS
222
+ SCOROUT SPARSE STDRES TOTPCT
223
+ CONTENTS CROSSLIST FORMAT LIST MAXLEVELS NOCOL NOCUM NOFREQ NOPERCENT
224
+ NOPRINT NOROW NOSPARSE NOWARN PLOTS OUT OUTCUM OUTEXPECT OUTPCT
225
+ ZEROS
226
+ )
227
+ # from Base SAS 9.4 Procedures Guide: Statistical Procedures, Fourth Edition
228
+
229
+ @proc_keywords["CORR"] ||= Set.new %w(
230
+ BY FREQ ID PARTIAL VAR WEIGHT WITH
231
+ DATA OUTH OUTK OUTP OUTPLC OUTPLS OUTS
232
+ EXCLNPWGHT FISHER HOEFFDING KENDALL NOMISS PEARSON POLYCHORIC
233
+ POLYSERIAL ALPHA COV CSSCP SINGULAR SSCP VARDEF PLOTS MATRIX SCATTER
234
+ BEST NOCORR NOPRINT NOPROB NOSIMPLE RANK
235
+ )
236
+ # from Base SAS 9.4 Procedures Guide: Statistical Procedures, Fourth Edition
237
+
238
+ @proc_keywords["REPORT"] ||= Set.new %w(
239
+ BREAK BY DESCENDING NOTSORTED COLUMN COMPUTE STYLE LINE ENDCOMP
240
+ CALL DEFINE _ROW_ FREQ RBREAK WEIGHT
241
+ ATTRIB FORMAT LABEL WHERE
242
+ DATA NOALIAS NOCENTER NOCOMPLETECOLS NOCOMPLETEROWS NOTHREADS
243
+ NOWINDOWS OUT PCTLDEF THREADS WINDOWS COMPLETECOLS NOCOMPLETECOLS
244
+ COMPLETEROWS NOCOMPLETEROWS CONTENTS SPANROWS COMMAND HELP PROMPT
245
+ BOX BYPAGENO CENTER NOCENTER COLWIDTH FORMCHAR LS MISSING PANELS PS
246
+ PSPACE SHOWALL SPACING WRAP EXCLNPWGT QMARKERS QMETHOD QNTLDEF VARDEF
247
+ NAMED NOHEADER SPLIT HEADLINE HEADSKIP LIST NOEXEC OUTREPT PROFILE
248
+ REPORT
249
+ COLOR DOL DUL OL PAGE SKIP SUMMARIZE SUPPRESS UL
250
+ BLINK COMMAND HIGHLIGHT RVSVIDEO MERGE REPLACE URL URLBP URLP
251
+ AFTER BEFORE _PAGE_ LEFT RIGHT CHARACTER LENGTH
252
+ EXCLUSIVE MISSING MLF ORDER DATA FORMATTED FREQ INTERNAL PRELOADFMT
253
+ WIDTH
254
+ ACROSS ANALYSIS COMPUTED DISPLAY GROUP ORDER
255
+ CONTENTS FLOW ID NOPRINT NOZERO PAGE
256
+ CSS CV MAX MEAN MIN MODE N NMISS PCTN PCTSUM RANGE STD STDERR SUM
257
+ SUMWGT USS VAR
258
+ MEDIAN P50 Q1 P25 Q3 P75 P1 P90 P5 P95 P10 P99 P20 P30 P40 P60 P70
259
+ P80 QRANGE
260
+ PROBT PRT T
261
+ )
262
+ # from BASE SAS 9.4 Procedures Guide, Fifth Edition
263
+
264
+ @proc_keywords["METALIB"] ||= Set.new %w(
265
+ OMR DBAUTH DBUSER DBPASSWORD EXCLUDE SELECT READ FOLDER FOLDERID
266
+ IMPACT_LIMIT NOEXEC PREFIX REPORT UPDATE_RULE DELETE NOADD NODELDUP
267
+ NOUPDATE
268
+ LIBID LIBRARY LIBURI
269
+ TYPE DETAIL SUMMARY
270
+ )
271
+ # from SAS 9.4 Language Interfaces to Metadata, Third Edition
272
+
273
+ @proc_keywords["GCHART"] ||= Set.new %w(
274
+ DATA ANNOTATE GOUT IMAGEMAP BLOCK HBAR HBAR3D VBAR VBAR3D PIE PIE3D
275
+ DONUT STAR ANNO
276
+ BY NOTE FORMAT LABEL WHERE
277
+ BLOCKMAX CAXIS COUTLINE CTEXT LEGEND NOHEADING NOLEGEND PATTERNID
278
+ GROUP MIDPOINT SUBGROUP WOUTLINE DESCRIPTION NAME DISCRETE LEVELS
279
+ OLD MISSING HTML_LEGEND HTML URL FREQ G100 SUMVAR TYPE
280
+ CAUTOREF CERROR CFRAME CLM CREF FRAME NOFRAME GSPACE IFRAME
281
+ IMAGESTYLE TILE FIT LAUTOREF NOSYMBOL PATTERNID SHAPE SPACE
282
+ SUBOUTSIDE WAUTOREF WIDTH WOUTLINE WREF
283
+ ASCENDING AUTOREF CLIPREF DESCENDING FRONTREF GAXIS MAXIS MINOR
284
+ NOAXIS NOBASEREF NOZERO RANGE AXIS REF CFREQ CFREQLABEL NONE CPERCENT
285
+ CPERCENTLABEL ERRORBAR BARS BOTH TOP FREQLABEL INSIDE MEAN MEANLABEL
286
+ NOSTATS OUTSIDE PERCENT PERCENTLABEL PERCENTSUM SUM
287
+ CFILL COUTLINE DETAIL_RADIUS EXPLODE FILL SOLID X INVISIBLE NOHEADING
288
+ RADIUS WOUTLINE DETAIL_THRESHOLD DETAIL_PERCENT DETAIL_SLICE
289
+ DETAIL_VALUE DONUTPCT LABEL ACROSS DOWN GROUP NOGROUPHEADING SUBGROUP
290
+ MATCHCOLOR OTHERCOLOR OTHERLABEL PERCENT ARROW PLABEL PPERCENT SLICE
291
+ VALUE
292
+ ANGLE ASCENDING CLOCKWISE DESCENDING JSTYLE
293
+ NOCONNECT STARMAX STARMIN
294
+ )
295
+ # from SAS GRAPH 9.4 Reference, Fourth Edition
296
+
297
+ @proc_keywords["GPLOT"] ||= Set.new %w(
298
+ DATA ANNOTATE GOUT IMAGEMAP UNIFORM BUBBLE BUBBLE2 PLOT PLOT2
299
+ BCOLOR BFILL BFONT BLABEL BSCALE AREA RADIUS BSIZE DESCRIPTION NAME
300
+ AUTOHREF CAUTOHREF CHREF HAXIS HMINOR HREF HREVERSE HZERO LAUTOHREF
301
+ LHREF WAUTOHREF WHREF HTML URL
302
+ CAXIS CFRAME CTEXT DATAORDER FRAME NOFRAME FRONTREF GRID IFRAME
303
+ IMAGESTYLE TILE FIT NOAXIS
304
+ AUTOVREF CAUTOVREF CVREF LAUTOVREF LVREF VAXIS VMINOR VREF VREVERSE
305
+ VZERO WAUTOVREF WVREF
306
+ CBASELINE COUTLINE
307
+ AREAS GRID LEGEND NOLASTAREA NOLEGEND OVERLAY REGEQN SKIPMISS
308
+ )
309
+ # from SAS GRAPH 9.4 Reference, Fourth Edition
310
+
311
+ @proc_keywords["REG"] ||= Set.new %w(
312
+ MODEL BY FREQ ID VAR WEIGHT ADD CODE DELETE MTEST OUTPUT PAINT
313
+ PLOT PRINT REFIT RESTRICT REWEIGHT STORE TEST
314
+ )
315
+ # from SAS/STAT 15.1 User's Guide
316
+
317
+ @proc_keywords["SGPLOT"] ||= Set.new %w(
318
+ STYLEATTRS BAND X Y UPPER LOWER BLOCK BUBBLE DENSITY DOT DROPLINE
319
+ ELLIPSE ELLIPSEPARM FRINGE GRADLEGEND HBAR HBARBASIC HBARPARM
320
+ HBOX HEATMAP HEATMAPPARM HIGHLOW HISTOGRAM HLINE INSET KEYLEGEND
321
+ LINEPARM LOESS NEEDLE PBSPLINE POLYGON REFLINE REG SCATTER SERIES
322
+ SPLINE STEP SYMBOLCHAR SYMBOLIMAGE TEXT VBAR VBARBASIC VBARPARM
323
+ VBOX VECTOR VLINE WATERFALL XAXIS X2AXIS XAXISTABLE YAXIS Y2AXIS
324
+ YAXISTABLE
325
+ )
326
+ # from ODS Graphics: Procedures Guide, Sixth Edition
327
+ return @proc_keywords
328
+ end
329
+
330
+ def self.sas_proc_names
331
+ # from SAS Procedures by Name
332
+ # http://support.sas.com/documentation/cdl/en/allprodsproc/68038/HTML/default/viewer.htm#procedures.htm
333
+
334
+ @sas_proc_names ||= Set.new %w(
335
+ ACCESS ACECLUS ADAPTIVEREG ALLELE ANOM ANOVA APPEND APPSRV ARIMA
336
+ AUTHLIB AUTOREG BCHOICE BOM BOXPLOT BTL BUILD CALENDAR CALIS CALLRFC
337
+ CANCORR CANDISC CAPABILITY CASECONTROL CATALOG CATMOD CDISC CDISC
338
+ CHART CIMPORT CLP CLUSTER COMPARE COMPILE COMPUTAB CONTENTS CONVERT
339
+ COPULA COPY CORR CORRESP COUNTREG CPM CPORT CUSUM CV2VIEW DATEKEYS
340
+ DATASETS DATASOURCE DB2EXT DB2UTIL DBCSTAB DBF DBLOAD DELETE DIF
341
+ DISCRIM DISPLAY DISTANCE DMSRVADM DMSRVDATASVC DMSRVPROCESSSVC
342
+ DOCUMENT DOWNLOAD DQLOCLST DQMATCH DQSCHEME DS2 DTREE ENTROPY ESM
343
+ EXPAND EXPLODE EXPORT FACTEX FACTOR FAMILY FASTCLUS FCMP FEDSQL FMM
344
+ FONTREG FORECAST FORMAT FORMS FREQ FSBROWSE FSEDIT FSLETTER FSLIST
345
+ FSVIEW G3D G3GRID GA GAM GAMPL GANNO GANTT GAREABAR GBARLINE GCHART
346
+ GCONTOUR GDEVICE GEE GENESELECT GENMOD GEOCODE GFONT GINSIDE GIS GKPI
347
+ GLIMMIX GLM GLMMOD GLMPOWER GLMSELECT GMAP GOPTIONS GPLOT GPROJECT
348
+ GRADAR GREDUCE GREMOVE GREPLAY GROOVY GSLIDE GTILE HADOOP HAPLOTYPE
349
+ HDMD HPBIN HPCANDISC HPCDM HPCOPULA HPCORR HPCOUNTREG HPDMDB HPDS2
350
+ HPFMM HPGENSELECT HPIMPUTE HPLMIXED HPLOGISTIC HPMIXED HPNLMOD
351
+ HPPANEL HPPLS HPPRINCOMP HPQUANTSELECT HPQLIM HPREG HPSAMPLE
352
+ HPSEVERITY HPSPLIT HPSUMMARY HTSNP HTTP ICLIFETEST ICPHREG IML IMPORT
353
+ IMSTAT IMXFER INBREED INFOMAPS INTPOINT IOMOPERATE IRT ISHIKAWA ITEMS
354
+ JAVAINFO JSON KDE KRIGE2D LASR LATTICE LIFEREG LIFETEST LOAN
355
+ LOCALEDATA LOESS LOGISTIC LP LUA MACONTROL MAPIMPORT MCMC MDC MDDB
356
+ MDS MEANS METADATA METALIB METAOPERATE MI MIANALYZE MIGRATE MIXED
357
+ MODECLUS MODEL MSCHART MULTTEST MVPDIAGNOSE MVPMODEL MVPMONITOR
358
+ NESTED NETDRAW NETFLOW NLIN NLMIXED NLP NPAR1WAY ODSLIST ODSTABLE
359
+ ODSTEXT OLAP OLAPCONTENTS OLAPOPERATE OPERATE OPTEX OPTGRAPH OPTIONS
360
+ OPTLOAD OPTLP OPTLSO OPTMILP OPTMODEL OPTNET OPTQP OPTSAVE ORTHOREG
361
+ PANEL PARETO PDLREG PDS PDSCOPY PHREG PLAN PLM PLOT PLS PM PMENU
362
+ POWER PRESENV PRINCOMP PRINQUAL PRINT PRINTTO PROBIT PROTO PRTDEF
363
+ PRTEXP PSMOOTH PWENCODE QDEVICE QLIM QUANTLIFE QUANTREG QUANTSELECT
364
+ QUEST RANK RAREEVENTS RDC RDPOOL RDSEC RECOMMEND REG REGISTRY RELEASE
365
+ RELIABILITY REPORT RISK ROBUSTREG RSREG SCAPROC SCORE SEQDESIGN
366
+ SEQTEST SERVER SEVERITY SGDESIGN SGPANEL SGPLOT SGRENDER SGSCATTER
367
+ SHEWHART SIM2D SIMILARITY SIMLIN SIMNORMAL SOAP SORT SOURCE SPECTRA
368
+ SPP SQL SQOOP SSM STANDARD STATESPACE STDIZE STDRATE STEPDISC STP
369
+ STREAM SUMMARY SURVEYFREQ SURVEYIMPUTE SURVEYLOGISTIC SURVEYMEANS
370
+ SURVEYPHREG SURVEYREG SURVEYSELECT SYSLIN TABULATE TAPECOPY TAPELABEL
371
+ TEMPLATE TIMEDATA TIMEID TIMEPLOT TIMESERIES TPSPLINE TRANSPOSE
372
+ TRANSREG TRANTAB TREE TSCSREG TTEST UCM UNIVARIATE UPLOAD VARCLUS
373
+ VARCOMP VARIOGRAM VARMAX VASMP X11 X12 X13 XSL
374
+ )
375
+ end
376
+
377
+ state :basics do
378
+ # Rules to be parsed before the keywords (which are different depending
379
+ # on the context)
380
+
381
+ rule %r/\s+/m, Text
382
+
383
+ # Single-line comments (between * and ;) - these can actually go onto multiple lines
384
+ # case 1 - where it starts a line
385
+ rule %r/^\s*%?\*[^;]*;/m, Comment::Single
386
+ # case 2 - where it follows the previous statement on the line (after a semicolon)
387
+ rule %r/(;)(\s*)(%?\*[^;]*;)/m do
388
+ groups Punctuation, Text, Comment::Single
389
+ end
390
+
391
+ # True multiline comments!
392
+ rule %r(/[*].*?[*]/)m, Comment::Multiline
393
+
394
+ # date/time constants (Language Reference pp91-2)
395
+ rule %r/'[0-9a-z]+?'d/i, Literal::Date
396
+ rule %r/'.+?'dt/i, Literal::Date
397
+ rule %r/'[0-9:]+?([a|p]m)?'t/i, Literal::Date
398
+
399
+ rule %r/'/, Str::Single, :single_string
400
+ rule %r/"/, Str::Double, :double_string
401
+ rule %r/&[a-z0-9_&.]+/i, Name::Variable
402
+
403
+ # numeric constants (Language Reference p91)
404
+ rule %r/\d[0-9a-f]*x/i, Num::Hex
405
+ rule %r/\d[0-9e\-.]+/i, Num # scientific notation
406
+
407
+ # auto variables from DATA step (Language Reference p46, p37)
408
+ rule %r/\b(_n_|_error_|_file_|_infile_|_msg_|_iorc_|_cmd_)\b/i, Name::Builtin::Pseudo
409
+
410
+ # auto variable list names
411
+ rule %r/\b(_character_|_numeric_|_all_)\b/i, Name::Builtin
412
+
413
+ # datalines/cards etc
414
+ rule %r/\b(datalines|cards)(\s*)(;)/i do
415
+ groups Keyword, Text, Punctuation
416
+ push :datalines
417
+ end
418
+ rule %r/\b(datalines4|cards4)(\s*)(;)/i do
419
+ groups Keyword, Text, Punctuation
420
+ push :datalines4
421
+ end
422
+
423
+
424
+ # operators (Language Reference p96)
425
+ rule %r(\*\*|[\*/\+-]), Operator
426
+ rule %r/[^¬~]?=:?|[<>]=?:?/, Operator
427
+ rule %r/\b(eq|ne|gt|lt|ge|le|in)\b/i, Operator::Word
428
+ rule %r/[&|!¦¬∘~]/, Operator
429
+ rule %r/\b(and|or|not)\b/i, Operator::Word
430
+ rule %r/(<>|><)/, Operator # min/max
431
+ rule %r/\|\|/, Operator # concatenation
432
+
433
+ # The OF operator should also be highlighted (Language Reference p49)
434
+ rule %r/\b(of)\b/i, Operator::Word
435
+ rule %r/\b(like)\b/i, Operator::Word # Language Ref p181
436
+
437
+ rule %r/\d+/, Num::Integer
438
+
439
+ rule %r/\$/, Keyword::Type
440
+
441
+ # Macro definitions
442
+ rule %r/(%macro|%mend)(\s*)(\w+)/i do
443
+ groups Keyword, Text, Name::Function
444
+ end
445
+ rule %r/%mend/, Keyword
446
+
447
+ rule %r/%\w+/ do |m|
448
+ if self.class.sas_macro_statements.include? m[0].upcase
449
+ token Keyword
450
+ elsif self.class.sas_macro_functions.include? m[0].upcase
451
+ token Keyword
452
+ else
453
+ token Name
454
+ end
455
+ end
456
+ end
457
+
458
+ state :basics2 do
459
+ # Rules to be parsed after the keywords (which are different depending
460
+ # on the context)
461
+
462
+ # Missing values (Language Reference p81)
463
+ rule %r/\s\.[;\s]/, Keyword::Constant # missing
464
+ rule %r/\s\.[a-z_]/, Name::Constant # user-defined missing
465
+
466
+ rule %r/[\(\),;:\{\}\[\]\\\.]/, Punctuation
467
+
468
+ rule %r/@/, Str::Symbol # line hold specifiers
469
+ rule %r/\?/, Str::Symbol # used for format modifiers
470
+
471
+ rule %r/[^\s]+/, Text # Fallback for anything we haven't matched so far
472
+ end
473
+
474
+ state :root do
475
+ mixin :basics
476
+
477
+ # PROC definitions
478
+ rule %r!(proc)(\s+)(\w+)!ix do |m|
479
+ @proc_name = m[3].upcase
480
+ puts " proc name: #{@proc_name}" if @debug
481
+ if self.class.sas_proc_names.include? @proc_name
482
+ groups Keyword, Text, Keyword
483
+ else
484
+ groups Keyword, Text, Name
485
+ end
486
+
487
+ push :proc
488
+ end
489
+
490
+ # Data step definitions
491
+ rule %r/(data)(\s+)([\w\.]+)/i do
492
+ groups Keyword, Text, Name::Variable
493
+ end
494
+ # Libname definitions
495
+ rule %r/(libname)(\s+)(\w+)/i do
496
+ groups Keyword, Text, Name::Variable
497
+ end
498
+
499
+ rule %r/\w+/ do |m|
500
+ if self.class.data_step_statements.include? m[0].upcase
501
+ token Keyword
502
+ elsif self.class.sas_functions.include? m[0].upcase
503
+ token Keyword
504
+ else
505
+ token Name
506
+ end
507
+ end
508
+
509
+ mixin :basics2
510
+ end
511
+
512
+
513
+ state :single_string do
514
+ rule %r/''/, Str::Escape
515
+ rule %r/'/, Str::Single, :pop!
516
+ rule %r/[^']+/, Str::Single
517
+ end
518
+
519
+ state :double_string do
520
+ rule %r/&[a-z0-9_&]+\.?/i, Str::Interpol
521
+ rule %r/""/, Str::Escape
522
+ rule %r/"/, Str::Double, :pop!
523
+
524
+ rule %r/[^&"]+/, Str::Double
525
+ # Allow & to be used as character if not already matched as macro variable
526
+ rule %r/&/, Str::Double
527
+ end
528
+
529
+ state :datalines do
530
+ rule %r/[^;]/, Literal::String::Heredoc
531
+ rule %r/;/, Punctuation, :pop!
532
+ end
533
+
534
+ state :datalines4 do
535
+ rule %r/;{4}/, Punctuation, :pop!
536
+ rule %r/[^;]/, Literal::String::Heredoc
537
+ rule %r/;{,3}/, Literal::String::Heredoc
538
+ end
539
+
540
+
541
+ # PROCS
542
+ state :proc do
543
+ rule %r/(quit|run)/i, Keyword, :pop!
544
+
545
+ mixin :basics
546
+ rule %r/\w+/ do |m|
547
+ if self.class.data_step_statements.include? m[0].upcase
548
+ token Keyword
549
+ elsif self.class.sas_functions.include? m[0].upcase
550
+ token Keyword
551
+ elsif self.class.proc_keywords.has_key?(@proc_name) and self.class.proc_keywords[@proc_name].include? m[0].upcase
552
+ token Keyword
553
+ else
554
+ token Name
555
+ end
556
+ end
557
+
558
+ mixin :basics2
559
+ end
560
+
561
+ end #class SAS
562
+ end #module Lexers
563
+ end #module Rouge