rugments 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +52 -0
  3. data/README.md +195 -0
  4. data/bin/rugmentize +6 -0
  5. data/lib/rugments/cli.rb +357 -0
  6. data/lib/rugments/formatter.rb +29 -0
  7. data/lib/rugments/formatters/html.rb +142 -0
  8. data/lib/rugments/formatters/null.rb +17 -0
  9. data/lib/rugments/formatters/terminal256.rb +174 -0
  10. data/lib/rugments/lexer.rb +431 -0
  11. data/lib/rugments/lexers/apache/keywords.yml +453 -0
  12. data/lib/rugments/lexers/apache.rb +67 -0
  13. data/lib/rugments/lexers/apple_script.rb +366 -0
  14. data/lib/rugments/lexers/c.rb +210 -0
  15. data/lib/rugments/lexers/clojure.rb +109 -0
  16. data/lib/rugments/lexers/coffeescript.rb +172 -0
  17. data/lib/rugments/lexers/common_lisp.rb +343 -0
  18. data/lib/rugments/lexers/conf.rb +22 -0
  19. data/lib/rugments/lexers/cpp.rb +63 -0
  20. data/lib/rugments/lexers/csharp.rb +85 -0
  21. data/lib/rugments/lexers/css.rb +269 -0
  22. data/lib/rugments/lexers/dart.rb +102 -0
  23. data/lib/rugments/lexers/diff.rb +39 -0
  24. data/lib/rugments/lexers/elixir.rb +105 -0
  25. data/lib/rugments/lexers/erb.rb +54 -0
  26. data/lib/rugments/lexers/erlang.rb +116 -0
  27. data/lib/rugments/lexers/factor.rb +300 -0
  28. data/lib/rugments/lexers/gherkin/keywords.rb +13 -0
  29. data/lib/rugments/lexers/gherkin.rb +135 -0
  30. data/lib/rugments/lexers/go.rb +176 -0
  31. data/lib/rugments/lexers/groovy.rb +102 -0
  32. data/lib/rugments/lexers/haml.rb +226 -0
  33. data/lib/rugments/lexers/handlebars.rb +77 -0
  34. data/lib/rugments/lexers/haskell.rb +181 -0
  35. data/lib/rugments/lexers/html.rb +92 -0
  36. data/lib/rugments/lexers/http.rb +78 -0
  37. data/lib/rugments/lexers/ini.rb +55 -0
  38. data/lib/rugments/lexers/io.rb +66 -0
  39. data/lib/rugments/lexers/java.rb +74 -0
  40. data/lib/rugments/lexers/javascript.rb +258 -0
  41. data/lib/rugments/lexers/literate_coffeescript.rb +31 -0
  42. data/lib/rugments/lexers/literate_haskell.rb +34 -0
  43. data/lib/rugments/lexers/llvm.rb +82 -0
  44. data/lib/rugments/lexers/lua/builtins.rb +21 -0
  45. data/lib/rugments/lexers/lua.rb +120 -0
  46. data/lib/rugments/lexers/make.rb +114 -0
  47. data/lib/rugments/lexers/markdown.rb +151 -0
  48. data/lib/rugments/lexers/matlab/builtins.rb +10 -0
  49. data/lib/rugments/lexers/matlab.rb +70 -0
  50. data/lib/rugments/lexers/moonscript.rb +108 -0
  51. data/lib/rugments/lexers/nginx.rb +69 -0
  52. data/lib/rugments/lexers/nim.rb +149 -0
  53. data/lib/rugments/lexers/objective_c.rb +188 -0
  54. data/lib/rugments/lexers/ocaml.rb +109 -0
  55. data/lib/rugments/lexers/perl.rb +195 -0
  56. data/lib/rugments/lexers/php/builtins.rb +192 -0
  57. data/lib/rugments/lexers/php.rb +162 -0
  58. data/lib/rugments/lexers/plain_text.rb +23 -0
  59. data/lib/rugments/lexers/prolog.rb +62 -0
  60. data/lib/rugments/lexers/properties.rb +53 -0
  61. data/lib/rugments/lexers/puppet.rb +126 -0
  62. data/lib/rugments/lexers/python.rb +225 -0
  63. data/lib/rugments/lexers/qml.rb +70 -0
  64. data/lib/rugments/lexers/r.rb +55 -0
  65. data/lib/rugments/lexers/racket.rb +540 -0
  66. data/lib/rugments/lexers/ruby.rb +413 -0
  67. data/lib/rugments/lexers/rust.rb +188 -0
  68. data/lib/rugments/lexers/sass/common.rb +172 -0
  69. data/lib/rugments/lexers/sass.rb +72 -0
  70. data/lib/rugments/lexers/scala.rb +140 -0
  71. data/lib/rugments/lexers/scheme.rb +109 -0
  72. data/lib/rugments/lexers/scss.rb +32 -0
  73. data/lib/rugments/lexers/sed.rb +167 -0
  74. data/lib/rugments/lexers/shell.rb +150 -0
  75. data/lib/rugments/lexers/slim.rb +222 -0
  76. data/lib/rugments/lexers/smalltalk.rb +114 -0
  77. data/lib/rugments/lexers/sml.rb +345 -0
  78. data/lib/rugments/lexers/sql.rb +138 -0
  79. data/lib/rugments/lexers/swift.rb +153 -0
  80. data/lib/rugments/lexers/tcl.rb +189 -0
  81. data/lib/rugments/lexers/tex.rb +70 -0
  82. data/lib/rugments/lexers/toml.rb +68 -0
  83. data/lib/rugments/lexers/vb.rb +162 -0
  84. data/lib/rugments/lexers/viml/keywords.rb +11 -0
  85. data/lib/rugments/lexers/viml.rb +99 -0
  86. data/lib/rugments/lexers/xml.rb +57 -0
  87. data/lib/rugments/lexers/yaml.rb +362 -0
  88. data/lib/rugments/plugins/redcarpet.rb +28 -0
  89. data/lib/rugments/regex_lexer.rb +432 -0
  90. data/lib/rugments/template_lexer.rb +23 -0
  91. data/lib/rugments/text_analyzer.rb +46 -0
  92. data/lib/rugments/theme.rb +202 -0
  93. data/lib/rugments/themes/base16.rb +128 -0
  94. data/lib/rugments/themes/colorful.rb +65 -0
  95. data/lib/rugments/themes/github.rb +69 -0
  96. data/lib/rugments/themes/monokai.rb +88 -0
  97. data/lib/rugments/themes/monokai_sublime.rb +89 -0
  98. data/lib/rugments/themes/thankful_eyes.rb +69 -0
  99. data/lib/rugments/token.rb +180 -0
  100. data/lib/rugments/util.rb +99 -0
  101. data/lib/rugments/version.rb +3 -0
  102. data/lib/rugments.rb +33 -0
  103. metadata +149 -0
