@@ -25,8 +25,7 @@ def self.detect?(text)
25
25
)xi , Str ::Symbol
26
26
27
27
# special symbols
28
- rule %r(:(?:\* \* |[-+]@|[/\% &\| ^`~]|\[ \] =?|<<|>>|<=?>|<=?|===?)) ,
29
- Str ::Symbol
28
+ rule %r(:(?:===|=?~|\[ \] [=?]?|\* \* =?|\/ \/ =?|[=^*/+-]=?|&[&*+-]?=?|\| \| ?=?|![=~]?|%=?|<=>|<<?=?|>>?=?|\. \. \. ?)) , Str ::Symbol
30
29
31
30
rule %r/:'(\\ \\ |\\ '|[^'])*'/ , Str ::Symbol
32
31
rule %r/:"/ , Str ::Symbol , :simple_sym
@@ -36,7 +35,7 @@ def self.detect?(text)
36
35
# %-sigiled strings
37
36
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
38
37
delimiter_map = { '{' => '}' , '[' => ']' , '(' => ')' , '<' => '>' }
39
- rule %r/%([rqswQWxiI])?([^\w \s ])/ do |m |
38
+ rule %r/%([rqswQWxiI])?([^\w \s } ])/ do |m |
40
39
open = Regexp . escape ( m [ 2 ] )
41
40
close = Regexp . escape ( delimiter_map [ m [ 2 ] ] || m [ 2 ] )
42
41
interp = /[rQWxI]/ === m [ 1 ]
@@ -79,9 +78,11 @@ def self.detect?(text)
79
78
state :strings do
80
79
mixin :symbols
81
80
rule %r/\b [a-z_]\w *?[?!]?:\s +/ , Str ::Symbol , :expr_start
82
- rule %r/'(\\ \\ |\\ '|[^'])*'/ , Str ::Single
83
81
rule %r/"/ , Str ::Double , :simple_string
84
82
rule %r/(?<!\. )`/ , Str ::Backtick , :simple_backtick
83
+ rule %r/(')(\\ u[a-fA-F0-9]{4}|\\ u\{ [a-fA-F0-9]{1,6}\} |\\ [abefnrtv])?(\\ \\ |\\ '|[^'])*(')/ do
84
+ groups Str ::Single , Str ::Escape , Str ::Single , Str ::Single
85
+ end
85
86
end
86
87
87
88
state :regex_flags do
@@ -154,11 +155,13 @@ def self.detect?(text)
154
155
mixin :whitespace
155
156
rule %r/__END__/ , Comment ::Preproc , :end_part
156
157
157
- rule %r/0_? [0-7]+(?:_[0-7]+)*/ , Num ::Oct
158
+ rule %r/0o [0-7]+(?:_[0-7]+)*/ , Num ::Oct
158
159
rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/ , Num ::Hex
159
160
rule %r/0b[01]+(?:_[01]+)*/ , Num ::Bin
160
- rule %r/\d +\. \d +(e[\+ \- ]?\d +)?/ , Num ::Float
161
- rule %r/[\d ]+(?:_\d +)*/ , Num ::Integer
161
+ rule %r/\d +\. \d +(e[\+ \- ]?\d +)?(_f32)?/i , Num ::Float
162
+ rule %r/\d +(e[\+ \- ]?\d +)/i , Num ::Float
163
+ rule %r/\d +_f32/i , Num ::Float
164
+ rule %r/[\d ]+(?:_\d +)*(_[iu]\d +)?/ , Num ::Integer
162
165
163
166
rule %r/@\[ ([^\] ]+)\] / , Name ::Decorator
164
167
@@ -183,7 +186,7 @@ def self.detect?(text)
183
186
groups Keyword , Text , Name ::Namespace
184
187
end
185
188
186
- rule %r/(def\b )(\s *)/ do
189
+ rule %r/(def|macro \b )(\s *)/ do
187
190
groups Keyword , Text
188
191
push :funcname
189
192
end
@@ -214,6 +217,7 @@ def self.detect?(text)
214
217
rule %r/[a-zA-Z_]\w */ , Name , :method_call
215
218
rule %r/\* \* |\/ \/ |>=|<=|<=>|<<?|>>?|=~|={3}|!~|&&?|\| \| |\. / ,
216
219
Operator , :expr_start
220
+ rule %r/{%|%}/ , Punctuation
217
221
rule %r/[-+\/ *%=<>&!^|~]=?/ , Operator , :expr_start
218
222
rule ( /[?]/ ) { token Punctuation ; push :ternary ; push :expr_start }
219
223
rule %r<[\[ ({,:\\ ;/]> , Punctuation , :expr_start
@@ -346,6 +350,7 @@ def self.detect?(text)
346
350
mixin :string_intp
347
351
rule %r/\\ ([\\ abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/ ,
348
352
Str ::Escape
353
+ rule %r/\\ u([a-fA-F0-9]{4}|\{ [^}]+\} )/ , Str ::Escape
349
354
rule %r/\\ ./ , Str ::Escape
350
355
end
351
356
0 commit comments