rouge 3.30.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,15 +17,15 @@ module Rouge
17
17
 
18
18
  def self.keywords
19
19
  @keywords ||= Set.new %w(
20
- break case cast catch class continue default do else enum false for
21
- function if import interface macro new null override package private
20
+ as break case cast catch class continue default do else enum false for
21
+ function if import in interface macro new null override package private
22
22
  public return switch this throw true try untyped while
23
23
  )
24
24
  end
25
25
 
26
26
  def self.imports
27
27
  @imports ||= Set.new %w(
28
- import using
28
+ package import using
29
29
  )
30
30
  end
31
31
 
@@ -55,6 +55,7 @@ module Rouge
55
55
  end
56
56
 
57
57
  id = /[$a-zA-Z_][a-zA-Z0-9_]*/
58
+ dotted_id = /[$a-zA-Z_][a-zA-Z0-9_.]*/
58
59
 
59
60
  state :comments_and_whitespace do
60
61
  rule %r/\s+/, Text
@@ -77,6 +78,22 @@ module Rouge
77
78
  rule %r//, Text, :pop!
78
79
  end
79
80
 
81
+ state :namespace do
82
+ mixin :comments_and_whitespace
83
+
84
+ rule %r/
85
+ (#{dotted_id})
86
+ (\s+)(in|as)(\s+)
87
+ (#{id})
88
+ /x do
89
+ groups(Name::Namespace, Text::Whitespace, Keyword, Text::Whitespace, Name)
90
+ end
91
+
92
+ rule %r/#{dotted_id}/, Name::Namespace
93
+
94
+ rule(//) { pop! }
95
+ end
96
+
80
97
  state :regex do
81
98
  rule %r(/) do
82
99
  token Str::Regex
@@ -141,20 +158,22 @@ module Rouge
141
158
  end
142
159
 
143
160
  rule id do |m|
144
- if self.class.keywords.include? m[0]
161
+ match = m[0]
162
+
163
+ if self.class.imports.include?(match)
164
+ token Keyword::Namespace
165
+ push :namespace
166
+ elsif self.class.keywords.include?(match)
145
167
  token Keyword
146
168
  push :expr_start
147
- elsif self.class.imports.include? m[0]
148
- token Keyword
149
- push :namespace
150
- elsif self.class.declarations.include? m[0]
169
+ elsif self.class.declarations.include?(match)
151
170
  token Keyword::Declaration
152
171
  push :expr_start
153
- elsif self.class.reserved.include? m[0]
172
+ elsif self.class.reserved.include?(match)
154
173
  token Keyword::Reserved
155
- elsif self.class.constants.include? m[0]
174
+ elsif self.class.constants.include?(match)
156
175
  token Keyword::Constant
157
- elsif self.class.builtins.include? m[0]
176
+ elsif self.class.builtins.include?(match)
158
177
  token Name::Builtin
159
178
  else
160
179
  token Name::Other
@@ -11,7 +11,7 @@ module Rouge
11
11
  option :content, "the language for the content (default: auto-detect)"
12
12
 
13
13
  def self.http_methods
14
- @http_methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH)
14
+ @http_methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH QUERY)
15
15
  end
16
16
 
17
17
  def content_lexer
@@ -46,7 +46,7 @@ module Rouge
46
46
 
47
47
  # response
48
48
  rule %r(
49
- (HTTPS?)(/)(\d(?:\.\d))([ ]+) # http version
49
+ (HTTPS?)(/)(\d(?:\.\d)?)([ ]+) # http version
50
50
  (\d{3})([ ]+)? # status
51
51
  ([^\r\n]*)?(\r?\n|$) # status message
52
52
  )x do
@@ -53,6 +53,7 @@ module Rouge
53
53
  rule %r/(?:true|false|null)\b/, Keyword::Constant
54
54
  rule %r/(?:class|interface)\b/, Keyword::Declaration, :class
55
55
  rule %r/(?:import|package)\b/, Keyword::Namespace, :import
56
+ rule %r/"""\s*\n.*?(?<!\\)"""/m, Str::Heredoc
56
57
  rule %r/"(\\\\|\\"|[^"])*"/, Str
57
58
  rule %r/'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, Str::Char
58
59
  rule %r/(\.)(#{id})/ do
@@ -271,7 +271,7 @@ module Rouge
271
271
  state :template_string do
272
272
  rule %r/[$]{/, Punctuation, :template_string_expr
273
273
  rule %r/`/, Str::Double, :pop!
274
- rule %r/\\[$`]/, Str::Escape
274
+ rule %r/\\[$`\\]/, Str::Escape
275
275
  rule %r/[^$`\\]+/, Str::Double
276
276
  rule %r/[\\$]/, Str::Double
277
277
  end
@@ -9,11 +9,11 @@ module Rouge
9
9
  module Lexers
10
10
  class LLVM
11
11
  def self.keywords
12
- @keywords ||= Set.new ["aarch64_sve_vector_pcs", "aarch64_vector_pcs", "acq_rel", "acquire", "addrspace", "afn", "alias", "aliasee", "align", "alignLog2", "alignstack", "allOnes", "allocsize", "alwaysInline", "alwaysinline", "amdgpu_cs", "amdgpu_es", "amdgpu_gs", "amdgpu_hs", "amdgpu_kernel", "amdgpu_ls", "amdgpu_ps", "amdgpu_vs", "any", "anyregcc", "appending", "arcp", "argmemonly", "args", "arm_aapcs_vfpcc", "arm_aapcscc", "arm_apcscc", "asm", "atomic", "attributes", "available_externally", "avr_intrcc", "avr_signalcc", "bit", "bitMask", "blockaddress", "branchFunnel", "builtin", "byArg", "byte", "byteArray", "byval", "c", "callee", "caller", "calls", "canAutoHide", "catch", "cc", "ccc", "cfguard_checkcc", "cleanup", "cold", "coldcc", "comdat", "common", "constant", "contract", "convergent", "critical", "cxx_fast_tlscc", "datalayout", "declare", "default", "define", "deplibs", "dereferenceable", "dereferenceable_or_null", "distinct", "dllexport", "dllimport", "dsoLocal", "dso_local", "dso_preemptable", "eq", "exact", "exactmatch", "extern_weak", "external", "externally_initialized", "false", "fast", "fastcc", "filter", "flags", "from", "funcFlags", "function", "gc", "ghccc", "global", "guid", "gv", "hash", "hhvm_ccc", "hhvmcc", "hidden", "hot", "hotness", "ifunc", "immarg", "inaccessiblemem_or_argmemonly", "inaccessiblememonly", "inalloca", "inbounds", "indir", "info", "initialexec", "inline", "inlineBits", "inlinehint", "inrange", "inreg", "insts", "intel_ocl_bicc", "inteldialect", "internal", "jumptable", "kind", "largest", "linkage", "linkonce", "linkonce_odr", "live", "local_unnamed_addr", "localdynamic", "localexec", "max", "min", "minsize", "module", "monotonic", "msp430_intrcc", "musttail", "naked", "name", "nand", "ne", "nest", "ninf", "nnan", "noInline", "noRecurse", "noalias", "nobuiltin", "nocapture", "nocf_check", "noduplicate", "noduplicates", "nofree", "noimplicitfloat", "noinline", "none", "nonlazybind", "nonnull", "norecurse", "noredzone", "noreturn", "nosync", "notEligibleToImport", "notail", "nounwind", "nsw", "nsz", "null", "nuw", "oeq", "offset", "oge", "ogt", "ole", "olt", "one", "opaque", "optforfuzzing", "optnone", "optsize", "ord", "partition", "path", "personality", "prefix", "preserve_allcc", "preserve_mostcc", "private", "prologue", "protected", "ptx_device", "ptx_kernel", "readNone", "readOnly", "readnone", "readonly", "reassoc", "refs", "relbf", "release", "resByArg", "returnDoesNotAlias", "returned", "returns_twice", "safestack", "samesize", "sanitize_address", "sanitize_hwaddress", "sanitize_memory", "sanitize_memtag", "sanitize_thread", "section", "seq_cst", "sge", "sgt", "shadowcallstack", "sideeffect", "signext", "single", "singleImpl", "singleImplName", "sizeM1", "sizeM1BitWidth", "sle", "slt", "source_filename", "speculatable", "speculative_load_hardening", "spir_func", "spir_kernel", "sret", "ssp", "sspreq", "sspstrong", "strictfp", "summaries", "summary", "swiftcc", "swifterror", "swiftself", "syncscope", "tail", "tailcc", "target", "thread_local", "to", "triple", "true", "type", "typeCheckedLoadConstVCalls", "typeCheckedLoadVCalls", "typeIdInfo", "typeTestAssumeConstVCalls", "typeTestAssumeVCalls", "typeTestRes", "typeTests", "typeid", "typeidCompatibleVTable", "ueq", "uge", "ugt", "ule", "ult", "umax", "umin", "undef", "une", "uniformRetVal", "uniqueRetVal", "unknown", "unnamed_addr", "uno", "unordered", "unsat", "unwind", "uselistorder", "uselistorder_bb", "uwtable", "vFuncId", "vTableFuncs", "varFlags", "variable", "vcall_visibility", "virtFunc", "virtualConstProp", "volatile", "vscale", "weak", "weak_odr", "webkit_jscc", "willreturn", "win64cc", "within", "wpdRes", "wpdResolutions", "writeonly", "x", "x86_64_sysvcc", "x86_fastcallcc", "x86_intrcc", "x86_regcallcc", "x86_stdcallcc", "x86_thiscallcc", "x86_vectorcallcc", "xchg", "zeroext", "zeroinitializer"]
12
+ @keywords ||= Set.new ["aarch64_sve_vector_pcs", "aarch64_vector_pcs", "acq_rel", "acquire", "addrspace", "afn", "alias", "aliasee", "align", "alignLog2", "alignstack", "allOnes", "allocalign", "allocptr", "allocsize", "alwaysInline", "alwaysinline", "amdgpu_cs", "amdgpu_es", "amdgpu_gfx", "amdgpu_gs", "amdgpu_hs", "amdgpu_kernel", "amdgpu_ls", "amdgpu_ps", "amdgpu_vs", "any", "anyregcc", "appending", "arcp", "argmemonly", "args", "arm_aapcs_vfpcc", "arm_aapcscc", "arm_apcscc", "asm", "async", "atomic", "attributes", "available_externally", "avr_intrcc", "avr_signalcc", "bit", "bitMask", "blockaddress", "blockcount", "branchFunnel", "builtin", "byArg", "byref", "byte", "byteArray", "byval", "c", "callee", "caller", "calls", "canAutoHide", "catch", "cc", "ccc", "cfguard_checkcc", "cleanup", "cold", "coldcc", "comdat", "common", "constant", "contract", "convergent", "critical", "cxx_fast_tlscc", "datalayout", "declare", "default", "define", "dereferenceable", "dereferenceable_or_null", "disable_sanitizer_instrumentation", "distinct", "dllexport", "dllimport", "dsoLocal", "dso_local", "dso_local_equivalent", "dso_preemptable", "elementtype", "eq", "exact", "exactmatch", "extern_weak", "external", "externally_initialized", "false", "fast", "fastcc", "filter", "flags", "from", "funcFlags", "function", "gc", "ghccc", "global", "guid", "gv", "hasUnknownCall", "hash", "hhvm_ccc", "hhvmcc", "hidden", "hot", "hotness", "ifunc", "immarg", "inaccessiblemem_or_argmemonly", "inaccessiblememonly", "inalloca", "inbounds", "indir", "info", "initialexec", "inline", "inlineBits", "inlinehint", "inrange", "inreg", "insts", "intel_ocl_bicc", "inteldialect", "internal", "jumptable", "kind", "largest", "linkage", "linkonce", "linkonce_odr", "live", "local_unnamed_addr", "localdynamic", "localexec", "max", "mayThrow", "min", "minsize", "module", "monotonic", "msp430_intrcc", "mustBeUnreachable", "mustprogress", "musttail", "naked", "name", "nand", "ne", "nest", "ninf", "nnan", "noInline", "noRecurse", "noUnwind", "no_cfi", "noalias", "nobuiltin", "nocallback", "nocapture", "nocf_check", "nodeduplicate", "noduplicate", "nofree", "noimplicitfloat", "noinline", "nomerge", "none", "nonlazybind", "nonnull", "noprofile", "norecurse", "noredzone", "noreturn", "nosanitize_bounds", "nosanitize_coverage", "nosync", "notEligibleToImport", "notail", "noundef", "nounwind", "nsw", "nsz", "null", "null_pointer_is_valid", "nuw", "oeq", "offset", "oge", "ogt", "ole", "olt", "one", "opaque", "optforfuzzing", "optnone", "optsize", "ord", "param", "params", "partition", "path", "personality", "poison", "preallocated", "prefix", "preserve_allcc", "preserve_mostcc", "private", "prologue", "protected", "ptx_device", "ptx_kernel", "readNone", "readOnly", "readnone", "readonly", "reassoc", "refs", "relbf", "release", "resByArg", "returnDoesNotAlias", "returned", "returns_twice", "safestack", "samesize", "sanitize_address", "sanitize_hwaddress", "sanitize_memory", "sanitize_memtag", "sanitize_thread", "section", "seq_cst", "sge", "sgt", "shadowcallstack", "sideeffect", "signext", "single", "singleImpl", "singleImplName", "sizeM1", "sizeM1BitWidth", "sle", "slt", "source_filename", "speculatable", "speculative_load_hardening", "spir_func", "spir_kernel", "sret", "ssp", "sspreq", "sspstrong", "strictfp", "summaries", "summary", "swiftasync", "swiftcc", "swifterror", "swiftself", "swifttailcc", "sync", "syncscope", "tail", "tailcc", "target", "thread_local", "to", "triple", "true", "type", "typeCheckedLoadConstVCalls", "typeCheckedLoadVCalls", "typeIdInfo", "typeTestAssumeConstVCalls", "typeTestAssumeVCalls", "typeTestRes", "typeTests", "typeid", "typeidCompatibleVTable", "ueq", "uge", "ugt", "ule", "ult", "umax", "umin", "undef", "une", "uniformRetVal", "uniqueRetVal", "unknown", "unnamed_addr", "uno", "unordered", "unsat", "unwind", "uselistorder", "uselistorder_bb", "uwtable", "vFuncId", "vTableFuncs", "varFlags", "variable", "vcall_visibility", "virtFunc", "virtualConstProp", "visibility", "volatile", "vscale", "vscale_range", "weak", "weak_odr", "webkit_jscc", "willreturn", "win64cc", "within", "wpdRes", "wpdResolutions", "writeonly", "x", "x86_64_sysvcc", "x86_fastcallcc", "x86_intrcc", "x86_regcallcc", "x86_stdcallcc", "x86_thiscallcc", "x86_vectorcallcc", "xchg", "zeroext", "zeroinitializer"]
13
13
  end
14
14
 
15
15
  def self.types
16
- @types ||= Set.new ["double", "float", "fp128", "half", "label", "metadata", "ppc_fp128", "token", "void", "x86_fp80", "x86_mmx"]
16
+ @types ||= Set.new ["bfloat", "double", "float", "fp128", "half", "label", "metadata", "ppc_fp128", "ptr", "token", "void", "x86_amx", "x86_fp80", "x86_mmx"]
17
17
  end
18
18
 
19
19
  def self.instructions
@@ -20,11 +20,6 @@ module Rouge
20
20
  )
21
21
  end
22
22
 
23
- # TODO: Add support for special keywords
24
- # bsd_special = %w(
25
- # include undef error warning if else elif endif for endfor
26
- # )
27
-
28
23
  def initialize(opts={})
29
24
  super
30
25
  @shell = Shell.new(opts)
@@ -41,11 +36,11 @@ module Rouge
41
36
  groups Keyword, Literal::String::Other
42
37
  end
43
38
 
44
- rule %r/(ifn?def|ifn?eq)([\t ]+)([^#\n]+)/ do
39
+ rule %r/((?:ifn?def|ifn?eq|unexport)\b)([\t ]+)([^#\n]+)/ do
45
40
  groups Keyword, Text, Name::Variable
46
41
  end
47
42
 
48
- rule %r/(?:else|endif)[\t ]*(?=[#\n])/, Keyword
43
+ rule %r/(?:else|endif|endef|endfor)[\t ]*(?=[#\n])/, Keyword
49
44
 
50
45
  rule %r/(export)([\t ]+)(?=[\w\${}()\t -]+\n)/ do
51
46
  groups Keyword, Text
@@ -55,10 +50,8 @@ module Rouge
55
50
  rule %r/export[\t ]+/, Keyword
56
51
 
57
52
  # assignment
58
- rule %r/([\w${}().-]+)([\t ]*)([!?:+]?=)/m do |m|
59
- token Name::Variable, m[1]
60
- token Text, m[2]
61
- token Operator, m[3]
53
+ rule %r/(override\b)*([\t ]*)([\w${}().-]+)([\t ]*)([!?:+]?=)/m do |m|
54
+ groups Name::Builtin, Text, Name::Variable, Text, Operator
62
55
  push :shell_line
63
56
  end
64
57
 
@@ -68,10 +61,19 @@ module Rouge
68
61
  groups Name::Label, Operator, Text
69
62
  push :block_header
70
63
  end
64
+
65
+ rule %r/(override\b)*([\t ])*(define)([\t ]+)([^#\n]+)/ do
66
+ groups Name::Builtin, Text, Keyword, Text, Name::Variable
67
+ end
68
+
69
+ rule %r/(\$[({])([\t ]*)(#{Make.functions.join('|')})([\t ]+)/m do
70
+ groups Name::Function, Text, Name::Builtin, Text
71
+ push :shell_expr
72
+ end
71
73
  end
72
74
 
73
75
  state :export do
74
- rule %r/[\w\${}()-]/, Name::Variable
76
+ rule %r/[\w[\$]{1,2}{}()-]/, Name::Variable
75
77
  rule %r/\n/, Text, :pop!
76
78
  rule %r/[\t ]+/, Text
77
79
  end
@@ -107,22 +109,29 @@ module Rouge
107
109
 
108
110
  state :shell do
109
111
  # macro interpolation
110
- rule %r/\$[({][\t ]*\w[\w:=%.]*[\t ]*[)}]/i, Name::Variable
112
+ rule %r/[\$]{1,2}[({]/, Punctuation, :macro_expr
113
+
111
114
  # function invocation
112
115
  rule %r/(\$[({])([\t ]*)(#{Make.functions.join('|')})([\t ]+)/m do
113
- groups Name::Function, Text, Name::Builtin, Text
116
+ groups Punctuation, Text, Name::Builtin, Text
114
117
  push :shell_expr
115
118
  end
116
119
 
117
120
  rule(/\\./m) { delegate @shell }
118
- stop = /\$\(|\$\{|\(|\)|\}|\\|$/
121
+ stop = /[\$]{1,2}\(|[\$]{1,2}\{|\(|\)|\}|\\|$/
119
122
  rule(/.+?(?=#{stop})/m) { delegate @shell }
120
123
  rule(stop) { delegate @shell }
121
124
  end
122
125
 
126
+ state :macro_expr do
127
+ rule %r/[)}]/, Punctuation, :pop!
128
+ rule %r/\n/, Text, :pop!
129
+ mixin :shell
130
+ end
131
+
123
132
  state :shell_expr do
124
133
  rule(/[({]/) { delegate @shell; push }
125
- rule %r/[)}]/, Name::Function, :pop!
134
+ rule %r/[)}]/, Punctuation, :pop!
126
135
  mixin :shell
127
136
  end
128
137
 
@@ -182,6 +182,10 @@ module Rouge
182
182
 
183
183
  state :parameters do
184
184
  rule %r/`./m, Str::Escape
185
+ rule %r/\)/ do
186
+ token Punctuation
187
+ pop!(2) if in_state?(:interpol) # pop :parameters and :interpol
188
+ end
185
189
  rule %r/\s*?\n/, Text::Whitespace, :pop!
186
190
  rule %r/[;(){}\]]/, Punctuation, :pop!
187
191
  rule %r/[|=]/, Operator, :pop!
@@ -236,6 +240,8 @@ module Rouge
236
240
 
237
241
  rule %r/[-+*\/%=!.&|]/, Operator
238
242
  rule %r/[{}(),:;]/, Punctuation
243
+
244
+ rule %r/`$/, Str::Escape # line continuation
239
245
  end
240
246
  end
241
247
  end