rouge 3.6.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/rouge/demos/ada +26 -0
  4. data/lib/rouge/demos/armasm +12 -0
  5. data/lib/rouge/demos/batchfile +3 -0
  6. data/lib/rouge/demos/bbcbasic +6 -0
  7. data/lib/rouge/demos/cmhg +8 -0
  8. data/lib/rouge/demos/cuda +11 -0
  9. data/lib/rouge/demos/cython +6 -0
  10. data/lib/rouge/demos/epp +4 -0
  11. data/lib/rouge/demos/gdscript +18 -0
  12. data/lib/rouge/demos/hocon +8 -0
  13. data/lib/rouge/demos/mason +22 -0
  14. data/lib/rouge/demos/msgtrans +4 -0
  15. data/lib/rouge/demos/opentype_feature_file +6 -0
  16. data/lib/rouge/demos/plist +1 -132
  17. data/lib/rouge/demos/reasonml +12 -0
  18. data/lib/rouge/demos/sas +13 -0
  19. data/lib/rouge/formatters/html_line_table.rb +3 -1
  20. data/lib/rouge/formatters/tex.rb +14 -12
  21. data/lib/rouge/guessers/disambiguation.rb +12 -0
  22. data/lib/rouge/lexers/ada.rb +162 -0
  23. data/lib/rouge/lexers/armasm.rb +145 -0
  24. data/lib/rouge/lexers/batchfile.rb +164 -0
  25. data/lib/rouge/lexers/bbcbasic.rb +112 -0
  26. data/lib/rouge/lexers/cmhg.rb +34 -0
  27. data/lib/rouge/lexers/console.rb +1 -1
  28. data/lib/rouge/lexers/cpp.rb +4 -1
  29. data/lib/rouge/lexers/cuda.rb +35 -0
  30. data/lib/rouge/lexers/cython.rb +151 -0
  31. data/lib/rouge/lexers/epp.rb +51 -0
  32. data/lib/rouge/lexers/escape.rb +3 -0
  33. data/lib/rouge/lexers/gdscript.rb +171 -0
  34. data/lib/rouge/lexers/gherkin.rb +4 -2
  35. data/lib/rouge/lexers/graphql.rb +10 -3
  36. data/lib/rouge/lexers/handlebars.rb +14 -3
  37. data/lib/rouge/lexers/hocon.rb +86 -0
  38. data/lib/rouge/lexers/html.rb +2 -2
  39. data/lib/rouge/lexers/igorpro.rb +1 -1
  40. data/lib/rouge/lexers/json.rb +43 -5
  41. data/lib/rouge/lexers/julia.rb +1 -1
  42. data/lib/rouge/lexers/make.rb +39 -12
  43. data/lib/rouge/lexers/mason.rb +115 -0
  44. data/lib/rouge/lexers/msgtrans.rb +26 -0
  45. data/lib/rouge/lexers/ocaml.rb +12 -48
  46. data/lib/rouge/lexers/ocaml/common.rb +53 -0
  47. data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
  48. data/lib/rouge/lexers/php.rb +31 -9
  49. data/lib/rouge/lexers/php/builtins.rb +181 -174
  50. data/lib/rouge/lexers/plain_text.rb +1 -1
  51. data/lib/rouge/lexers/puppet.rb +2 -2
  52. data/lib/rouge/lexers/r.rb +2 -3
  53. data/lib/rouge/lexers/reasonml.rb +65 -0
  54. data/lib/rouge/lexers/rust.rb +12 -9
  55. data/lib/rouge/lexers/sas.rb +563 -0
  56. data/lib/rouge/lexers/sed.rb +1 -1
  57. data/lib/rouge/lexers/smarty.rb +10 -10
  58. data/lib/rouge/tex_theme_renderer.rb +5 -1
  59. data/lib/rouge/themes/magritte.rb +3 -3
  60. data/lib/rouge/themes/thankful_eyes.rb +1 -1
  61. data/lib/rouge/themes/tulip.rb +1 -1
  62. data/lib/rouge/version.rb +1 -1
  63. data/rouge.gemspec +4 -3
  64. metadata +38 -5
@@ -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
@@ -199,7 +199,7 @@ module Rouge
199
199
  end
200
200
 
201
201
  # types
202
- rule %r/((mutable )?struct|(abstract|primitive) type)((?:\s|\\\s)+)/ do
202
+ rule %r/((?:mutable )?struct|(?:abstract|primitive) type)((?:\s|\\\s)+)/ do
203
203
  groups Keyword, Name::Class
204
204
  push :typename
205
205
  end
@@ -8,9 +8,18 @@ module Rouge
8
8
  desc "Makefile syntax"
9
9
  tag 'make'
