Skip to content

Instantly share code, notes, and snippets.

@raspberrypisig
Created March 4, 2026 06:24
Show Gist options
  • Select an option

  • Save raspberrypisig/9e13a526c45e0a597438fdff39de8648 to your computer and use it in GitHub Desktop.

Select an option

Save raspberrypisig/9e13a526c45e0a597438fdff39de8648 to your computer and use it in GitHub Desktop.
micro editor mojo
filetype: mojo
detect:
filename: "\\.mojo$"
header: "^#!.*/(env +)?mojo$"
rules:
# 1. Variable Declarations & Modifiers
# Mojo specific: var, let, alias, comptime, raises, capturing
- preproc: "\\b(var|let|alias|comptime|raises|capturing)\\b"
# 2. Booleans and None
- constant: "\\b(True|False|None|NotImplemented|Ellipsis)\\b"
# 3. Standard Exceptions (From MagicPython JSON)
- constant: "\\b((Arithmetic|Assertion|Attribute|Buffer|BlockingIO|BrokenPipe|ChildProcess|Connection(Aborted|Refused|Reset)?|EOF|Environment|FileExists|FileNotFound|FloatingPoint|IO|Import|Indentation|Index|Interrupted|IsADirectory|NotADirectory|Permission|ProcessLookup|Timeout|Key|Lookup|Memory|Name|NotImplemented|OS|Overflow|Reference|Runtime|Recursion|Syntax|System|Tab|Type|UnboundLocal|Unicode(Encode|Decode|Translate)?|Value|Windows|ZeroDivision|ModuleNotFound)Error|((Pending)?Deprecation|Runtime|Syntax|User|Future|Import|Unicode|Bytes|Resource)?Warning|SystemExit|Stop(Async)?Iteration|KeyboardInterrupt|GeneratorExit|(Base)?Exception)\\b"
# 4. Built-in Data Types
# Python Standard + Mojo Specific (Int, SIMD, DType, etc.) + MLIR 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|Int|Int8|Int16|Int32|Int64|UInt|UInt8|UInt16|UInt32|UInt64|Float|Float16|Float32|Float64|BFloat16|String|List|Dict|Tuple|Set|Optional|SIMD|DType|Scalar|Array|Tensor|Matrix|FileHandle|Path|Regex|Error|Variant|Pointer|UnsafePointer|Reference|Span|AnyType|NoneType|Collection|Sized|Iterable|Iterator|Keyable|Writable|Readable|Stringable|Movable|Copyable|Destructable|__mlir_attr|__mlir_op|__mlir_type)\\b"
# 5. Magic Methods (Dunder methods)
# Python standard + Mojo specific lifecycle (__copyinit__, __moveinit__)
- 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|copyinit|moveinit|mlir_op|mlir_type)__\\b"
# 6. 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__|constrained|alias|var|let|invert|offset|swizzle|simd|bitcast|print_no_error|element|address|with_malloc|zero|sleep|tight_loop|typeassert|Parameter)\\b"
# 7. Function Definitions
- identifier: "((def|fn) [a-zA-Z_0-9]+)"
# 8. Keywords
# Control flow + Mojo keywords (struct, trait, ownership)
- 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|fn|struct|trait|inout|ref|owned|borrow|where)\\b"
# 9. Decorators
- preproc: "^\\s*@[^(]*"
# 10. Operators (Mojo adds arrow ->)
- symbol.operator: "([~^.:;,+*|=!\\%@]|<|>|/|-|&|->)"
# 11. Brackets
- symbol.brackets: "([(){}]|\\[|\\])"
# 12. Numbers
- constant.number: "\\b[0-9](_?[0-9])*(\\.([0-9](_?[0-9])*)?)?(e[0-9](_?[0-9])*)?\\b"
- constant.number: "\\b0b(_?[01])+\\b"
- constant.number: "\\b0o(_?[0-7])+\\b"
- constant.number: "\\b0x(_?[0-9a-fA-F])+\\b"
# 13. Strings
- constant.string:
start: "\"\"\""
end: "\"\"\""
rules: []
- constant.string:
start: "'''"
end: "'''"
rules: []
- constant.string:
start: "\""
end: "(\"|$)"
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- constant.string:
start: "'"
end: "('|$)"
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- comment:
start: "#"
end: "$"
rules:
- todo: "(TODO|FIXME|HACK|BUG|NOTE):?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment