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,172 @@
1
+ module Rugments
2
+ module Lexers
3
+ # shared states with SCSS
4
+ class SassCommon < RegexLexer
5
+ id = /[\w-]+/
6
+
7
+ state :content_common do
8
+ rule /@for\b/, Keyword, :for
9
+ rule /@(debug|warn|if|while)/, Keyword, :value
10
+ rule /(@mixin)(\s+)(#{id})/ do
11
+ groups Keyword, Text, Name::Function
12
+ push :value
13
+ end
14
+
15
+ rule /@extend\b/, Keyword, :selector
16
+
17
+ rule /(@include)(\s+)(#{id})/ do
18
+ groups Keyword, Text, Name::Decorator
19
+ push :value
20
+ end
21
+
22
+ rule /@#{id}/, Keyword, :selector
23
+
24
+ # $variable: assignment
25
+ rule /([$]#{id})([ \t]*)(:)/ do
26
+ groups Name::Variable, Text, Punctuation
27
+ push :value
28
+ end
29
+ end
30
+
31
+ state :value do
32
+ mixin :end_section
33
+ rule /[ \t]+/, Text
34
+ rule /[$]#{id}/, Name::Variable
35
+ rule /url[(]/, Str::Other, :string_url
36
+ rule /#{id}(?=\s*[(])/, Name::Function
37
+ rule /%#{id}/, Name::Decorator
38
+
39
+ # named literals
40
+ rule /(true|false)\b/, Name::Builtin::Pseudo
41
+ rule /(and|or|not)\b/, Operator::Word
42
+
43
+ # colors and numbers
44
+ rule /#[a-z0-9]{1,6}/i, Num::Hex
45
+ rule /-?\d+(%|[a-z]+)?/, Num
46
+ rule /-?\d*\.\d+(%|[a-z]+)?/, Num::Integer
47
+
48
+ mixin :has_strings
49
+ mixin :has_interp
50
+
51
+ rule /[~^*!&%<>\|+=@:,.\/?-]+/, Operator
52
+ rule /[\[\]()]+/, Punctuation
53
+ rule %r{/[*]}, Comment::Multiline, :inline_comment
54
+ rule %r{//[^\n]*}, Comment::Single
55
+
56
+ # identifiers
57
+ rule(id) do |m|
58
+ if CSS.builtins.include? m[0]
59
+ token Name::Builtin
60
+ elsif CSS.constants.include? m[0]
61
+ token Name::Constant
62
+ else
63
+ token Name
64
+ end
65
+ end
66
+ end
67
+
68
+ state :has_interp do
69
+ rule /[#][{]/, Str::Interpol, :interpolation
70
+ end
71
+
72
+ state :has_strings do
73
+ rule /"/, Str::Double, :dq
74
+ rule /'/, Str::Single, :sq
75
+ end
76
+
77
+ state :interpolation do
78
+ rule /}/, Str::Interpol, :pop!
79
+ mixin :value
80
+ end
81
+
82
+ state :selector do
83
+ mixin :end_section
84
+
85
+ mixin :has_strings
86
+ mixin :has_interp
87
+ rule /[ \t]+/, Text
88
+ rule /:/, Name::Decorator, :pseudo_class
89
+ rule /[.]/, Name::Class, :class
90
+ rule /#/, Name::Namespace, :id
91
+ rule /%/, Name::Variable, :placeholder
92
+ rule id, Name::Tag
93
+ rule /&/, Keyword
94
+ rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, Operator
95
+ end
96
+
97
+ state :dq do
98
+ rule /"/, Str::Double, :pop!
99
+ mixin :has_interp
100
+ rule /(\\.|#(?![{])|[^\n"#])+/, Str::Double
101
+ end
102
+
103
+ state :sq do
104
+ rule /'/, Str::Single, :pop!
105
+ mixin :has_interp
106
+ rule /(\\.|#(?![{])|[^\n'#])+/, Str::Single
107
+ end
108
+
109
+ state :string_url do
110
+ rule /[)]/, Str::Other, :pop!
111
+ rule /(\\.|#(?![{])|[^\n)#])+/, Str::Other
112
+ mixin :has_interp
113
+ end
114
+
115
+ state :selector_piece do
116
+ mixin :has_interp
117
+ rule(//) { pop! }
118
+ end
119
+
120
+ state :pseudo_class do
121
+ rule id, Name::Decorator
122
+ mixin :selector_piece
123
+ end
124
+
125
+ state :class do
126
+ rule id, Name::Class
127
+ mixin :selector_piece
128
+ end
129
+
130
+ state :id do
131
+ rule id, Name::Namespace
132
+ mixin :selector_piece
133
+ end
134
+
135
+ state :placeholder do
136
+ rule id, Name::Variable
137
+ mixin :selector_piece
138
+ end
139
+
140
+ state :for do
141
+ rule /(from|to|through)/, Operator::Word
142
+ mixin :value
143
+ end
144
+
145
+ state :attr_common do
146
+ mixin :has_interp
147
+ rule id do |m|
148
+ if CSS.attributes.include? m[0]
149
+ token Name::Label
150
+ else
151
+ token Name::Attribute
152
+ end
153
+ end
154
+ end
155
+
156
+ state :attribute do
157
+ mixin :attr_common
158
+
159
+ rule /([ \t]*)(:)/ do
160
+ groups Text, Punctuation
161
+ push :value
162
+ end
163
+ end
164
+
165
+ state :inline_comment do
166
+ rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, Comment::Multiline
167
+ mixin :has_interp
168
+ rule %r{[*]/}, Comment::Multiline, :pop!
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,72 @@
1
+ module Rugments
2
+ module Lexers
3
+ load_const :SassCommon, 'sass/common.rb'
4
+
5
+ class Sass < SassCommon
6
+ include Indentation
7
+
8
+ title 'Sass'
9
+ desc 'The Sass stylesheet language language (sass-lang.com)'
10
+
11
+ tag 'sass'
12
+ filenames '*.sass'
13
+ mimetypes 'text/x-sass'
14
+
15
+ id = /[\w-]+/
16
+
17
+ state :root do
18
+ rule /[ \t]*\n/, Text
19
+ rule(/[ \t]*/) { |m| token Text; indentation(m[0]) }
20
+ end
21
+
22
+ state :content do
23
+ # block comments
24
+ rule %r{//.*?\n} do
25
+ token Comment::Single
26
+ pop!; starts_block :single_comment
27
+ end
28
+
29
+ rule %r{/[*].*?\n} do
30
+ token Comment::Multiline
31
+ pop!; starts_block :multi_comment
32
+ end
33
+
34
+ rule /@import\b/, Keyword, :import
35
+
36
+ mixin :content_common
37
+
38
+ rule %r{=#{id}}, Name::Function, :value
39
+ rule %r{[+]#{id}}, Name::Decorator, :value
40
+
41
+ rule /:/, Name::Attribute, :old_style_attr
42
+
43
+ rule(/(?=.+?:([^a-z]|$))/) { push :attribute }
44
+
45
+ rule(//) { push :selector }
46
+ end
47
+
48
+ state :single_comment do
49
+ rule /.*?\n/, Comment::Single, :pop!
50
+ end
51
+
52
+ state :multi_comment do
53
+ rule /.*?\n/, Comment::Multiline, :pop!
54
+ end
55
+
56
+ state :import do
57
+ rule /[ \t]+/, Text
58
+ rule /\S+/, Str
59
+ rule /\n/, Text, :pop!
60
+ end
61
+
62
+ state :old_style_attr do
63
+ mixin :attr_common
64
+ rule(//) { pop!; push :value }
65
+ end
66
+
67
+ state :end_section do
68
+ rule(/\n/) { token Text; reset_stack }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,140 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Scala < RegexLexer
4
+ title 'Scala'
5
+ desc 'The Scala programming language (scala-lang.org)'
6
+ tag 'scala'
7
+ aliases 'scala'
8
+ filenames '*.scala', '*.sbt'
9
+
10
+ mimetypes 'text/x-scala', 'application/x-scala'
11
+
12
+ # As documented in the ENBF section of the scala specification
13
+ # http://www.scala-lang.org/docu/files/ScalaReference.pdf
14
+ whitespace = /\p{Space}/
15
+ letter = /[\p{L}$_]/
16
+ upper = /[\p{Lu}$_]/
17
+ digits = /[0-9]/
18
+ parens = /[(){}\[\]]/
19
+ delims = %r{[‘’".;,]}
20
+
21
+ # negative lookahead to filter out other classes
22
+ op = %r(
23
+ (?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims})
24
+ [\u0020-\u007F\p{Sm}\p{So}]
25
+ )x
26
+
27
+ idrest = %r{#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?}x
28
+
29
+ keywords = %w(
30
+ abstract case catch def do else extends final finally for forSome
31
+ if implicit lazy match new override private protected requires return
32
+ sealed super this throw try val var while with yield
33
+ )
34
+
35
+ state :root do
36
+ rule /(class|trait|object)(\s+)/ do
37
+ groups Keyword, Text
38
+ push :class
39
+ end
40
+ rule /'#{idrest}[^']/, Str::Symbol
41
+ rule /[^\S\n]+/, Text
42
+
43
+ rule %r{//.*?\n}, Comment::Single
44
+ rule %r{/\*}, Comment::Multiline, :comment
45
+
46
+ rule /@#{idrest}/, Name::Decorator
47
+ rule %r{
48
+ (#{keywords.join("|")})\b|
49
+ (<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\s)|$)
50
+ }x, Keyword
51
+ rule /:(?!#{op})/, Keyword, :type
52
+ rule /#{upper}#{idrest}\b/, Name::Class
53
+ rule /(true|false|null)\b/, Keyword::Constant
54
+ rule /(import|package)(\s+)/ do
55
+ groups Keyword, Text
56
+ push :import
57
+ end
58
+
59
+ rule /(type)(\s+)/ do
60
+ groups Keyword, Text
61
+ push :type
62
+ end
63
+
64
+ rule /""".*?"""(?!")/m, Str
65
+ rule /"(\\\\|\\"|[^"])*"/, Str
66
+ rule /'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'/, Str::Char
67
+
68
+ rule idrest, Name
69
+ rule /`[^`]+`/, Name
70
+
71
+ rule /\[/, Operator, :typeparam
72
+ rule /[\(\)\{\};,.#]/, Operator
73
+ rule /#{op}+/, Operator
74
+
75
+ rule /([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?/, Num::Float
76
+ rule /([0-9][0-9]*[fFdD])/, Num::Float
77
+ rule /0x[0-9a-fA-F]+/, Num::Hex
78
+ rule /[0-9]+L?/, Num::Integer
79
+ rule /\n/, Text
80
+ end
81
+
82
+ state :class do
83
+ rule /(#{idrest}|#{op}+|`[^`]+`)(\s*)(\[)/ do
84
+ groups Name::Class, Text, Operator
85
+ push :typeparam
86
+ end
87
+
88
+ rule /\s+/, Text
89
+ rule /{/, Operator, :pop!
90
+ rule /\(/, Operator, :pop!
91
+ rule %r{//.*?\n}, Comment::Single, :pop!
92
+ rule %r{#{idrest}|#{op}+|`[^`]+`}, Name::Class, :pop!
93
+ end
94
+
95
+ state :type do
96
+ rule /\s+/, Text
97
+ rule /<[%:]|>:|[#_\u21D2]|forSome|type/, Keyword
98
+ rule /([,\);}]|=>|=)(\s*)/ do
99
+ groups Operator, Text
100
+ pop!
101
+ end
102
+ rule /[\(\{]/, Operator, :type
103
+
104
+ typechunk = /(?:#{idrest}|#{op}+\`[^`]+`)/
105
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)(\[)/ do
106
+ groups Keyword::Type, Text, Operator
107
+ pop!
108
+ push :typeparam
109
+ end
110
+
111
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)$/ do
112
+ groups Keyword::Type, Text
113
+ pop!
114
+ end
115
+
116
+ rule %r{//.*?\n}, Comment::Single, :pop!
117
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
118
+ end
119
+
120
+ state :typeparam do
121
+ rule /[\s,]+/, Text
122
+ rule /<[%:]|=>|>:|[#_\u21D2]|forSome|type/, Keyword
123
+ rule /([\]\)\}])/, Operator, :pop!
124
+ rule /[\(\[\{]/, Operator, :typeparam
125
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
126
+ end
127
+
128
+ state :comment do
129
+ rule %r{[^/\*]+}, Comment::Multiline
130
+ rule %r{/\*}, Comment::Multiline, :comment
131
+ rule %r{\*/}, Comment::Multiline, :pop!
132
+ rule %r{[*/]}, Comment::Multiline
133
+ end
134
+
135
+ state :import do
136
+ rule %r{(#{idrest}|\.)+}, Name::Namespace, :pop!
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,109 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Scheme < RegexLexer
4
+ title 'Scheme'
5
+ desc 'The Scheme variant of Lisp'
6
+
7
+ tag 'scheme'
8
+ filenames '*.scm', '*.ss'
9
+ mimetypes 'text/x-scheme', 'application/x-scheme'
10
+
11
+ def self.keywords
12
+ @keywords ||= Set.new %w(
13
+ lambda define if else cond and or case let let* letrec begin
14
+ do delay set! => quote quasiquote unquote unquote-splicing
15
+ define-syntax let-syntax letrec-syntax syntax-rules
16
+ )
17
+ end
18
+
19
+ def self.builtins
20
+ @builtins ||= Set.new %w(
21
+ * + - / < <= = > >= abs acos angle append apply asin
22
+ assoc assq assv atan boolean? caaaar caaadr caaar caadar
23
+ caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
24
+ cadr call-with-current-continuation call-with-input-file
25
+ call-with-output-file call-with-values call/cc car cdaaar cdaadr
26
+ cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr
27
+ cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci<=?
28
+ char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase
29
+ char-lower-case? char-numeric? char-ready? char-upcase
30
+ char-upper-case? char-whitespace? char<=? char<? char=? char>=?
31
+ char>? char? close-input-port close-output-port complex? cons
32
+ cos current-input-port current-output-port denominator
33
+ display dynamic-wind eof-object? eq? equal? eqv? eval
34
+ even? exact->inexact exact? exp expt floor for-each force gcd
35
+ imag-part inexact->exact inexact? input-port? integer->char
36
+ integer? interaction-environment lcm length list list->string
37
+ list->vector list-ref list-tail list? load log magnitude
38
+ make-polar make-rectangular make-string make-vector map
39
+ max member memq memv min modulo negative? newline not
40
+ null-environment null? number->string number? numerator odd?
41
+ open-input-file open-output-file output-port? pair? peek-char
42
+ port? positive? procedure? quotient rational? rationalize
43
+ read read-char real-part real? remainder reverse round
44
+ scheme-report-environment set-car! set-cdr! sin sqrt string
45
+ string->list string->number string->symbol string-append
46
+ string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>?
47
+ string-copy string-fill! string-length string-ref
48
+ string-set! string<=? string<? string=? string>=?
49
+ string>? string? substring symbol->string symbol?
50
+ tan transcript-off transcript-on truncate values vector
51
+ vector->list vector-fill! vector-length vector-ref
52
+ vector-set! vector? with-input-from-file with-output-to-file
53
+ write write-char zero?
54
+ )
55
+ end
56
+
57
+ id = /[a-z0-9!$\%&*+,\/:<=>?@^_~|-]+/i
58
+
59
+ state :root do
60
+ # comments
61
+ rule /;.*$/, Comment::Single
62
+ rule /\s+/m, Text
63
+ rule /-?\d+\.\d+/, Num::Float
64
+ rule /-?\d+/, Num::Integer
65
+
66
+ # Racket infinitites
67
+ rule /[+-]inf[.][f0]/, Num
68
+
69
+ rule /#b[01]+/, Num::Bin
70
+ rule /#o[0-7]+/, Num::Oct
71
+ rule /#d[0-9]+/, Num::Integer
72
+ rule /#x[0-9a-f]+/i, Num::Hex
73
+ rule /#[ei][\d.]+/, Num::Other
74
+
75
+ rule /"(\\\\|\\"|[^"])*"/, Str
76
+ rule /'#{id}/i, Str::Symbol
77
+ rule /#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
78
+ Str::Char
79
+ rule /#t|#f/, Name::Constant
80
+ rule /(?:'|#|`|,@|,|\.)/, Operator
81
+
82
+ rule /(['#])(\s*)(\()/m do
83
+ groups Str::Symbol, Text, Punctuation
84
+ end
85
+
86
+ rule /\(/, Punctuation, :command
87
+ rule /\)/, Punctuation
88
+
89
+ rule id, Name::Variable
90
+ end
91
+
92
+ state :command do
93
+ rule id, Name::Function do |m|
94
+ if self.class.keywords.include? m[0]
95
+ token Keyword
96
+ elsif self.class.builtins.include? m[0]
97
+ token Name::Builtin
98
+ else
99
+ token Name::Function
100
+ end
101
+
102
+ pop!
103
+ end
104
+
105
+ rule(//) { pop! }
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,32 @@
1
+ module Rugments
2
+ module Lexers
3
+ load_const :SassCommon, 'sass/common.rb'
4
+
5
+ class Scss < SassCommon
6
+ title 'SCSS'
7
+ desc 'SCSS stylesheets (sass-lang.com)'
8
+ tag 'scss'
9
+ filenames '*.scss'
10
+ mimetypes 'text/x-scss'
11
+
12
+ state :root do
13
+ rule /\s+/, Text
14
+ rule %r{//.*?\n}, Comment::Single
15
+ rule %r{/[*].*?[*]/}m, Comment::Multiline
16
+ rule /@import\b/, Keyword, :value
17
+
18
+ mixin :content_common
19
+
20
+ rule(/(?=[^;{}][;}])/) { push :attribute }
21
+ rule(/(?=[^;{}:]+:[^a-z])/) { push :attribute }
22
+
23
+ rule(//) { push :selector }
24
+ end
25
+
26
+ state :end_section do
27
+ rule /\n/, Text
28
+ rule(/[;{}]/) { token Punctuation; reset_stack }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,167 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Sed < RegexLexer
4
+ title 'sed'
5
+ desc 'sed, the ultimate stream editor'
6
+
7
+ tag 'sed'
8
+ filenames '*.sed'
9
+ mimetypes 'text/x-sed'
10
+
11
+ def self.analyze_text(text)
12
+ return 1 if text.shebang? 'sed'
13
+ end
14
+
15
+ class Regex < RegexLexer
16
+ state :root do
17
+ rule /\\./, Str::Escape
18
+ rule /\[/, Punctuation, :brackets
19
+ rule /[$^.*]/, Operator
20
+ rule /[()]/, Punctuation
21
+ rule /./, Str::Regex
22
+ end
23
+
24
+ state :brackets do
25
+ rule /\^?/ do
26
+ token Punctuation
27
+ goto :brackets_int
28
+ end
29
+ end
30
+
31
+ state :brackets_int do
32
+ # ranges
33
+ rule /.-./, Name::Variable
34
+ rule /\]/, Punctuation, :pop!
35
+ rule /./, Str::Regex
36
+ end
37
+ end
38
+
39
+ class Replacement < RegexLexer
40
+ state :root do
41
+ rule /\\./m, Str::Escape
42
+ rule /&/, Operator
43
+ rule /[^\\&]+/m, Text
44
+ end
45
+ end
46
+
47
+ def regex
48
+ @regex ||= Regex.new(options)
49
+ end
50
+
51
+ def replacement
52
+ @replacement ||= Replacement.new(options)
53
+ end
54
+
55
+ start { regex.reset!; replacement.reset! }
56
+
57
+ state :whitespace do
58
+ rule /\s+/m, Text
59
+ rule(/#.*?\n/) { token Comment; reset_stack }
60
+ rule(/\n/) { token Text; reset_stack }
61
+ rule(/;/) { token Punctuation; reset_stack }
62
+ end
63
+
64
+ state :root do
65
+ mixin :addr_range
66
+ end
67
+
68
+ edot = /\\.|./m
69
+
70
+ state :command do
71
+ mixin :whitespace
72
+
73
+ # subst and transliteration
74
+ rule /(s)(.)(#{edot}*?)(\2)(#{edot}*?)(\2)/m do |m|
75
+ token Keyword, m[1]
76
+ token Punctuation, m[2]
77
+ delegate regex, m[3]
78
+ token Punctuation, m[4]
79
+ delegate replacement, m[5]
80
+ token Punctuation, m[6]
81
+
82
+ goto :flags
83
+ end
84
+
85
+ rule /(y)(.)(#{edot}*?)(\2)(#{edot}*?)(\2)/m do |m|
86
+ token Keyword, m[1]
87
+ token Punctuation, m[2]
88
+ delegate replacement, m[3]
89
+ token Punctuation, m[4]
90
+ delegate replacement, m[5]
91
+ token Punctuation, m[6]
92
+
93
+ pop!
94
+ end
95
+
96
+ # commands that take a text segment as an argument
97
+ rule /([aic])(\s*)/ do
98
+ groups Keyword, Text; goto :text
99
+ end
100
+
101
+ rule /[pd]/, Keyword
102
+
103
+ # commands that take a number argument
104
+ rule /([qQl])(\s+)(\d+)/i do
105
+ groups Keyword, Text, Num
106
+ pop!
107
+ end
108
+
109
+ # no-argument commands
110
+ rule /[={}dDgGhHlnpPqx]/, Keyword, :pop!
111
+
112
+ # commands that take a filename argument
113
+ rule /([rRwW])(\s+)(\S+)/ do
114
+ groups Keyword, Text, Name
115
+ pop!
116
+ end
117
+
118
+ # commands that take a label argument
119
+ rule /([:btT])(\s+)(\S+)/ do
120
+ groups Keyword, Text, Name::Label
121
+ pop!
122
+ end
123
+ end
124
+
125
+ state :addr_range do
126
+ mixin :whitespace
127
+
128
+ ### address ranges ###
129
+ addr_tok = Keyword::Namespace
130
+ rule /\d+/, addr_tok
131
+ rule /[$,~+!]/, addr_tok
132
+
133
+ rule %r{(/)(\\.|.)*?(/)} do |m|
134
+ token addr_tok, m[1]; delegate regex, m[2]; token addr_tok, m[3]
135
+ end
136
+
137
+ # alternate regex rage delimiters
138
+ rule %r{(\\)(.)(\\.|.)*?(\2)} do |m|
139
+ token addr_tok, m[1] + m[2]
140
+ delegate regex, m[3]
141
+ token addr_tok, m[4]
142
+ end
143
+
144
+ rule(//) { push :command }
145
+ end
146
+
147
+ state :text do
148
+ rule /[^\\\n]+/, Str
149
+ rule /\\\n/, Str::Escape
150
+ rule /\\/, Str
151
+ rule /\n/, Text, :pop!
152
+ end
153
+
154
+ state :flags do
155
+ rule /[gp]+/, Keyword, :pop!
156
+
157
+ # writing to a file with the subst command.
158
+ # who'da thunk...?
159
+ rule /([wW])(\s+)(\S+)/ do
160
+ token Keyword; token Text; token Name
161
+ end
162
+
163
+ rule(//) { pop! }
164
+ end
165
+ end
166
+ end
167
+ end