# ASnake syntax highlighting rules for micro
# modified from: https://github.com/scopatz/nanorc/blob/master/python.nanorc
# meaning license is GPLv3
# version date: 12-23-2025
filetype: asnake

detect:
    filename: "\\.[aA][sS]nake$"
    header: "^#!.*(env +)?([pP]ython|[aA][sS]nake)[-0-9._]*( |$)"

rules:
    # built-in objects
    - constant: "\\b(Ellipsis|None|self|cls|True|False)\\b"
      # built-in attributes
    - constant: "\\b(__bases__|__builtin__|__class__|__debug__|__dict__|__doc__|__file__|__members__|__methods__|__name__|__self__)\\b"
      # built-in functions
    - identifier: "\\b(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dir|divmod|eval|exec|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|max|min|next|nonlocal|oct|open|ord|pow|print|repr|round|setattr|sorted|sum|vars|__import__)\\b"
      # special method names
    - identifier: "\\b__(abs|add|and|call|cmp|coerce|complex|concat|contains|delattr|delitem|delslice|del|dict|divmod|div|float|getattr|getitem|getslice|hash|hex|iadd|iand|iconcat|ifloordiv|ilshift|imatmul|imod|imul|init|int|invert|inv|ior|ipow|irshift|isub|iter|itruediv|ixor|len|long|lshift|mod|mul|neg|next|nonzero|oct|or|pos|pow|radd|rand|rcmp|rdivmod|rdiv|repeat|repr|rlshift|rmod|rmul|ror|rpow|rrshift|rshift|rsub|rxor|setattr|setitem|setslice|str|sub|xor)__\\b"
      # types
    - type: "\\b(bool|bytearray|bytes|classmethod|complex|dict|enumerate|filter|float|frozenset|int|list|map|memoryview|object|property|range|reversed|set|slice|staticmethod|str|super|tuple|type|zip)\\b"
      # definitions
    - identifier: "\\bc?def\\s+[A-Za-z_][A-Za-z0-9_]*\\b"
      # keywords
    - statement: "\\b(and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|raise|return|try|while|with|yield)\\b"
    - statement: "\\<(from|equals|greater|less|minus|nothing|plus|power|remainder|than|times|modulo|are(n'?t)?|const|constant|pipe|into|to|exponent|isn'?t|and|as|assert|async|await|break|class|continue|del|global|import|in|is|lambda|map|not|or|pass|raise|return|yield)\\>"
      # exception classes
    - identifier: "\\<(Exception|StandardError|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|EOFError|FloatingPointError|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RuntimeError|SyntaxError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|ValueError|WindowsError|ZeroDivisionError)\\>"
      # decorators
    - preproc: "@[A-Za-z_][A-Za-z0-9_]*\\s*\\("
      # operators
    - symbol.operator: "[\\.\\:;,+\\*\\|=\\!\\%\\@\\<\\>\\/\\-\\&]+"
      # parentheses
    - symbol.brackets: "[()\\{\\}\\[\\]]+"
      # numbers
    - constant.number: "\\b(([1-9][0-9]+)|0+)\\.[0-9]+j?\\b"
    - constant.number: "\\b([1-9][0-9]*[Lj]?)\\b"
    - constant.number: "\\b0o?[0-7]*L?\\b"
    - constant.number: "\\b0x[1-9a-f][0-9a-f]*L?\\b"
    - constant.number: "\\b0b[01]+\\b"
    - constant.number: "\\b[0-9]+\\.[0-9]+\\b"

    - constant.string:
        start: "[ubrUBR]*?\"\"\""
        end: "\"\"\""
        rules: []

    - constant.string:
        start: "[ubrUBR]*?'''"
        end: "'''"
        rules: []

    - constant.string:
        start: "[ubrUBR]*?[fF][ubrUBR]*?[\'\"]"
        end: '\{|$'
        rules: []
    - constant.string:
        start: '\}'
        end: '[''"\{]|$'
        rules: []

    - constant.string:
        start: "(\\b|[ubrUBR]*?)\""
        end: "(\"|$)"
        skip: "\\\\."
        rules:
            - constant.specialChar: "\\\\."

    - constant.string:
        start: "(\\b|[ubrUBR]*?)'"
        end: "('|$)"
        skip: "\\\\."
        rules:
            - constant.specialChar: "\\\\."
            
    - comment:
        start: "#"
        end: "$"
        rules:  # AKA Code tags (PEP 350)
            - todo: "(TODO|FIXME|HACK|BUG|NOTE|FAQ|MNEMONIC|REQ|RFE|IDEA|PORT|\\?\\?\\?|!!!|GLOSS|SEE|TODOC|STAT|RVD|CRED):?"

    # comptime / meta
    - identifier.macro: "\\$ *\\w+? *(\\w *)*?="
    - symbol.operator: "\\$"