10
10
  aliases 'makefile', 'mf', 'gnumake', 'bsdmake'
11
- filenames '*.make', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'
11
+ filenames '*.make', '*.mak', '*.mk', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile', '*,fe1'
12
12
  mimetypes 'text/x-makefile'
13
13
 
14
+ def self.functions
15
+ @functions ||= %w(
16
+ abspath addprefix addsuffix and basename call dir error eval file
17
+ filter filter-out findstring firstword flavor foreach if join lastword
18
+ notdir or origin patsubst realpath shell sort strip subst suffix value
19
+ warning wildcard word wordlist words
20
+ )
21
+ end
22
+
14
23
  # TODO: Add support for special keywords
15
24
  # bsd_special = %w(
16
25
  # include undef error warning if else elif endif for endfor
@@ -28,15 +37,25 @@ module Rouge
28
37
 
29
38
  rule %r/#.*?\n/, Comment
30
39
 
31
- rule %r/(export)(\s+)(?=[a-zA-Z0-9_\${}\t -]+\n)/ do
40
+ rule %r/([-s]?include)((?:[\t ]+[^\t\n #]+)+)/ do
41
+ groups Keyword, Literal::String::Other
42
+ end
43
+
44
+ rule %r/(ifn?def|ifn?eq)([\t ]+)([^#\n]+)/ do
45
+ groups Keyword, Text, Name::Variable
46
+ end
47
+
48
+ rule %r/(?:else|endif)[\t ]*(?=[#\n])/, Keyword
49
+
50
+ rule %r/(export)([\t ]+)(?=[\w\${}()\t -]+\n)/ do
32
51
  groups Keyword, Text
33
52
  push :export
34
53
  end
35
54
 
36
- rule %r/export\s+/, Keyword
55
+ rule %r/export[\t ]+/, Keyword
37
56
 
38
57
  # assignment
39
- rule %r/([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)/m do |m|
58
+ rule %r/([\w${}().-]+)([\t ]*)([!?:+]?=)/m do |m|
40
59
  token Name::Variable, m[1]
41
60
  token Text, m[2]
42
61
  token Operator, m[3]
@@ -52,9 +71,9 @@ module Rouge
52
71
  end
53
72
 
54
73
  state :export do
55
- rule %r/[\w\${}-]/, Name::Variable
74
+ rule %r/[\w\${}()-]/, Name::Variable
56
75
  rule %r/\n/, Text, :pop!
57
- rule %r/\s+/, Text
76
+ rule %r/[\t ]+/, Text
58
77
  end
59
78
 
60
79
  state :block_header do
@@ -70,6 +89,14 @@ module Rouge
70
89
  end
71
90
 
72
91
  state :block_body do
92
+ rule %r/(ifn?def|ifn?eq)([\t ]+)([^#\n]+)(#.*)?(\n)/ do
93
+ groups Keyword, Text, Name::Variable, Comment, Text
94
+ end
95
+
96
+ rule %r/(else|endif)([\t ]*)(#.*)?(\n)/ do
97
+ groups Keyword, Text, Comment, Text
98
+ end
99
+
73
100
  rule %r/(\t[\t ]*)([@-]?)/ do
74
101
  groups Text, Punctuation
75
102
  push :shell_line
@@ -80,22 +107,22 @@ module Rouge
80
107
 
81
108
  state :shell do
82
109
  # macro interpolation
83
- rule %r/\$\(\s*[a-z_]\w*\s*\)/i, Name::Variable
84
- # $(shell ...)
85
- rule %r/(\$\()(\s*)(shell)(\s+)/m do
110
+ rule %r/\$[({][\t ]*\w[\w:=%.]*[\t ]*[)}]/i, Name::Variable
111
+ # function invocation
112
+ rule %r/(\$[({])([\t ]*)(#{Make.functions.join('|')})([\t ]+)/m do
86
113
  groups Name::Function, Text, Name::Builtin, Text
87
114
  push :shell_expr
88
115
  end
89
116
 
90
117
  rule(/\\./m) { delegate @shell }
91
- stop = /\$\(|\(|\)|\\|$/
118
+ stop = /\$\(|\$\{|\(|\)|\}|\\|$/
92
119
  rule(/.+?(?=#{stop})/m) { delegate @shell }
93
120
  rule(stop) { delegate @shell }
94
121
  end
95
122
 
96
123
  state :shell_expr do
97
- rule(/\(/) { delegate @shell; push }
98
- rule %r/\)/, Name::Variable, :pop!
124
+ rule(/[({]/) { delegate @shell; push }
125
+ rule %r/[)}]/, Name::Function, :pop!
99
126
  mixin :shell
100
127
  end
101
128
 
@@ -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