rouge 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -8,7 +8,7 @@ module Rouge
8
8
  aliases 'cucumber', 'behat'
9
9
 
10
10
  title "Gherkin"
11
- desc 'A business-readable spec DSL ( github.com/cucumber/cucumber/wiki/Gherkin )'
11
+ desc 'A business-readable spec DSL (github.com/cucumber/cucumber/wiki/Gherkin)'
12
12
 
13
13
  filenames '*.feature'
14
14
  mimetypes 'text/x-gherkin'
@@ -30,6 +30,8 @@ module Rouge
30
30
  keywords[:step].map do |w|
31
31
  if w.end_with? '<'
32
32
  Regexp.escape(w.chop)
33
+ elsif w.end_with?(' ')
34
+ Regexp.escape(w)
33
35
  else
34
36
  "#{Regexp.escape(w)}\\b"
35
37
  end
@@ -130,7 +132,7 @@ module Rouge
130
132
  mixin :basic
131
133
  rule %r/<.*?>/, Name::Variable
132
134
  rule %r/".*?"/, Str
133
- rule %r/\S+/, Text
135
+ rule %r/\S[^\s<]*/, Text
134
136
  rule rest_of_line, Text, :pop!
135
137
  end
136
138
  end
@@ -20,19 +20,26 @@ module Rouge
20
20
  end
21
21
 
22
22
  rule %r/\bfragment\b/, Keyword, :fragment_definition
23
+
24
+ rule %r/\bscalar\b/, Keyword, :value
23
25
 
24
26
  rule %r/\b(?:type|interface|enum)\b/, Keyword, :type_definition
27
+
25
28
  rule %r/\b(?:input|schema)\b/, Keyword, :type_definition
26
29
 
27
30
  rule %r/\bunion\b/, Keyword, :union_definition
28
31
 
32
+ rule %r/\bextend\b/, Keyword
33
+
29
34
  mixin :basic
30
35
 
31
36
  # Markdown descriptions
32
- rule %r/(""")(.*?)(""")/m do |m|
37
+ rule %r/(""")(\n)(.*?)(\n)(""")/m do |m|
33
38
  token Str::Double, m[1]
34
- delegate Markdown, m[2]
35
- token Str::Double, m[3]
39
+ token Text::Whitespace, m[2]
40
+ delegate Markdown, m[3]
41
+ token Text::Whitespace, m[4]
42
+ token Str::Double, m[5]
36
43
  end
37
44
  end
38
45
 
@@ -27,7 +27,15 @@ module Rouge
27
27
  push :open_sym
28
28
  end
29
29
 
30
- rule(/(.+?)(?=\\|{{)/m) { delegate parent }
30
+ rule(/(.+?)(?=\\|{{)/m) do
31
+ delegate parent
32
+
33
+ # if parent state is attr, then we have an html attribute without quotes
34
+ # pop the parent state to return to the tag state
35
+ if parent.state?('attr')
36
+ parent.pop!
37
+ end
38
+ end
31
39
 
32
40
  # if we get here, there's no more mustache tags, so we eat
33
41
  # the rest of the doc
@@ -43,9 +51,12 @@ module Rouge
43
51
 
44
52
  state :stache do
45
53
  rule %r/}}}?/, Keyword, :pop!
54
+ rule %r/\|/, Punctuation
55
+ rule %r/~/, Keyword
46
56
  rule %r/\s+/m, Text
47
57
  rule %r/[=]/, Operator
48
58
  rule %r/[\[\]]/, Punctuation
59
+ rule %r/[\(\)]/, Punctuation
49
60
  rule %r/[.](?=[}\s])/, Name::Variable
50
61
  rule %r/[.][.]/, Name::Variable
51
62
  rule %r([/.]), Punctuation
@@ -65,7 +76,7 @@ module Rouge
65
76
  goto :block_name
66
77
  end
67
78
 
68
- rule %r/[>^&]/, Keyword
79
+ rule %r/[>^&~]/, Keyword
69
80
 
