lib/rouge/lexers/crystal.rb in rouge-4.2.1 vs lib/rouge/lexers/crystal.rb in rouge-4.3.0
- old
+ new
@@ -19,11 +19,11 @@
state :symbols do
# symbols
rule %r(
: # initial :
@{0,2} # optional ivar, for :@foo and :@@foo
- [a-z_]\w*[!?]? # the symbol
+ [\p{Ll}_]\p{Word}*[!?]? # the symbol
)xi, Str::Symbol
# special symbols
rule %r(:(?:===|=?~|\[\][=?]?|\*\*=?|\/\/=?|[=^*/+-]=?|&[&*+-]?=?|\|\|?=?|![=~]?|%=?|<=>|<<?=?|>>?=?|\.\.\.?)), Str::Symbol
@@ -33,11 +33,11 @@
state :sigil_strings do
# %-sigiled strings
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
- rule %r/%([rqswQWxiI])?([^\w\s}])/ do |m|
+ rule %r/%([rqswQWxiI])?([^\p{Word}\s}])/ do |m|
open = Regexp.escape(m[2])
close = Regexp.escape(delimiter_map[m[2]] || m[2])
interp = /[rQWxI]/ === m[1]
toktype = Str::Other
@@ -75,11 +75,11 @@
end
end
state :strings do
mixin :symbols
- rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
+ rule %r/\b[\p{Ll}_]\p{Word}*?[?!]?:\s+/, Str::Symbol, :expr_start
rule %r/"/, Str::Double, :simple_string
rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
rule %r/(')(\\u[a-fA-F0-9]{4}|\\u\{[a-fA-F0-9]{1,6}\}|\\[abefnrtv])?(\\\\|\\'|[^'])*(')/ do
groups Str::Single, Str::Escape, Str::Single, Str::Single
end
@@ -164,13 +164,13 @@
rule %r/[\d]+(?:_\d+)*(_[iu]\d+)?/, Num::Integer
rule %r/@\[([^\]]+)\]/, Name::Decorator
# names
- rule %r/@@[a-z_]\w*/i, Name::Variable::Class
- rule %r/@[a-z_]\w*/i, Name::Variable::Instance
- rule %r/\$\w+/, Name::Variable::Global
+ rule %r/@@[\p{Ll}_]\p{Word}*/i, Name::Variable::Class
+ rule %r/@[\p{Ll}_]\p{Word}*/i, Name::Variable::Instance
+ rule %r/\$\p{Word}+/, Name::Variable::Global
rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
rule %r/::/, Operator
mixin :strings
@@ -179,11 +179,11 @@
rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
rule %r(
(module)
(\s+)
- ([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)
+ ([\p{L}_][\p{L}0-9_]*(::[\p{L}_][\p{L}0-9_]*)*)
)x do
groups Keyword, Text, Name::Namespace
end
rule %r/(def|macro\b)(\s*)/ do
@@ -205,29 +205,29 @@
# `..` and `...` for ranges must have higher priority than `.`
# Otherwise, they will be parsed as :method_call
rule %r/\.{2,3}/, Operator, :expr_start
- rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
- rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
+ rule %r/[\p{Lu}][\p{L}0-9_]*/, Name::Constant, :method_call
+ rule %r/(\.|::)(\s*)([\p{Ll}_]\p{Word}*[!?]?|[*%&^`~+-\/\[<>=])/ do
groups Punctuation, Text, Name::Function
push :method_call
end
- rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
- rule %r/[a-zA-Z_]\w*/, Name, :method_call
+ rule %r/[\p{L}_]\p{Word}*[?!]/, Name, :expr_start
+ rule %r/[\p{L}_]\p{Word}*/, Name, :method_call
rule %r/\*\*|\/\/|>=|<=|<=>|<<?|>>?|=~|={3}|!~|&&?|\|\||\./,
Operator, :expr_start
rule %r/{%|%}/, Punctuation
rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
rule %r<[\])}]>, Punctuation
end
state :has_heredocs do
- rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
+ rule %r/(?<!\p{Word})(<<[-~]?)(["`']?)([\p{L}_]\p{Word}*)(\2)/ do |m|
token Operator, m[1]
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
push :heredoc_queue unless state? :heredoc_queue
end
@@ -280,13 +280,13 @@
state :funcname do
rule %r/\s+/, Text
rule %r/\(/, Punctuation, :defexpr
rule %r(
- (?:([a-zA-Z_]\w*)(\.))?
+ (?:([\p{L}_]\p{Word}*)(\.))?
(
- [a-zA-Z_]\w*[!?]? |
+ [\p{L}_]\p{Word}*[!?]? |
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
<<? | >>? | <=>? | >= | ===?
)
)x do |m|
puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
@@ -309,11 +309,11 @@
rule %r/<</ do
token Operator
goto :expr_start
end
- rule %r/[A-Z_]\w*/, Name::Class, :pop!
+ rule %r/[\p{Lu}_]\p{Word}*/, Name::Class, :pop!
rule(//) { pop! }
end
state :ternary do
@@ -341,11 +341,11 @@
mixin :root
end
state :string_intp do
rule %r/[#][{]/, Str::Interpol, :in_interp
- rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
+ rule %r/#(@@?|\$)[\p{Ll}_]\p{Word}*/i, Str::Interpol
end
state :string_intp_escaped do
mixin :string_intp
rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
@@ -397,10 +397,10 @@
# char operator. ?x evaulates to "x", unless there's a digit
# beforehand like x>=0?n[x]:""
rule %r(
[?](\\[MC]-)* # modifiers
(\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
- (?!\w)
+ (?!\p{Word})
)x, Str::Char, :pop!
# special case for using a single space. Ruby demands that
# these be in a single line, otherwise it would make no sense.
rule %r/(\s*)(%[rqswQWxiI]? \S* )/ do