Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions runtime/syntax/gleam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
filetype: gleam

detect:
filename: "\\.gleam$"

rules:
# 1. Base Identifier Rule (Must be first so specific types below overwrite it)
- identifier: "\\b[A-Z][a-zA-Z0-9_]*\\b"

# 2. Built-in Types (Overwrites the identifier rule for these exact matches; Nil removed)
- type: "\\b(Int|Float|String|Bool|List|Option|Result|BitArray)\\b"

# 3. Constants (Nil safely kept here)
- constant: "\\b(True|False|Nil)\\b"

# 4. Keywords
- statement: "\\b(fn|let|case|if|use|import|pub|type|opaque|const|as|assert|panic|todo|echo)\\b"

# 5. Attributes / Decorators (Added for @external, @deprecated, etc.)
- preproc: "@[a-zA-Z0-9_]+"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too permissive. I'm not sure if Gleam even has anything besides @external and @deprecated right now but if we follow vim's example we should only allow lowercase here: 1

Suggested change
- preproc: "@[a-zA-Z0-9_]+"
- preproc: "@[a-z][a-z_]*"

Footnotes

  1. https://github.com/vim/vim/blob/e21c4a649a830716599eadebad04ddf2393230bc/runtime/syntax/gleam.vim#L65


# 6. Operators (Moved to 'statement' for red highlighting; arithmetic, float math, and assignment added)
- statement: "(\\|>|->|<-|\\.\\.|<>|==|!=|<=|>=|&&|\\|\\||\\+\\.|-\\.|\\*\\.|/\\.|\\+|-|\\*|/|%|=|<|>)"

# 7. Numbers (Copied directly from Python's robust micro syntax as the maintainer requested)
- constant.number: "\\b0b[01]+\\b"
- constant.number: "\\b0o[0-7]+\\b"
- constant.number: "\\b0x[0-9a-fA-F]+\\b"
- constant.number: "\\b[0-9]+\\.[0-9]*([eE][+-]?[0-9]+)?\\b"
- constant.number: "\\b[0-9]+\\b"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contrary to what the comment claims these are not copied from Python, they're missing support for underscores.


# 8. Strings
- constant.string:
start: '"'
end: '"'
skip: "\\\\."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
skip: "\\\\."
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."

Copy link
Copy Markdown
Contributor Author

@HiwarkhedePrasad HiwarkhedePrasad Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Andriamanitra, thanks again for the detailed feedback! I've made all the suggested changes:

  • Numbers now support underscores (e.g., 1_000_000)
  • Added float comparison operators (<., >., <=., >=.)
  • String escapes are now highlighted as special characters
  • Added tuple syntax #(...) highlighting
  • Attributes are now restricted to lowercase only

Comment thread
HiwarkhedePrasad marked this conversation as resolved.
Outdated
# 9. Comments
- comment:
start: "//"
end: "$"