class_docstr: For Crystal source code.
  
  .. versionadded:: 2.2
class_docstr_tok: ["For","Crystal","source","code",".","..","versionadded",":",":","2.2"]
code: def gen_crystalstrings_rules():
      states = {}
      states["strings"] = [
          (r"\:\w+[!?]?", String.Symbol),
          (words(CRYSTAL_OPERATORS, prefix=r"\:"), String.Symbol),
          (r":'(\\\\|\\[^\\]|[^'\\])*'", String.Symbol),
          # This allows arbitrary text after '\ for simplicity
          (r"'(\\\\|\\'|[^']|\\[^'\\]+)'", String.Char),
          (r':"', String.Symbol, "simple-sym"),
          # Crystal doesn't have "symbol:"s but this simplifies function args
          (
              r"([a-zA-Z_]\w*)(:)(?!:)",
              bygroups(String.Symbol, Punctuation),
          ),
          (r'"', String.Double, "simple-string"),
          (r"(?<!\.)`", String.Backtick, "simple-backtick"),
      ]
  
      # double-quoted string and symbol
      for name, ttype, end in (
          ("string", String.Double, '"'),
          ("sym", String.Symbol, '"'),
          ("backtick", String.Backtick, "`"),
      ):
          states["simple-" + name] = [
              include(
                  "string-escaped"
                  if name == "sym"
                  else "string-intp-escaped"
              ),
              (r"[^\\%s#]+" % end, ttype),
              (r"[\\#]", ttype),
              (end, ttype, "#pop"),
          ]
  
      # https://crystal-lang.org/docs/syntax_and_semantics/literals/string.html#percent-string-literals
      for lbrace, rbrace, bracecc, name in (
          ("\\{", "\\}", "{}", "cb"),
          ("\\[", "\\]", "\\[\\]", "sb"),
          ("\\(", "\\)", "()", "pa"),
          ("<", ">", "<>", "ab"),
          ("\\|", "\\|", "\\|", "pi"),
      ):
          states[name + "-intp-string"] = (
              [
                  (r"\\" + lbrace, String.Other),
              ]
              + (lbrace != rbrace)
              * [
                  (lbrace, String.Other, "#push"),
              ]
              + [
                  (rbrace, String.Other, "#pop"),
                  include("string-intp-escaped"),
                  (r"[\\#" + bracecc + "]", String.Other),
                  (r"[^\\#" + bracecc + "]+", String.Other),
              ]
          )
          states["strings"].append(
              (r"%Q?" + lbrace, String.Other, name + "-intp-string")
          )
          states[name + "-string"] = (
              [
                  (r"\\[\\" + bracecc + "]", String.Other),
              ]
              + (lbrace != rbrace)
              * [
                  (lbrace, String.Other, "#push"),
              ]
              + [
                  (rbrace, String.Other, "#pop"),
                  (r"[\\#" + bracecc + "]", String.Other),
                  (r"[^\\#" + bracecc + "]+", String.Other),
              ]
          )
          # https://crystal-lang.org/docs/syntax_and_semantics/literals/array.html#percent-array-literals
          states["strings"].append(
              (r"%[qwi]" + lbrace, String.Other, name + "-string")
          )
          states[name + "-regex"] = (
              [
                  (r"\\[\\" + bracecc + "]", String.Regex),
              ]
              + (lbrace != rbrace)
              * [
                  (lbrace, String.Regex, "#push"),
              ]
              + [
                  (rbrace + "[imsx]*", String.Regex, "#pop"),
                  include("string-intp"),
                  (r"[\\#" + bracecc + "]", String.Regex),
                  (r"[^\\#" + bracecc + "]+", String.Regex),
              ]
          )
          states["strings"].append(
              (r"%r" + lbrace, String.Regex, name + "-regex")
          )
  
      return states
  
imports: import re
  from pygments.lexer import ExtendedRegexLexer, include, bygroups, default, words, line_re
  from pygments.token import Comment, Operator, Keyword, Name, String, Number, Punctuation, Error, Whitespace
label_desc: Use image node_id 2 for calling the CrystalLexer obj's underlying member method code with example usage: obj.gen_crystalstrings_rules() and returns: states