
Description="Rust"

Categories = {"source"}

Digits=[[ (?:0x|0o|0b)[0-9a-fA-F\_uif]+|\d+[\.]?[\d\_uif]+(?:[eE][\-\+][\d\_uif]+)?|\d+ ]]

Keywords={
  { Id=1,
    List={"as", "async", "await", "box", "break", "const", "continue", "crate", "else",
          "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop",
          "match", "mod", "move", "mut", "pub", "ref", "return", "self",
          "Self", "static", "super", "trait", "true", "try", "type",
          "unsafe", "use", "where", "while", "abstract", "alignof", "become",
          "do", "final", "macro", "offsetof", "override", "priv", "pure",
          "sizeof", "typeof", "unsized", "virtual", "yield", "auto", "catch"
        }
  },
  { Id=2,
    List= { "u8", "u16", "u32", "u64", "i8", "i16", "i32", "i64",
            "f32", "f64", "usize", "isize", "char", "str", "struct","enum"
          }
  },

  -- weak keywords
  { Id=3,
    List= { "default", "dyn", "union"
          }
  },
  { Id=4,
    Regex=[[(\w+\!?)\s*\(]]
  },
  { Id=5,
    Regex=[[b'(?:[\x00-\x08\x0B\x0C\x0E-\x26\x28-\x5B\x5D-\x7F]|\\(?:[0tnr\'\\]|x[0-9a-fA-F]{2}))']]
  },

  --see OnStateChange
  { Id=6,
    Regex=[[#+\"]]
  },

  { Id=7,
    Regex=[[\"#+]]
  }
}

Strings = {
  Delimiter=[["]],
  RawPrefix="r",
  Escape = [[ \\[\'\\\"aftnrv]|\\x[0-9a-fA-F]{2}|\\U\{[0-9a-fA-F]{8}\}|\\u\{[0-9a-fA-F]{4}\}|\\x?? ]],
  Interpolation=[[ \{\S*?\} ]]
}

Comments = {
  { Block=true,
    Nested=true,
    Delimiter = { [[\/\*]], [[\*\/]] }
  },
  {
    Block=false,
    Delimiter = { [[//]] }
  }
}

IgnoreCase=false

--PreProcessor = {
--  Prefix=[[#]],
--  Continuation="\\",
--}

Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\.|\:|\&|<|>|\!|=|\/|\*|\%|\+|\-|\~|\||\^']]

EnableIndentation=true

-- fix raw string literals  https://doc.rust-lang.org/reference/tokens.html#byte-string-literals
function OnStateChange(oldState, newState, token, groupID)

  if token == endDelim then
    endDelim = nil
    return HL_STRING_END
  end

  if  groupID==6 and oldState ~= HL_STRING then
    endDelim = string.reverse(token)
    return HL_STRING
  end

end
