rouge 3.15.0 → 3.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rougify +2 -2
- data/lib/rouge.rb +67 -52
- data/lib/rouge/cli.rb +18 -1
- data/lib/rouge/demos/augeas +16 -0
- data/lib/rouge/demos/bibtex +12 -0
- data/lib/rouge/demos/cypher +5 -0
- data/lib/rouge/demos/datastudio +21 -0
- data/lib/rouge/demos/ecl +18 -0
- data/lib/rouge/demos/ghc-cmm +23 -0
- data/lib/rouge/demos/hlsl +20 -0
- data/lib/rouge/demos/isbl +4 -0
- data/lib/rouge/demos/livescript +15 -0
- data/lib/rouge/demos/nasm +6 -6
- data/lib/rouge/demos/rego +8 -0
- data/lib/rouge/demos/solidity +13 -0
- data/lib/rouge/demos/vcl +12 -0
- data/lib/rouge/demos/velocity +9 -0
- data/lib/rouge/demos/yang +17 -0
- data/lib/rouge/demos/zig +6 -0
- data/lib/rouge/formatters/terminal256.rb +22 -6
- data/lib/rouge/formatters/terminal_truecolor.rb +37 -0
- data/lib/rouge/lexer.rb +4 -2
- data/lib/rouge/lexers/apache.rb +22 -12
- data/lib/rouge/lexers/apache/keywords.rb +24 -0
- data/lib/rouge/lexers/augeas.rb +93 -0
- data/lib/rouge/lexers/bibtex.rb +115 -0
- data/lib/rouge/lexers/cmake.rb +1 -0
- data/lib/rouge/lexers/coffeescript.rb +47 -15
- data/lib/rouge/lexers/console.rb +53 -37
- data/lib/rouge/lexers/cpp.rb +18 -5
- data/lib/rouge/lexers/cypher.rb +108 -0
- data/lib/rouge/lexers/d.rb +3 -3
- data/lib/rouge/lexers/datastudio.rb +138 -0
- data/lib/rouge/lexers/diff.rb +1 -1
- data/lib/rouge/lexers/ecl.rb +175 -0
- data/lib/rouge/lexers/fsharp.rb +1 -0
- data/lib/rouge/lexers/ghc_cmm.rb +340 -0
- data/lib/rouge/lexers/gherkin.rb +1 -1
- data/lib/rouge/lexers/gherkin/keywords.rb +9 -6
- data/lib/rouge/lexers/haskell.rb +27 -19
- data/lib/rouge/lexers/hlsl.rb +166 -0
- data/lib/rouge/lexers/html.rb +1 -1
- data/lib/rouge/lexers/isbl.rb +97 -0
- data/lib/rouge/lexers/isbl/builtins.rb +17 -0
- data/lib/rouge/lexers/java.rb +4 -5
- data/lib/rouge/lexers/javascript.rb +1 -3
- data/lib/rouge/lexers/json.rb +3 -0
- data/lib/rouge/lexers/json_doc.rb +1 -0
- data/lib/rouge/lexers/jsx.rb +47 -59
- data/lib/rouge/lexers/kotlin.rb +14 -2
- data/lib/rouge/lexers/lasso.rb +11 -12
- data/lib/rouge/lexers/lasso/keywords.rb +20 -0
- data/lib/rouge/lexers/livescript.rb +310 -0
- data/lib/rouge/lexers/llvm.rb +6 -33
- data/lib/rouge/lexers/llvm/keywords.rb +25 -0
- data/lib/rouge/lexers/lua.rb +41 -3
- data/lib/rouge/lexers/lua/keywords.rb +28 -0
- data/lib/rouge/lexers/markdown.rb +9 -5
- data/lib/rouge/lexers/mathematica.rb +2 -2
- data/lib/rouge/lexers/mathematica/keywords.rb +17 -0
- data/lib/rouge/lexers/matlab.rb +3 -4
- data/lib/rouge/lexers/matlab/builtins.rb +11 -0
- data/lib/rouge/lexers/matlab/keywords.rb +15 -0
- data/lib/rouge/lexers/nasm.rb +42 -168
- data/lib/rouge/lexers/objective_c/common.rb +2 -2
- data/lib/rouge/lexers/opentype_feature_file.rb +27 -42
- data/lib/rouge/lexers/pascal.rb +1 -1
- data/lib/rouge/lexers/php.rb +48 -33
- data/lib/rouge/lexers/php/keywords.rb +202 -0
- data/lib/rouge/lexers/powershell.rb +7 -2
- data/lib/rouge/lexers/python.rb +58 -57
- data/lib/rouge/lexers/racket.rb +24 -1
- data/lib/rouge/lexers/rego.rb +45 -0
- data/lib/rouge/lexers/ruby.rb +16 -3
- data/lib/rouge/lexers/rust.rb +2 -10
- data/lib/rouge/lexers/scala.rb +1 -1
- data/lib/rouge/lexers/shell.rb +1 -1
- data/lib/rouge/lexers/solidity.rb +185 -0
- data/lib/rouge/lexers/sparql.rb +5 -4
- data/lib/rouge/lexers/sqf.rb +2 -2
- data/lib/rouge/lexers/sqf/keywords.rb +12 -0
- data/lib/rouge/lexers/terraform.rb +15 -0
- data/lib/rouge/lexers/toml.rb +23 -0
- data/lib/rouge/lexers/tsx.rb +10 -3
- data/lib/rouge/lexers/turtle.rb +1 -1
- data/lib/rouge/lexers/typescript.rb +1 -1
- data/lib/rouge/lexers/typescript/common.rb +18 -4
- data/lib/rouge/lexers/varnish.rb +168 -0
- data/lib/rouge/lexers/velocity.rb +71 -0
- data/lib/rouge/lexers/viml.rb +6 -38
- data/lib/rouge/lexers/viml/keywords.rb +11 -4
- data/lib/rouge/lexers/vue.rb +4 -1
- data/lib/rouge/lexers/yang.rb +147 -0
- data/lib/rouge/lexers/zig.rb +139 -0
- data/lib/rouge/version.rb +1 -1
- metadata +43 -9
- data/lib/rouge/lexers/apache/keywords.yml +0 -764
- data/lib/rouge/lexers/lasso/keywords.yml +0 -446
- data/lib/rouge/lexers/lua/builtins.rb +0 -24
- data/lib/rouge/lexers/mathematica/builtins.rb +0 -13
- data/lib/rouge/lexers/matlab/builtins.yml +0 -3515
- data/lib/rouge/lexers/php/builtins.rb +0 -203
- data/lib/rouge/lexers/sqf/commands.rb +0 -15
data/lib/rouge/lexers/diff.rb
CHANGED
@@ -14,7 +14,7 @@ module Rouge
|
|
14
14
|
def self.detect?(text)
|
15
15
|
return true if text.start_with?('Index: ')
|
16
16
|
return true if text =~ %r(\Adiff[^\n]*?\ba/[^\n]*\bb/)
|
17
|
-
return true if text =~
|
17
|
+
return true if text =~ /---.*?\n[+][+][+]/ || text =~ /[+][+][+].*?\n---/
|
18
18
|
end
|
19
19
|
|
20
20
|
state :root do
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# -*- codding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class ECL < RegexLexer
|
7
|
+
tag 'ecl'
|
8
|
+
filenames '*.ecl'
|
9
|
+
mimetypes 'application/x-ecl'
|
10
|
+
|
11
|
+
title "ECL"
|
12
|
+
desc "Enterprise Control Language (hpccsystems.com)"
|
13
|
+
|
14
|
+
id = /(#?)\b([a-z_][\w]*?)(\d*)\b/i
|
15
|
+
|
16
|
+
def self.class_first
|
17
|
+
@class_first ||= Set.new %w(
|
18
|
+
file date str math metaphone metaphone3 uni audit blas system
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.class_second
|
23
|
+
@class_second ||= Set.new %w(
|
24
|
+
debug email job log thorlib util workunit
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.functions
|
29
|
+
@functions ||= Set.new %w(
|
30
|
+
abs acos aggregate allnodes apply ascii asin asstring atan _token ave
|
31
|
+
case catch choose choosen choosesets clustersize combine correlation
|
32
|
+
cos cosh count covariance cron dataset dedup define denormalize
|
33
|
+
dictionary distribute distributed distribution ebcdic enth error
|
34
|
+
evaluate event eventextra eventname exists exp failcode failmessage
|
35
|
+
fetch fromunicode fromxml getenv getisvalid global graph group hash
|
36
|
+
hashcrc having httpcall httpheader if iff index intformat isvalid
|
37
|
+
iterate join keyunicode length library limit ln local log loop map
|
38
|
+
matched matchlength matchposition matchtext matchunicode max merge
|
39
|
+
mergejoin min nofold nolocal nonempty normalize parse pipe power
|
40
|
+
preload process project pull random range rank ranked realformat
|
41
|
+
recordof regexfind regexreplace regroup rejected rollup round roundup
|
42
|
+
row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt
|
43
|
+
stepped stored sum table tan tanh thisnode topn tounicode toxml
|
44
|
+
transfer transform trim truncate typeof ungroup unicodeorder variance
|
45
|
+
which workunit xmldecode xmlencode xmltext xmlunicode apply assert
|
46
|
+
build buildindex evaluate fail keydiff keypatch loadxml nothor notify
|
47
|
+
output parallel sequential soapcall wait
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.keywords
|
52
|
+
@keywords ||= Set.new %w(
|
53
|
+
and or in not all any as from atmost before best between case const
|
54
|
+
counter csv descend encrypt end endmacro enum except exclusive expire
|
55
|
+
export extend fail few first flat full function functionmacro group
|
56
|
+
heading hole ifblock import joined keep keyed last left limit load
|
57
|
+
local locale lookup many maxcount maxlength _token module interface
|
58
|
+
named nocase noroot noscan nosort of only opt outer overwrite packed
|
59
|
+
partition penalty physicallength pipe quote record repeat return
|
60
|
+
right rows scan self separator service shared skew skip sql store
|
61
|
+
terminator thor threshold token transform trim type unicodeorder
|
62
|
+
unsorted validate virtual whole wild within xml xpath after cluster
|
63
|
+
compressed compression default encoding escape fileposition forward
|
64
|
+
grouped inner internal linkcounted literal lzw mofn multiple
|
65
|
+
namespace wnotrim noxpath onfail prefetch retry rowset scope smart
|
66
|
+
soapaction stable timelimit timeout unordered unstable update use
|
67
|
+
width
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.template
|
72
|
+
@template ||= Set.new %w(
|
73
|
+
append apply break constant debug declare demangle else elseif end
|
74
|
+
endregion error expand export exportxml for forall getdatatype if
|
75
|
+
ifdefined inmodule isdefined isvalid line link loop mangle onwarning
|
76
|
+
option region set stored text trace uniquename warning webservice
|
77
|
+
workunit loadxml
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.type
|
82
|
+
@type ||= Set.new %w(
|
83
|
+
ascii big_endian boolean data decimal ebcdic grouped integer
|
84
|
+
linkcounted pattern qstring real record rule set of streamed string
|
85
|
+
token udecimal unicode utf8 unsigned varstring varunicode
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.typed
|
90
|
+
@typed ||= Set.new %w(
|
91
|
+
data string qstring varstring varunicode unicode utf8
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
state :single_quote do
|
96
|
+
rule %r([xDQUV]?'([^'\\]*(?:\\.[^'\\]*)*)'), Str::Single
|
97
|
+
rule %r/\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)/, Text
|
98
|
+
end
|
99
|
+
|
100
|
+
state :inline_whitespace do
|
101
|
+
rule %r/[ \t\r]+/, Text
|
102
|
+
rule %r/\\\n/, Text # line continuation
|
103
|
+
rule %r(/[*].*?[*]/)m, Comment::Multiline
|
104
|
+
end
|
105
|
+
|
106
|
+
state :whitespace do
|
107
|
+
rule %r/\n+/m, Text
|
108
|
+
rule %r(//.*), Comment::Single
|
109
|
+
mixin :inline_whitespace
|
110
|
+
end
|
111
|
+
|
112
|
+
state :root do
|
113
|
+
mixin :whitespace
|
114
|
+
mixin :single_quote
|
115
|
+
|
116
|
+
rule %r(\b(?i:(and|not|or|in))\b), Operator::Word
|
117
|
+
rule %r([:=|>|<|<>|/|\\|\+|-|=]), Operator
|
118
|
+
rule %r([\[\]{}();,\&,\.,\%]), Punctuation
|
119
|
+
|
120
|
+
rule %r(\b(?i:(beginc\+\+.*?endc\+\+)))m, Str::Single
|
121
|
+
rule %r(\b(?i:(embed.*?endembed)))m, Str::Single
|
122
|
+
|
123
|
+
rule %r(\b(\w+)\.(\w+)\.(\w+)) do |m|
|
124
|
+
if m[1] == "std" &&
|
125
|
+
self.class.class_first.include?(m[2]) &&
|
126
|
+
self.class.class_second.include?(m[3])
|
127
|
+
token Name::Class
|
128
|
+
else
|
129
|
+
token Name::Variable
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
rule %r(\b(?i:(u)?decimal)(\d+(_\d+)?)\b), Keyword::Type
|
134
|
+
|
135
|
+
rule %r/\d+\.\d+(e[\+\-]?\d+)?/i, Num::Float
|
136
|
+
rule %r/x[0-9a-f]+/i, Num::Hex
|
137
|
+
|
138
|
+
rule %r/0x[0-9a-f]+/i, Num::Hex
|
139
|
+
rule %r/0[0-9a-f]+x/i, Num::Hex
|
140
|
+
rule %r(0[bB][01]+), Num::Bin
|
141
|
+
rule %r([01]+[bB]), Num::Bin
|
142
|
+
rule %r(\d+), Num::Integer
|
143
|
+
|
144
|
+
rule id do |m|
|
145
|
+
name_only = m[2].downcase
|
146
|
+
name = name_only + m[3]
|
147
|
+
number = (m[3] == "") ? nil : m[3].to_i
|
148
|
+
if m[1] == "#"
|
149
|
+
if self.class.template.include? name
|
150
|
+
token Keyword::Type
|
151
|
+
else
|
152
|
+
token Error
|
153
|
+
end
|
154
|
+
elsif self.class.typed.include?(name_only) && number != nil
|
155
|
+
token Keyword::Type
|
156
|
+
elsif self.class.type.include? name
|
157
|
+
token Keyword::Type
|
158
|
+
elsif self.class.keywords.include? name
|
159
|
+
token Keyword
|
160
|
+
elsif self.class.functions.include? name
|
161
|
+
token Name::Function
|
162
|
+
elsif ["integer", "unsigned"].include?(name_only) && (1..8).cover?(number)
|
163
|
+
token Keyword::Type
|
164
|
+
elsif name_only == "real" && [4, 8].include?(number)
|
165
|
+
token Keyword::Type
|
166
|
+
elsif ["true", "false"].include? name
|
167
|
+
token Keyword::Constant
|
168
|
+
else
|
169
|
+
token Name::Other
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
data/lib/rouge/lexers/fsharp.rb
CHANGED
@@ -0,0 +1,340 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# C minus minus (Cmm) is a pun on the name C++. It's an intermediate language
|
5
|
+
# of the Glasgow Haskell Compiler (GHC) that is very similar to C, but with
|
6
|
+
# many features missing and some special constructs.
|
7
|
+
#
|
8
|
+
# Cmm is a dialect of C--. The goal of this lexer is to use what GHC produces
|
9
|
+
# and parses (Cmm); C-- itself is not supported.
|
10
|
+
#
|
11
|
+
# https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/cmm-syntax
|
12
|
+
#
|
13
|
+
module Rouge
|
14
|
+
module Lexers
|
15
|
+
class GHCCmm < RegexLexer
|
16
|
+
title "GHC Cmm (C--)"
|
17
|
+
desc "GHC Cmm is the intermediate representation of the GHC Haskell compiler"
|
18
|
+
tag 'ghc-cmm'
|
19
|
+
filenames '*.cmm', '*.dump-cmm', '*.dump-cmm-*'
|
20
|
+
aliases 'cmm'
|
21
|
+
|
22
|
+
ws = %r(\s|//.*?\n|/[*](?:[^*]|(?:[*][^/]))*[*]+/)mx
|
23
|
+
|
24
|
+
# Make sure that this is not a preprocessor macro, e.g. `#if` or `#define`.
|
25
|
+
id = %r((?!#[a-zA-Z])[\w#\$%_']+)
|
26
|
+
|
27
|
+
complex_id = %r(
|
28
|
+
(?:[\w#$%_']|\(\)|\(,\)|\[\]|[0-9])*
|
29
|
+
(?:[\w#$%_']+)
|
30
|
+
)mx
|
31
|
+
|
32
|
+
state :root do
|
33
|
+
rule %r/\s+/m, Text
|
34
|
+
|
35
|
+
# sections markers
|
36
|
+
rule %r/^=====.*=====$/, Generic::Heading
|
37
|
+
|
38
|
+
# timestamps
|
39
|
+
rule %r/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC$/, Comment::Single
|
40
|
+
|
41
|
+
mixin :detect_section
|
42
|
+
mixin :preprocessor_macros
|
43
|
+
|
44
|
+
mixin :info_tbls
|
45
|
+
mixin :comments
|
46
|
+
mixin :literals
|
47
|
+
mixin :keywords
|
48
|
+
mixin :types
|
49
|
+
mixin :infos
|
50
|
+
mixin :names
|
51
|
+
mixin :operators
|
52
|
+
|
53
|
+
# escaped newline
|
54
|
+
rule %r/\\\n/, Text
|
55
|
+
|
56
|
+
# rest is Text
|
57
|
+
rule %r/./, Text
|
58
|
+
end
|
59
|
+
|
60
|
+
state :detect_section do
|
61
|
+
rule %r/(section)(\s+)/ do |m|
|
62
|
+
token Keyword, m[1]
|
63
|
+
token Text, m[2]
|
64
|
+
push :section
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
state :section do
|
69
|
+
rule %r/"(data|cstring|text|rodata|relrodata|bss)"/, Name::Builtin
|
70
|
+
|
71
|
+
rule %r/{/, Punctuation, :pop!
|
72
|
+
|
73
|
+
mixin :names
|
74
|
+
mixin :operators
|
75
|
+
mixin :keywords
|
76
|
+
|
77
|
+
rule %r/\s+/, Text
|
78
|
+
end
|
79
|
+
|
80
|
+
state :preprocessor_macros do
|
81
|
+
rule %r/#(include|endif|else|if)/, Comment::Preproc
|
82
|
+
|
83
|
+
rule %r{
|
84
|
+
(\#define)
|
85
|
+
(#{ws}*)
|
86
|
+
(#{id})
|
87
|
+
}mx do |m|
|
88
|
+
token Comment::Preproc, m[1]
|
89
|
+
recurse m[2]
|
90
|
+
token Name::Label, m[3]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
state :info_tbls do
|
95
|
+
rule %r/({ )(info_tbls)(:)/ do |m|
|
96
|
+
token Punctuation, m[1]
|
97
|
+
token Name::Entity, m[2]
|
98
|
+
token Punctuation, m[3]
|
99
|
+
|
100
|
+
push :info_tbls_body
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
state :info_tbls_body do
|
105
|
+
rule %r/}/, Punctuation, :pop!
|
106
|
+
rule %r/{/, Punctuation, :info_tbls_body
|
107
|
+
|
108
|
+
rule %r/(?=label:)/ do
|
109
|
+
push :label
|
110
|
+
end
|
111
|
+
|
112
|
+
rule %r{(\()(#{complex_id})(,)}mx do |m|
|
113
|
+
token Punctuation, m[1]
|
114
|
+
token Name::Label, m[2]
|
115
|
+
token Punctuation, m[3]
|
116
|
+
end
|
117
|
+
|
118
|
+
mixin :literals
|
119
|
+
mixin :infos
|
120
|
+
mixin :keywords
|
121
|
+
mixin :operators
|
122
|
+
|
123
|
+
rule %r/#{id}/, Text
|
124
|
+
rule %r/\s+/, Text
|
125
|
+
end
|
126
|
+
|
127
|
+
state :label do
|
128
|
+
mixin :infos
|
129
|
+
mixin :names
|
130
|
+
mixin :keywords
|
131
|
+
mixin :operators
|
132
|
+
|
133
|
+
rule %r/[^\S\n]+/, Text # Tab, space, etc. but not newline!
|
134
|
+
rule %r/\n/, Text, :pop!
|
135
|
+
end
|
136
|
+
|
137
|
+
state :comments do
|
138
|
+
rule %r/\/{2}.*/, Comment::Single
|
139
|
+
rule %r/\(likely.*?\)/, Comment
|
140
|
+
rule %r/\/\*.*?\*\//m, Comment::Multiline
|
141
|
+
end
|
142
|
+
|
143
|
+
state :literals do
|
144
|
+
rule %r/-?[0-9]+\.[0-9]+/, Literal::Number::Float
|
145
|
+
rule %r/-?[0-9]+/, Literal::Number::Integer
|
146
|
+
rule %r/"/, Literal::String::Delimiter, :literal_string
|
147
|
+
end
|
148
|
+
|
149
|
+
state :literal_string do
|
150
|
+
# quotes
|
151
|
+
rule %r/\\./, Literal::String::Escape
|
152
|
+
rule %r/%./, Literal::String::Symbol
|
153
|
+
rule %r/"/, Literal::String::Delimiter, :pop!
|
154
|
+
rule %r/./, Literal::String
|
155
|
+
end
|
156
|
+
|
157
|
+
state :operators do
|
158
|
+
rule %r/\.\./, Operator
|
159
|
+
rule %r/[+\-*\/<>=!&|~]/, Operator
|
160
|
+
rule %r/[\[\].{}:;,()]/, Punctuation
|
161
|
+
end
|
162
|
+
|
163
|
+
state :keywords do
|
164
|
+
rule %r/(const)(\s+)/ do |m|
|
165
|
+
token Keyword::Constant, m[1]
|
166
|
+
token Text, m[2]
|
167
|
+
end
|
168
|
+
|
169
|
+
rule %r/"/, Literal::String::Double
|
170
|
+
|
171
|
+
rule %r/(switch)([^{]*)({)/ do |m|
|
172
|
+
token Keyword, m[1]
|
173
|
+
recurse m[2]
|
174
|
+
token Punctuation, m[3]
|
175
|
+
end
|
176
|
+
|
177
|
+
rule %r/(arg|result)(#{ws}+)(hints)(:)/ do |m|
|
178
|
+
token Name::Property, m[1]
|
179
|
+
recurse m[2]
|
180
|
+
token Name::Property, m[3]
|
181
|
+
token Punctuation, m[4]
|
182
|
+
end
|
183
|
+
|
184
|
+
rule %r/(returns)(#{ws}*)(to)/ do |m|
|
185
|
+
token Keyword, m[1]
|
186
|
+
recurse m[2]
|
187
|
+
token Keyword, m[3]
|
188
|
+
end
|
189
|
+
|
190
|
+
rule %r/(never)(#{ws}*)(returns)/ do |m|
|
191
|
+
token Keyword, m[1]
|
192
|
+
recurse m[2]
|
193
|
+
token Keyword, m[3]
|
194
|
+
end
|
195
|
+
|
196
|
+
rule %r{(return)(#{ws}*)(\()} do |m|
|
197
|
+
token Keyword, m[1]
|
198
|
+
recurse m[2]
|
199
|
+
token Punctuation, m[3]
|
200
|
+
end
|
201
|
+
|
202
|
+
rule %r{(if|else|goto|call|offset|import|jump|ccall|foreign|prim|case|unwind|export|reserve|push)(#{ws})} do |m|
|
203
|
+
token Keyword, m[1]
|
204
|
+
recurse m[2]
|
205
|
+
end
|
206
|
+
|
207
|
+
rule %r{(default)(#{ws}*)(:)} do |m|
|
208
|
+
token Keyword, m[1]
|
209
|
+
recurse m[2]
|
210
|
+
token Punctuation, m[3]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
state :types do
|
215
|
+
# Memory access: `type[42]`
|
216
|
+
# Note: Only a token for type is produced.
|
217
|
+
rule %r/(#{id})(?=\[[^\]])/ do |m|
|
218
|
+
token Keyword::Type, m[1]
|
219
|
+
end
|
220
|
+
|
221
|
+
# Array type: `type[]`
|
222
|
+
rule %r/(#{id}\[\])/ do |m|
|
223
|
+
token Keyword::Type, m[1]
|
224
|
+
end
|
225
|
+
|
226
|
+
# Capture macro substitutions before lexing typed declarations
|
227
|
+
# I.e. there is no type in `PREPROCESSOR_MACRO_VARIABLE someFun()`
|
228
|
+
rule %r{
|
229
|
+
(^#{id})
|
230
|
+
(#{ws}+)
|
231
|
+
(#{id})
|
232
|
+
(#{ws}*)
|
233
|
+
(\()
|
234
|
+
}mx do |m|
|
235
|
+
token Name::Label, m[1]
|
236
|
+
recurse m[2]
|
237
|
+
token Name::Function, m[3]
|
238
|
+
recurse m[4]
|
239
|
+
token Punctuation, m[5]
|
240
|
+
end
|
241
|
+
|
242
|
+
# Type in variable or parameter declaration:
|
243
|
+
# `type /* optional whitespace */ var_name /* optional whitespace */;`
|
244
|
+
# `type /* optional whitespace */ var_name /* optional whitespace */, var_name2`
|
245
|
+
# `(type /* optional whitespace */ var_name /* optional whitespace */)`
|
246
|
+
# Note: Only the token for type is produced here.
|
247
|
+
rule %r{
|
248
|
+
(^#{id})
|
249
|
+
(#{ws}+)
|
250
|
+
(#{id})
|
251
|
+
}mx do |m|
|
252
|
+
token Keyword::Type, m[1]
|
253
|
+
recurse m[2]
|
254
|
+
token Name::Label, m[3]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
state :infos do
|
259
|
+
rule %r/(args|res|upd|label|rep|srt|arity|fun_type|arg_space|updfr_space)(:)/ do |m|
|
260
|
+
token Name::Property, m[1]
|
261
|
+
token Punctuation, m[2]
|
262
|
+
end
|
263
|
+
|
264
|
+
rule %r/(stack_info)(:)/ do |m|
|
265
|
+
token Name::Entity, m[1]
|
266
|
+
token Punctuation, m[2]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
state :names do
|
271
|
+
rule %r/(::)(#{ws}*)([A-Z]\w+)/ do |m|
|
272
|
+
token Operator, m[1]
|
273
|
+
recurse m[2]
|
274
|
+
token Keyword::Type, m[3]
|
275
|
+
end
|
276
|
+
|
277
|
+
rule %r/<(#{id})>/, Name::Builtin
|
278
|
+
|
279
|
+
rule %r/(Sp|SpLim|Hp|HpLim|HpAlloc|BaseReg|CurrentNursery|CurrentTSO|R\d{1,2}|gcptr)(?!#{id})/, Name::Variable::Global
|
280
|
+
rule %r/([A-Z]#{id})(\.)/ do |m|
|
281
|
+
token Name::Namespace, m[1]
|
282
|
+
token Punctuation, m[2]
|
283
|
+
push :namespace_name
|
284
|
+
end
|
285
|
+
|
286
|
+
# Inline function calls:
|
287
|
+
# ```
|
288
|
+
# arg1 `lt` arg2
|
289
|
+
# ```
|
290
|
+
rule %r/(`)(#{id})(`)/ do |m|
|
291
|
+
token Punctuation, m[1]
|
292
|
+
token Name::Function, m[2]
|
293
|
+
token Punctuation, m[3]
|
294
|
+
end
|
295
|
+
|
296
|
+
# Function: `name /* optional whitespace */ (`
|
297
|
+
# Function (arguments via explicit stack handling): `name /* optional whitespace */ {`
|
298
|
+
rule %r{(?=
|
299
|
+
#{complex_id}
|
300
|
+
#{ws}*
|
301
|
+
[\{\(]
|
302
|
+
)}mx do
|
303
|
+
push :function
|
304
|
+
end
|
305
|
+
|
306
|
+
rule %r/CLOSURE/, Keyword::Type
|
307
|
+
rule %r/#{complex_id}/, Name::Label
|
308
|
+
end
|
309
|
+
|
310
|
+
state :namespace_name do
|
311
|
+
rule %r/([A-Z]#{id})(\.)/ do |m|
|
312
|
+
token Name::Namespace, m[1]
|
313
|
+
token Punctuation, m[2]
|
314
|
+
end
|
315
|
+
|
316
|
+
rule %r{(#{complex_id})(#{ws}*)([\{\(])}mx do |m|
|
317
|
+
token Name::Function, m[1]
|
318
|
+
recurse m[2]
|
319
|
+
token Punctuation, m[3]
|
320
|
+
pop!
|
321
|
+
end
|
322
|
+
|
323
|
+
rule %r/#{complex_id}/, Name::Label, :pop!
|
324
|
+
|
325
|
+
rule %r/(?=.)/m do
|
326
|
+
pop!
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
state :function do
|
331
|
+
rule %r/INFO_TABLE_FUN|INFO_TABLE_CONSTR|INFO_TABLE_SELECTOR|INFO_TABLE_RET|INFO_TABLE/, Name::Builtin
|
332
|
+
rule %r/%#{id}/, Name::Builtin
|
333
|
+
rule %r/#{complex_id}/, Name::Function
|
334
|
+
rule %r/\s+/, Text
|
335
|
+
rule %r/[({]/, Punctuation, :pop!
|
336
|
+
mixin :comments
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|