Skip to content

Commit

Permalink
support non-ascii identifiers in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Jul 22, 2021
1 parent 3eec114 commit 6b3ea77
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/ace/mode/rust_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var stringEscape = /\\(?:[nrt0'"\\]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\})/.source;
var wordPattern = /[a-zA-Z_\xa1-\uffff][a-zA-Z0-9_\xa1-\uffff]*/.source;
var RustHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
Expand All @@ -46,11 +47,11 @@ var RustHighlightRules = function() {
// `(?![\\\'])` to keep a lifetime name highlighting from continuing one character
// past the name. The end `\'` will block this from matching for a character like
// `'a'` (it should have character highlighting, not variable highlighting).
regex: '\'[a-zA-Z_][a-zA-Z0-9_]*(?![\\\'])' },
regex: '\'' + wordPattern + '(?![\\\'])' },
{ token: 'string.quoted.single.source.rust',
regex: "'(?:[^'\\\\]|" + stringEscape + ")'" },
{ token: 'identifier',
regex: /r#[a-zA-Z_][a-zA-Z0-9_]*\b/ },
regex: "r#" + wordPattern + "\\b" },
{
stateName: "bracketedComment",
onMatch : function(value, currentState, stack){
Expand Down Expand Up @@ -90,8 +91,8 @@ var RustHighlightRules = function() {
regex: stringEscape },
{ defaultToken: 'string.quoted.double.source.rust' } ] },
{ token: [ 'keyword.source.rust', 'text', 'entity.name.function.source.rust' ],
regex: '\\b(fn)(\\s+)((?:r#)?[a-zA-Z_][a-zA-Z0-9_]*)' },
{ token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
regex: '\\b(fn)(\\s+)((?:r#)?'+ wordPattern + ')' },
{ token: 'support.constant', regex: wordPattern + '::' },
{ token: 'keyword.source.rust',
regex: '\\b(?:abstract|alignof|as|async|await|become|box|break|catch|continue|const|crate|default|do|dyn|else|enum|extern|for|final|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|proc|pub|pure|ref|return|self|sizeof|static|struct|super|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\\b' },
{ token: 'storage.type.source.rust',
Expand Down

0 comments on commit 6b3ea77

Please sign in to comment.