70
81
  rule(//) { pop! }
71
82
  end
@@ -77,4 +88,4 @@ module Rouge
77
88
  end
78
89
  end
79
90
  end
80
- end
91
+ end
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'json.rb'
7
+
8
+ class HOCON < JSON
9
+ title 'HOCON'
10
+ desc "Human-Optimized Config Object Notation (https://github.com/lightbend/config)"
11
+ tag 'hocon'
12
+ filenames '*.hocon'
13
+
14
+ state :comments do
15
+ # Comments
16
+ rule %r(//.*?$), Comment::Single
17
+ rule %r(#.*?$), Comment::Single
18
+ end
19
+
20
+ prepend :root do
21
+ mixin :comments
22
+ end
23
+
24
+ prepend :object do
25
+ # Keywords
26
+ rule %r/\b(?:include|url|file|classpath)\b/, Keyword
27
+ end
28
+
29
+ state :name do
30
+ rule %r/("(?:\"|[^"\n])*?")(\s*)([:=]|(?={))/ do
31
+ groups Name::Label, Text::Whitespace, Punctuation
32
+ end
33
+
34
+ rule %r/([-\w.]+)(\s*)([:=]|(?={))/ do
35
+ groups Name::Label, Text::Whitespace, Punctuation
36
+ end
37
+ end
38
+
39
+ state :value do
40
+ mixin :comments
41
+
42
+ rule %r/\n/, Text::Whitespace
43
+ rule %r/\s+/, Text::Whitespace
44
+
45
+ mixin :constants
46
+
47
+ # Interpolation
48
+ rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
49
+
50
+ # Strings
51
+ rule %r/"""/, Literal::String::Double, :multiline_string
52
+ rule %r/"/, Str::Double, :string
53
+
54
+ rule %r/\[/, Punctuation, :array
55
+ rule %r/{/, Punctuation, :object
56
+
57
+ # Symbols (only those not handled by JSON)
58
+ rule %r/[()=]/, Punctuation
59
+
60
+ # Values
61
+ rule %r/[^$"{}\[\]:=,\+#`^?!@*&]+?/, Literal
62
+ end
63
+
64
+ state :interpolation do
65
+ rule %r/[\w\-\.]+?/, Name::Variable
66
+ rule %r/}/, Literal::String::Interpol, :pop!
67
+ end
68
+
69
+ prepend :string do
70
+ rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
71
+ rule %r/[^\\"\${]+/, Literal::String::Double
72
+ end
73
+
74
+ state :multiline_string do
75
+ rule %r/"[^"]{1,2}/, Literal::String::Double
76
+ mixin :string
77
+ rule %r/"""/, Literal::String::Double, :pop!
78
+ end
79
+
80
+ prepend :constants do
81
+ # Numbers (handle the case where we have multiple periods, ie. IP addresses)
82
+ rule %r/\d+\.(\d+\.?){3,}/, Literal
83
+ end
84
+ end
85
+ end
86
+ end
@@ -83,8 +83,8 @@ module Rouge
83
83
 
84
84
  state :tag do
85
85
  rule %r/\s+/m, Text
86
- rule %r/[a-zA-Z0-9_:-]+\s*=\s*/m, Name::Attribute, :attr
87
- rule %r/[a-zA-Z0-9_:-]+/, Name::Attribute
86
+ rule %r/[a-zA-Z0-9_:\[\]()*.-]+\s*=\s*/m, Name::Attribute, :attr
87
+ rule %r/[a-zA-Z0-9_:#*-]+/, Name::Attribute
88
88
  rule %r(/?\s*>)m, Name::Tag, :pop!
89
89
  end
90
90
 
@@ -20,7 +20,7 @@ module Rouge
20
20
  break return continue
21
21
  for endfor do while
22
22
  case default
23
- try catch endtry
23
+ try catch endtry
24
24
  abortonrte
25
25
  )
26
26
  end
@@ -12,13 +12,39 @@ module Rouge
12
12
  'application/hal+json', 'application/problem+json',
13
13
  'application/schema+json'
14
14
 
15
+ state :whitespace do
16
+ rule %r/\s+/, Text::Whitespace
17
+ end
18
+
15
19
  state :root do
16
- rule %r/\s+/m, Text::Whitespace
20
+ mixin :whitespace
21
+ rule %r/{/, Punctuation, :object
22
+ rule %r/\[/, Punctuation, :array
23
+
24
+ mixin :name
25
+ mixin :value
26
+ end
27
+
28
+ state :object do
29
+ mixin :whitespace
30
+ mixin :name
31
+ mixin :value
32
+ rule %r/}/, Punctuation, :pop!
33
+ rule %r/,/, Punctuation
34
+ end
35
+
36
+ state :name do
37
+ rule %r/("(?:\"|[^"\n])*?")(\s*)(:)/ do
38
+ groups Name::Label, Text::Whitespace, Punctuation
39
+ end
40
+ end
41
+
42
+ state :value do
43
+ mixin :whitespace
44
+ mixin :constants
17
45
  rule %r/"/, Str::Double, :string
18
- rule %r/(?:true|false|null)\b/, Keyword::Constant
19
- rule %r/[{},:\[\]]/, Punctuation
20
- rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
21
- rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
46
+ rule %r/\[/, Punctuation, :array
47
+ rule %r/{/, Punctuation, :object
22
48
  end
23
49
 
24
50
  state :string do
@@ -26,6 +52,18 @@ module Rouge
26
52
  rule %r/\\./, Str::Escape
27
53
  rule %r/"/, Str::Double, :pop!
28
54
  end
55
+
56
+ state :array do
57
+ mixin :value
58
+ rule %r/\]/, Punctuation, :pop!
59
+ rule %r/,/, Punctuation
60
+ end
61
+
62
+ state :constants do
63
+ rule %r/(?:true|false|null)/, Keyword::Constant
64
+ rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
65
+ rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
66
+ end
29
67
  end
30
68
  end
31
69
  end
@@ -0,0 +1,115 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Mason < TemplateLexer
7
+ title 'Mason'
8
+ desc 'The HTML::Mason framework (https://metacpan.org/pod/HTML::Mason)'
9
+ tag 'mason'
10
+ filenames '*.mi', '*.mc', '*.mas', '*.m', '*.mhtml', '*.mcomp', 'autohandler', 'dhandler'
11
+ mimetypes 'text/x-mason', 'application/x-mason'
12
+
13
+ def initialize(*)
14
+ super
15
+ @perl = Perl.new
16
+ end
17
+
18
+ def self.detect?(text)
19
+ return false if text.doctype?(/((?:ht|x)ml)/)
20
+ return true if text.doctype?
21
+ end
22
+
23
+ # Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
24
+ TEXT_BLOCKS = %w(text doc)
25
+ PERL_BLOCKS = %w(args flags attr init once shared perl cleanup filter)
26
+ COMPONENTS = %w(def method)
27
+
28
+ state :root do
29
+ mixin :mason_tags
30
+ end
31
+
32
+ state :mason_tags do
33
+ rule %r/\s+/, Text::Whitespace
34
+
35
+ rule %r/<%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :text_block
36
+
37
+ rule %r/<%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :perl_block
38
+
39
+ rule %r/(<%(#{COMPONENTS.join('|')}))([^>]*)(>)/oi do |m|
40
+ token Comment::Preproc, m[1]
41
+ token Name, m[3]
42
+ token Comment::Preproc, m[4]
43
+ push :component_block
44
+ end
45
+
46
+ # perl line
47
+ rule %r/^(%)(.*)$/ do |m|
48
+ token Comment::Preproc, m[1]
49
+ delegate @perl, m[2]
50
+ end
51
+
52
+ # start of component call
53
+ rule %r/<%/, Comment::Preproc, :component_call
54
+
55
+ # start of component with content
56
+ rule %r/<&\|/ do
57
+ token Comment::Preproc
58
+ push :component_with_content
59
+ push :component_sub
60
+ end
61
+
62
+ # start of component substitution
63
+ rule %r/<&/, Comment::Preproc, :component_sub
64
+
65
+ # fallback to HTML until a mason tag is encountered
66
+ rule(/(.+?)(?=(<\/?&|<\/?%|^%|^#))/m) { delegate parent }
67
+
68
+ # if we get here, there's no more mason tags, so we parse the rest of the doc as HTML
69
+ rule(/.+/m) { delegate parent }
70
+ end
71
+
72
+ state :perl_block do
73
+ rule %r/<\/%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
74
+ rule %r/\s+/, Text::Whitespace
75
+ rule %r/^(#.*)$/, Comment
76
+ rule(/(.*?[^"])(?=<\/%)/m) { delegate @perl }
77
+ end
78
+
79
+ state :text_block do
80
+ rule %r/<\/%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
81
+ rule %r/\s+/, Text::Whitespace
82
+ rule %r/^(#.*)$/, Comment
83
+ rule %r/(.*?[^"])(?=<\/%)/m, Comment
84
+ end
85
+
86
+ state :component_block do
87
+ rule %r/<\/%(#{COMPONENTS.join('|')})>/oi, Comment::Preproc, :pop!
88
+ rule %r/\s+/, Text::Whitespace
89
+ rule %r/^(#.*)$/, Comment
90
+ mixin :mason_tags
91
+ end
92
+
93
+ state :component_with_content do
94
+ rule %r/<\/&>/ do
95
+ token Comment::Preproc
96
+ pop!
97
+ end
98
+
99
+ mixin :mason_tags
100
+ end
101
+
102
+ state :component_sub do
103
+ rule %r/&>/, Comment::Preproc, :pop!
104
+
105
+ rule(/(.*?)(?=&>)/m) { delegate @perl }
106
+ end
107
+
108
+ state :component_call do
109
+ rule %r/%>/, Comment::Preproc, :pop!
110
+
111
+ rule(/(.*?)(?=%>)/m) { delegate @perl }
112
+ end
113
+ end
114
+ end
115
+ end
@@ -3,7 +3,9 @@
3
3
 
4
4
  module Rouge
5
5
  module Lexers
6
- class OCaml < RegexLexer
6
+ load_lexer 'ocaml/common.rb'
7
+
8
+ class OCaml < OCamlCommon
7
9
  title "OCaml"
8
10
  desc 'Objective Caml (ocaml.org)'
9
11
  tag 'ocaml'
@@ -11,35 +13,19 @@ module Rouge
11
13
  mimetypes 'text/x-ocaml'
12
14
 
13
15
  def self.keywords
14
- @keywords ||= Set.new %w(
15
- as assert begin class constraint do done downto else end
16
- exception external false for fun function functor if in include
17
- inherit initializer lazy let match method module mutable new
18
- nonrec object of open private raise rec sig struct then to true
19
- try type val virtual when while with
20
- )
21
- end
22
-
23
- def self.word_operators
24
- @word_operators ||= Set.new %w(and asr land lor lsl lxor mod or)
16
+ @keywords ||= super + Set.new(%w(
17
+ match raise
18
+ ))
25
19
  end
26
20
 
27
- def self.primitives
28
- @primitives ||= Set.new %w(unit int float bool string char list array)
29
- end
30
-
31
- operator = %r([;,_!$%&*+./:<=>?@^|~#-]+)
32
- id = /[a-z_][\w']*/i
33
- upper_id = /[A-Z][\w']*/
34
-
35
21
  state :root do
36
22
  rule %r/\s+/m, Text
37
23
  rule %r/false|true|[(][)]|\[\]/, Name::Builtin::Pseudo
38
- rule %r/#{upper_id}(?=\s*[.])/, Name::Namespace, :dotted
39
- rule %r/`#{id}/, Name::Tag
40
- rule upper_id, Name::Class
24
+ rule %r/#{@@upper_id}(?=\s*[.])/, Name::Namespace, :dotted
25
+ rule %r/`#{@@id}/, Name::Tag
26
+ rule @@upper_id, Name::Class
41
27
  rule %r/[(][*](?![)])/, Comment, :comment
42
- rule id do |m|
28
+ rule @@id do |m|
43
29
  match = m[0]
44
30
  if self.class.keywords.include? match
45
31
  token Keyword
@@ -53,7 +39,7 @@ module Rouge
53
39
  end
54
40
 
55
41
  rule %r/[(){}\[\];]+/, Punctuation
56
- rule operator, Operator
42
+ rule @@operator, Operator
57
43
 
58
44
  rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
59
45
  rule %r/0x\h[\h_]*/i, Num::Hex
@@ -65,7 +51,7 @@ module Rouge
65
51
  rule %r/'[.]'/, Str::Char
66
52
  rule %r/'/, Keyword
67
53
  rule %r/"/, Str::Double, :string
68
- rule %r/[~?]#{id}/, Name::Variable
54
+ rule %r/[~?]#{@@id}/, Name::Variable
69
55
  end
70
56
 
71
57
  state :comment do
@@ -74,28 +60,6 @@ module Rouge
74
60
  rule %r/[*][)]/, Comment, :pop!
75
61
  rule %r/[(*)]/, Comment
76
62
  end
77
-
78
- state :string do
79
- rule %r/[^\\"]+/, Str::Double
80
- mixin :escape_sequence
81
- rule %r/\\\n/, Str::Double
82
- rule %r/"/, Str::Double, :pop!
83
- end
84
-
85
- state :escape_sequence do
86
- rule %r/\\[\\"'ntbr]/, Str::Escape
87
- rule %r/\\\d{3}/, Str::Escape
88
- rule %r/\\x\h{2}/, Str::Escape
89
- end
90
-
91
- state :dotted do
92
- rule %r/\s+/m, Text
93
- rule %r/[.]/, Punctuation
94
- rule %r/#{upper_id}(?=\s*[.])/, Name::Namespace
95
- rule upper_id, Name::Class, :pop!
96
- rule id, Name, :pop!
97
- rule %r/[({\[]/, Punctuation, :pop!
98
- end
99
63
  end
100
64
  end
101
65
  end