@@ -0,0 +1,109 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Clojure < RegexLexer
4
+ title 'Clojure'
5
+ desc 'The Clojure programming language (clojure.org)'
6
+
7
+ tag 'clojure'
8
+ aliases 'clj', 'cljs'
9
+
10
+ filenames '*.clj', '*.cljs'
11
+
12
+ mimetypes 'text/x-clojure', 'application/x-clojure'
13
+
14
+ def self.keywords
15
+ @keywords ||= Set.new %w(
16
+ fn def defn defmacro defmethod defmulti defn- defstruct if
17
+ cond let for
18
+ )
19
+ end
20
+
21
+ def self.builtins
22
+ @builtins ||= Set.new %w(
23
+ . .. * + - -> / < <= = == > >= accessor agent agent-errors
24
+ aget alength all-ns alter and append-child apply array-map
25
+ aset aset-boolean aset-byte aset-char aset-double aset-float
26
+ aset-int aset-long aset-short assert assoc await await-for bean
27
+ binding bit-and bit-not bit-or bit-shift-left bit-shift-right
28
+ bit-xor boolean branch? butlast byte cast char children
29
+ class clear-agent-errors comment commute comp comparator
30
+ complement concat conj cons constantly construct-proxy
31
+ contains? count create-ns create-struct cycle dec deref
32
+ difference disj dissoc distinct doall doc dorun doseq dosync
33
+ dotimes doto double down drop drop-while edit end? ensure eval
34
+ every? false? ffirst file-seq filter find find-doc find-ns
35
+ find-var first float flush fnseq frest gensym get-proxy-class
36
+ get hash-map hash-set identical? identity if-let import in-ns
37
+ inc index insert-child insert-left insert-right inspect-table
38
+ inspect-tree instance? int interleave intersection into
39
+ into-array iterate join key keys keyword keyword? last lazy-cat
40
+ lazy-cons left lefts line-seq list* list load load-file locking
41
+ long loop macroexpand macroexpand-1 make-array make-node map
42
+ map-invert map? mapcat max max-key memfn merge merge-with meta
43
+ min min-key name namespace neg? new newline next nil? node not
44
+ not-any? not-every? not= ns-imports ns-interns ns-map ns-name
45
+ ns-publics ns-refers ns-resolve ns-unmap nth nthrest or parse
46
+ partial path peek pop pos? pr pr-str print print-str println
47
+ println-str prn prn-str project proxy proxy-mappings quot
48
+ rand rand-int range re-find re-groups re-matcher re-matches
49
+ re-pattern re-seq read read-line reduce ref ref-set refer rem
50
+ remove remove-method remove-ns rename rename-keys repeat replace
51
+ replicate resolve rest resultset-seq reverse rfirst right
52
+ rights root rrest rseq second select select-keys send send-off
53
+ seq seq-zip seq? set short slurp some sort sort-by sorted-map
54
+ sorted-map-by sorted-set special-symbol? split-at split-with
55
+ str string? struct struct-map subs subvec symbol symbol?
56
+ sync take take-nth take-while test time to-array to-array-2d
57
+ tree-seq true? union up update-proxy val vals var-get var-set
58
+ var? vector vector-zip vector? when when-first when-let
59
+ when-not with-local-vars with-meta with-open with-out-str
60
+ xml-seq xml-zip zero? zipmap zipper'
61
+ )
62
+ end
63
+
64
+ identifier = %r{[\w!$%*+,<=>?/.-]+}
65
+ keyword = %r{[\w!\#$%*+,<=>?/.-]+}
66
+
67
+ def name_token(name)
68
+ return Keyword if self.class.keywords.include?(name)
69
+ return Name::Builtin if self.class.builtins.include?(name)
70
+ nil
71
+ end
72
+
73
+ state :root do
74
+ rule /;.*?\n/, Comment::Single
75
+ rule /\s+/m, Text::Whitespace
76
+
77
+ rule /-?\d+\.\d+/, Num::Float
78
+ rule /-?\d+/, Num::Integer
79
+ rule /0x-?[0-9a-fA-F]+/, Num::Hex
80
+
81
+ rule /"(\\.|[^"])*"/, Str
82
+ rule /'#{keyword}/, Str::Symbol
83
+ rule /::?#{keyword}/, Name::Constant
84
+ rule /\\(.|[a-z]+)/i, Str::Char
85
+
86
+ rule /~@|[`\'#^~&]/, Operator
87
+
88
+ rule /(\()(\s*)(#{identifier})/m do |m|
89
+ token Punctuation, m[1]
90
+ token Text::Whitespace, m[2]
91
+ token(name_token(m[3]) || Name::Function, m[3])
92
+ end
93
+
94
+ rule identifier do |m|
95
+ token name_token(m[0]) || Name
96
+ end
97
+
98
+ # vectors
99
+ rule /[\[\]]/, Punctuation
100
+
101
+ # maps
102
+ rule /[{}]/, Punctuation
103
+
104
+ # parentheses
105
+ rule /[()]/, Punctuation
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,172 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Coffeescript < RegexLexer
4
+ tag 'coffeescript'
5
+ aliases 'coffee', 'coffee-script'
6
+ filenames '*.coffee', 'Cakefile'
7
+ mimetypes 'text/coffeescript'
8
+
9
+ title 'CoffeeScript'
10
+ desc 'The Coffeescript programming language (coffeescript.org)'
11
+
12
+ def self.analyze_text(text)
13
+ return 1 if text.shebang? 'coffee'
14
+ end
15
+
16
+ def self.keywords
17
+ @keywords ||= Set.new %w(
18
+ for in of while break return continue switch when then if else
19
+ throw try catch finally new delete typeof instanceof super
20
+ extends this class by
21
+ )
22
+ end
23
+
24
+ def self.constants
25
+ @constants ||= Set.new %w(
26
+ true false yes no on off null NaN Infinity undefined
27
+ )
28
+ end
29
+
30
+ def self.builtins
31
+ @builtins ||= Set.new %w(
32
+ Array Boolean Date Error Function Math netscape Number Object
33
+ Packages RegExp String sun decodeURI decodeURIComponent
34
+ encodeURI encodeURIComponent eval isFinite isNaN parseFloat
35
+ parseInt document window
36
+ )
37
+ end
38
+
39
+ id = /[$a-zA-Z_][a-zA-Z0-9_]*/
40
+
41
+ state :comments_and_whitespace do
42
+ rule /\s+/m, Text
43
+ rule /###.*?###/m, Comment::Multiline
44
+ rule /#.*?\n/, Comment::Single
45
+ end
46
+
47
+ state :multiline_regex do
48
+ # this order is important, so that #{ isn't interpreted
49
+ # as a comment
50
+ mixin :has_interpolation
51
+ mixin :comments_and_whitespace
52
+
53
+ rule %r{///([gim]+\b|\B)}, Str::Regex, :pop!
54
+ rule %r{/}, Str::Regex
55
+ rule %r{[^/#]+}, Str::Regex
56
+ end
57
+
58
+ state :slash_starts_regex do
59
+ mixin :comments_and_whitespace
60
+ rule %r{///} do
61
+ token Str::Regex
62
+ goto :multiline_regex
63
+ end
64
+
65
+ rule %r{
66
+ /(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
67
+ ([gim]+\b|\B)
68
+ }x, Str::Regex, :pop!
69
+
70
+ rule(//) { pop! }
71
+ end
72
+
73
+ state :root do
74
+ rule(%r{^(?=\s|/|<!--)}) { push :slash_starts_regex }
75
+ mixin :comments_and_whitespace
76
+ rule %r{
77
+ [+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
78
+ [|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
79
+ }x, Operator, :slash_starts_regex
80
+
81
+ rule /[-=]>/, Name::Function
82
+
83
+ rule /(@)([ \t]*)(#{id})/ do
84
+ groups Name::Variable::Instance, Text, Name::Attribute
85
+ push :slash_starts_regex
86
+ end
87
+
88
+ rule /([.])([ \t]*)(#{id})/ do
89
+ groups Punctuation, Text, Name::Attribute
90
+ push :slash_starts_regex
91
+ end
92
+
93
+ rule /#{id}(?=\s*:)/, Name::Attribute, :slash_starts_regex
94
+
95
+ rule /#{id}/ do |m|
96
+ if self.class.keywords.include? m[0]
97
+ token Keyword
98
+ elsif self.class.constants.include? m[0]
99
+ token Name::Constant
100
+ elsif self.class.builtins.include? m[0]
101
+ token Name::Builtin
102
+ else
103
+ token Name::Other
104
+ end
105
+
106
+ push :slash_starts_regex
107
+ end
108
+
109
+ rule /[{(\[;,]/, Punctuation, :slash_starts_regex
110
+ rule /[})\].]/, Punctuation
111
+
112
+ rule /\d+[.]\d+([eE]\d+)?[fd]?/, Num::Float
113
+ rule /0x[0-9a-fA-F]+/, Num::Hex
114
+ rule /\d+/, Num::Integer
115
+ rule /"""/, Str, :tdqs
116
+ rule /'''/, Str, :tsqs
117
+ rule /"/, Str, :dqs
118
+ rule /'/, Str, :sqs
119
+ end
120
+
121
+ state :strings do
122
+ # all coffeescript strings are multi-line
123
+ rule /[^#\\'"]+/m, Str
124
+
125
+ rule /\\./, Str::Escape
126
+ rule /#/, Str
127
+ end
128
+
129
+ state :double_strings do
130
+ rule /'/, Str
131
+ mixin :has_interpolation
132
+ mixin :strings
133
+ end
134
+
135
+ state :single_strings do
136
+ rule /"/, Str
137
+ mixin :strings
138
+ end
139
+
140
+ state :interpolation do
141
+ rule /}/, Str::Interpol, :pop!
142
+ mixin :root
143
+ end
144
+
145
+ state :has_interpolation do
146
+ rule /[#][{]/, Str::Interpol, :interpolation
147
+ end
148
+
149
+ state :dqs do
150
+ rule /"/, Str, :pop!
151
+ mixin :double_strings
152
+ end
153
+
154
+ state :tdqs do
155
+ rule /"""/, Str, :pop!
156
+ rule /"/, Str
157
+ mixin :double_strings
158
+ end
159
+
160
+ state :sqs do
161
+ rule /'/, Str, :pop!
162
+ mixin :single_strings
163
+ end
164
+
165
+ state :tsqs do
166
+ rule /'''/, Str, :pop!
167
+ rule /'/, Str
168
+ mixin :single_strings
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,343 @@
1
+ module Rugments
2
+ module Lexers
3
+ class CommonLisp < RegexLexer
4
+ title 'Common Lisp'
5
+ desc 'The Common Lisp variant of Lisp (common-lisp.net)'
6
+ tag 'common_lisp'
7
+ aliases 'cl', 'common-lisp'
8
+
9
+ filenames '*.cl', '*.lisp', '*.el' # used for Elisp too
10
+ mimetypes 'text/x-common-lisp'
11
+
12
+ # 638 functions
13
+ BUILTIN_FUNCTIONS = Set.new %w(
14
+ < <= = > >= - / /= * + 1- 1+ abort abs acons acos acosh add-method
15
+ adjoin adjustable-array-p adjust-array allocate-instance
16
+ alpha-char-p alphanumericp append apply apropos apropos-list
17
+ aref arithmetic-error-operands arithmetic-error-operation
18
+ array-dimension array-dimensions array-displacement
19
+ array-element-type array-has-fill-pointer-p array-in-bounds-p
20
+ arrayp array-rank array-row-major-index array-total-size
21
+ ash asin asinh assoc assoc-if assoc-if-not atan atanh atom
22
+ bit bit-and bit-andc1 bit-andc2 bit-eqv bit-ior bit-nand
23
+ bit-nor bit-not bit-orc1 bit-orc2 bit-vector-p bit-xor boole
24
+ both-case-p boundp break broadcast-stream-streams butlast
25
+ byte byte-position byte-size caaaar caaadr caaar caadar
26
+ caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
27
+ cadr call-next-method car cdaaar cdaadr cdaar cdadar cdaddr
28
+ cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr
29
+ ceiling cell-error-name cerror change-class char char< char<=
30
+ char= char> char>= char/= character characterp char-code
31
+ char-downcase char-equal char-greaterp char-int char-lessp
32
+ char-name char-not-equal char-not-greaterp char-not-lessp
33
+ char-upcase cis class-name class-of clear-input clear-output
34
+ close clrhash code-char coerce compile compiled-function-p
35
+ compile-file compile-file-pathname compiler-macro-function
36
+ complement complex complexp compute-applicable-methods
37
+ compute-restarts concatenate concatenated-stream-streams conjugate
38
+ cons consp constantly constantp continue copy-alist copy-list
39
+ copy-pprint-dispatch copy-readtable copy-seq copy-structure
40
+ copy-symbol copy-tree cos cosh count count-if count-if-not
41
+ decode-float decode-universal-time delete delete-duplicates
42
+ delete-file delete-if delete-if-not delete-package denominator
43
+ deposit-field describe describe-object digit-char digit-char-p
44
+ directory directory-namestring disassemble documentation dpb
45
+ dribble echo-stream-input-stream echo-stream-output-stream
46
+ ed eighth elt encode-universal-time endp enough-namestring
47
+ ensure-directories-exist ensure-generic-function eq
48
+ eql equal equalp error eval evenp every exp export expt
49
+ fboundp fceiling fdefinition ffloor fifth file-author
50
+ file-error-pathname file-length file-namestring file-position
51
+ file-string-length file-write-date fill fill-pointer find
52
+ find-all-symbols find-class find-if find-if-not find-method
53
+ find-package find-restart find-symbol finish-output first
54
+ float float-digits floatp float-precision float-radix
55
+ float-sign floor fmakunbound force-output format fourth
56
+ fresh-line fround ftruncate funcall function-keywords
57
+ function-lambda-expression functionp gcd gensym gentemp get
58
+ get-decoded-time get-dispatch-macro-character getf gethash
59
+ get-internal-real-time get-internal-run-time get-macro-character
60
+ get-output-stream-string get-properties get-setf-expansion
61
+ get-universal-time graphic-char-p hash-table-count hash-table-p
62
+ hash-table-rehash-size hash-table-rehash-threshold
63
+ hash-table-size hash-table-test host-namestring identity
64
+ imagpart import initialize-instance input-stream-p inspect
65
+ integer-decode-float integer-length integerp interactive-stream-p
66
+ intern intersection invalid-method-error invoke-debugger
67
+ invoke-restart invoke-restart-interactively isqrt keywordp
68
+ last lcm ldb ldb-test ldiff length lisp-implementation-type
69
+ lisp-implementation-version list list* list-all-packages listen
70
+ list-length listp load load-logical-pathname-translations
71
+ log logand logandc1 logandc2 logbitp logcount logeqv
72
+ logical-pathname logical-pathname-translations logior
73
+ lognand lognor lognot logorc1 logorc2 logtest logxor
74
+ long-site-name lower-case-p machine-instance machine-type
75
+ machine-version macroexpand macroexpand-1 macro-function
76
+ make-array make-broadcast-stream make-concatenated-stream
77
+ make-condition make-dispatch-macro-character make-echo-stream
78
+ make-hash-table make-instance make-instances-obsolete make-list
79
+ make-load-form make-load-form-saving-slots make-package
80
+ make-pathname make-random-state make-sequence make-string
81
+ make-string-input-stream make-string-output-stream make-symbol
82
+ make-synonym-stream make-two-way-stream makunbound map mapc
83
+ mapcan mapcar mapcon maphash map-into mapl maplist mask-field
84
+ max member member-if member-if-not merge merge-pathnames
85
+ method-combination-error method-qualifiers min minusp mismatch mod
86
+ muffle-warning name-char namestring nbutlast nconc next-method-p
87
+ nintersection ninth no-applicable-method no-next-method not notany
88
+ notevery nreconc nreverse nset-difference nset-exclusive-or
89
+ nstring-capitalize nstring-downcase nstring-upcase nsublis
90
+ nsubst nsubst-if nsubst-if-not nsubstitute nsubstitute-if
91
+ nsubstitute-if-not nth nthcdr null numberp numerator nunion
92
+ oddp open open-stream-p output-stream-p package-error-package
93
+ package-name package-nicknames packagep package-shadowing-symbols
94
+ package-used-by-list package-use-list pairlis parse-integer
95
+ parse-namestring pathname pathname-device pathname-directory
96
+ pathname-host pathname-match-p pathname-name pathnamep
97
+ pathname-type pathname-version peek-char phase plusp
98
+ position position-if position-if-not pprint pprint-dispatch
99
+ pprint-fill pprint-indent pprint-linear pprint-newline pprint-tab
100
+ pprint-tabular prin1 prin1-to-string princ princ-to-string print
101
+ print-object probe-file proclaim provide random random-state-p
102
+ rassoc rassoc-if rassoc-if-not rational rationalize rationalp
103
+ read read-byte read-char read-char-no-hang read-delimited-list
104
+ read-from-string read-line read-preserving-whitespace
105
+ read-sequence readtable-case readtablep realp realpart
106
+ reduce reinitialize-instance rem remhash remove
107
+ remove-duplicates remove-if remove-if-not remove-method
108
+ remprop rename-file rename-package replace require rest
109
+ restart-name revappend reverse room round row-major-aref
110
+ rplaca rplacd sbit scale-float schar search second set
111
+ set-difference set-dispatch-macro-character set-exclusive-or
112
+ set-macro-character set-pprint-dispatch set-syntax-from-char
113
+ seventh shadow shadowing-import shared-initialize
114
+ short-site-name signal signum simple-bit-vector-p
115
+ simple-condition-format-arguments simple-condition-format-control
116
+ simple-string-p simple-vector-p sin sinh sixth sleep slot-boundp
117
+ slot-exists-p slot-makunbound slot-missing slot-unbound slot-value
118
+ software-type software-version some sort special-operator-p
119
+ sqrt stable-sort standard-char-p store-value stream-element-type
120
+ stream-error-stream stream-external-format streamp string string<
121
+ string<= string= string> string>= string/= string-capitalize
122
+ string-downcase string-equal string-greaterp string-left-trim
123
+ string-lessp string-not-equal string-not-greaterp string-not-lessp
124
+ stringp string-right-trim string-trim string-upcase sublis subseq
125
+ subsetp subst subst-if subst-if-not substitute substitute-if
126
+ substitute-if-not subtypepsvref sxhash symbol-function
127
+ symbol-name symbolp symbol-package symbol-plist symbol-value
128
+ synonym-stream-symbol syntax: tailp tan tanh tenth terpri third
129
+ translate-logical-pathname translate-pathname tree-equal truename
130
+ truncate two-way-stream-input-stream two-way-stream-output-stream
131
+ type-error-datum type-error-expected-type type-of
132
+ typep unbound-slot-instance unexport unintern union
133
+ unread-char unuse-package update-instance-for-different-class
134
+ update-instance-for-redefined-class upgraded-array-element-type
135
+ upgraded-complex-part-type upper-case-p use-package
136
+ user-homedir-pathname use-value values values-list vector vectorp
137
+ vector-pop vector-push vector-push-extend warn wild-pathname-p
138
+ write write-byte write-char write-line write-sequence write-string
139
+ write-to-string yes-or-no-p y-or-n-p zerop
140
+ ).freeze
141
+
142
+ SPECIAL_FORMS = Set.new %w(
143
+ block catch declare eval-when flet function go if labels lambda
144
+ let let* load-time-value locally macrolet multiple-value-call
145
+ multiple-value-prog1 progn progv quote return-from setq
146
+ symbol-macrolet tagbody the throw unwind-protect
147
+ )
148
+
149
+ MACROS = Set.new %w(
150
+ and assert call-method case ccase check-type cond ctypecase decf
151
+ declaim defclass defconstant defgeneric define-compiler-macro
152
+ define-condition define-method-combination define-modify-macro
153
+ define-setf-expander define-symbol-macro defmacro defmethod
154
+ defpackage defparameter defsetf defstruct deftype defun defvar
155
+ destructuring-bind do do* do-all-symbols do-external-symbols
156
+ dolist do-symbols dotimes ecase etypecase formatter
157
+ handler-bind handler-case ignore-errors incf in-package
158
+ lambda loop loop-finish make-method multiple-value-bind
159
+ multiple-value-list multiple-value-setq nth-value or pop
160
+ pprint-exit-if-list-exhausted pprint-logical-block pprint-pop
161
+ print-unreadable-object prog prog* prog1 prog2 psetf psetq
162
+ push pushnew remf restart-bind restart-case return rotatef
163
+ setf shiftf step time trace typecase unless untrace when
164
+ with-accessors with-compilation-unit with-condition-restarts
165
+ with-hash-table-iterator with-input-from-string with-open-file
166
+ with-open-stream with-output-to-string with-package-iterator
167
+ with-simple-restart with-slots with-standard-io-syntax
168
+ )
169
+
170
+ LAMBDA_LIST_KEYWORDS = Set.new %w(
171
+ &allow-other-keys &aux &body &environment &key &optional &rest
172
+ &whole
173
+ )
174
+
175
+ DECLARATIONS = Set.new %w(
176
+ dynamic-extent ignore optimize ftype inline special ignorable
177
+ notinline type
178
+ )
179
+
180
+ BUILTIN_TYPES = Set.new %w(
181
+ atom boolean base-char base-string bignum bit compiled-function
182
+ extended-char fixnum keyword nil signed-byte short-float
183
+ single-float double-float long-float simple-array
184
+ simple-base-string simple-bit-vector simple-string simple-vector
185
+ standard-char unsigned-byte
186
+
187
+ arithmetic-error cell-error condition control-error
188
+ division-by-zero end-of-file error file-error
189
+ floating-point-inexact floating-point-overflow
190
+ floating-point-underflow floating-point-invalid-operation
191
+ parse-error package-error print-not-readable program-error
192
+ reader-error serious-condition simple-condition simple-error
193
+ simple-type-error simple-warning stream-error storage-condition
194
+ style-warning type-error unbound-variable unbound-slot
195
+ undefined-function warning
196
+ )
197
+
198
+ BUILTIN_CLASSES = Set.new %w(
199
+ array broadcast-stream bit-vector built-in-class character
200
+ class complex concatenated-stream cons echo-stream file-stream
201
+ float function generic-function hash-table integer list
202
+ logical-pathname method-combination method null number package
203
+ pathname ratio rational readtable real random-state restart
204
+ sequence standard-class standard-generic-function standard-method
205
+ standard-object string-stream stream string structure-class
206
+ structure-object symbol synonym-stream t two-way-stream vector
207
+ )
208
+
209
+ nonmacro = /\\.|[a-zA-Z0-9!$%&*+-\/<=>?@\[\]^_{}~]/
210
+ constituent = /#{nonmacro}|[#.:]/
211
+ terminated = /(?=[ "'()\n,;`])/ # whitespace or terminating macro chars
212
+ symbol = /(\|[^\|]+\||#{nonmacro}#{constituent}*)/
213
+
214
+ state :root do
215
+ rule /\s+/m, Text
216
+ rule /;.*$/, Comment::Single
217
+ rule /#\|/, Comment::Multiline, :multiline_comment
218
+
219
+ # encoding comment
220
+ rule /#\d*Y.*$/, Comment::Special
221
+ rule /"(\\.|[^"\\])*"/, Str
222
+
223
+ rule /[:']#{symbol}/, Str::Symbol
224
+ rule /['`]/, Operator
225
+
226
+ # numbers
227
+ rule /[-+]?\d+\.?#{terminated}/, Num::Integer
228
+ rule %r{[-+]?\d+/\d+#{terminated}}, Num::Integer
229
+ rule %r{
230
+ [-+]?
231
+ (\d*\.\d+([defls][-+]?\d+)?
232
+ |\d+(\.\d*)?[defls][-+]?\d+)
233
+ #{terminated}
234
+ }x, Num::Float
235
+
236
+ # sharpsign strings and characters
237
+ rule /#\\.#{terminated}/, Str::Char
238
+ rule /#\\#{symbol}/, Str::Char
239
+
240
+ rule /#\(/, Operator, :root
241
+
242
+ # bitstring
243
+ rule /#\d*\*[01]*/, Other
244
+
245
+ # uninterned symbol
246
+ rule /#:#{symbol}/, Str::Symbol
247
+
248
+ # read-time and load-time evaluation
249
+ rule /#[.,]/, Operator
250
+
251
+ # function shorthand
252
+ rule /#'/, Name::Function
253
+
254
+ # binary rational
255
+ rule /#b[+-]?[01]+(\/[01]+)?/i, Num
256
+
257
+ # octal rational
258
+ rule /#o[+-]?[0-7]+(\/[0-7]+)?/i, Num::Oct
259
+
260
+ # hex rational
261
+ rule /#x[+-]?[0-9a-f]+(\/[0-9a-f]+)?/i, Num
262
+
263
+ # complex
264
+ rule /(#c)(\()/i do
265
+ groups Num, Punctuation
266
+ push :root
267
+ end
268
+
269
+ # arrays and structures
270
+ rule /(#(?:\d+a|s))(\()/i do
271
+ groups Literal::Other, Punctuation
272
+ push :root
273
+ end
274
+
275
+ # path
276
+ rule /#p?"(\\.|[^"])*"/i, Str::Symbol
277
+
278
+ # reference
279
+ rule /#\d+[=#]/, Operator
280
+
281
+ # read-time comment
282
+ rule /#+nil#{terminated}\s*\(/, Comment, :commented_form
283
+
284
+ # read-time conditional
285
+ rule /#[+-]/, Operator
286
+
287
+ # special operators that should have been parsed already
288
+ rule /(,@|,|\.)/, Operator
289
+
290
+ # special constants
291
+ rule /(t|nil)#{terminated}/, Name::Constant
292
+
293
+ # functions and variables
294
+ # note that these get filtered through in stream_tokens
295
+ rule /\*#{symbol}\*/, Name::Variable::Global
296
+ rule symbol do |m|
297
+ sym = m[0]
298
+
299
+ if BUILTIN_FUNCTIONS.include? sym
300
+ token Name::Builtin
301
+ elsif SPECIAL_FORMS.include? sym
302
+ token Keyword
303
+ elsif MACROS.include? sym
304
+ token Name::Builtin
305
+ elsif LAMBDA_LIST_KEYWORDS.include? sym
306
+ token Keyword
307
+ elsif DECLARATIONS.include? sym
308
+ token Keyword
309
+ elsif BUILTIN_TYPES.include? sym
310
+ token Keyword::Type
311
+ elsif BUILTIN_CLASSES.include? sym
312
+ token Name::Class
313
+ else
314
+ token Name::Variable
315
+ end
316
+ end
317
+
318
+ rule /\(/, Punctuation, :root
319
+ rule /\)/, Punctuation do
320
+ if stack.empty?
321
+ token Error
322
+ else
323
+ token Punctuation
324
+ pop!
325
+ end
326
+ end
327
+ end
328
+
329
+ state :multiline_comment do
330
+ rule /#\|/, Comment::Multiline, :multiline_comment
331
+ rule /\|#/, Comment::Multiline, :pop!
332
+ rule /[^\|#]+/, Comment::Multiline
333
+ rule /[\|#]/, Comment::Multiline
334
+ end
335
+
336
+ state :commented_form do
337
+ rule /\(/, Comment, :commented_form
338
+ rule /\)/, Comment, :pop!
339
+ rule /[^()]+/, Comment
340
+ end
341
+ end
342
+ end
343
+ end
@@ -0,0 +1,22 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Conf < RegexLexer
4
+ tag 'conf'
5
+ aliases 'config', 'configuration'
6
+
7
+ title 'Config File'
8
+ desc 'A generic lexer for configuration files'
9
+ filenames '*.conf', '*.config'
10
+
11
+ # short and sweet
12
+ state :root do
13
+ rule /#.*?\n/, Comment
14
+ rule /".*?"/, Str::Double
15
+ rule /'.*?'/, Str::Single
16
+ rule /[a-z]\w*/i, Name
17
+ rule /\d+/, Num
18
+ rule /[^\d\w#"']+/, Text
19
+ end
20
+ end
21
+ end
22
+ end