Skip to content
Merged
Changes from 2 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
19 changes: 19 additions & 0 deletions runtime/syntax/gleam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
filetype: gleam

detect:
filename: "\\.gleam$"

rules:
- statement: "\\b(fn|let|case|if|use|import|pub|type|opaque|const|as|assert|panic|todo|echo)\\b"
- identifier: "\\b(Int|Float|String|Bool|List|Option|Result|Nil|BitArray)\\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.

I would remove Nil from here since it's also in constant.

- constant: "\\b(True|False|Nil)\\b"
- operator: "(\\|>|->|<>|==|!=|<=|>=|&&|\\|\\|)"
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.

Most syntaxes choose to use statement for operators (to color them red in the default colorscheme). Most built-in colorschemes color operator with the default (white) color. The list is missing assignment and arithmetic operators.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @Andriamanitra , thanks for the great feedback! I've pushed a new commit that addresses all your points:

Rule Overlap: Moved the base identifier rule to the top, so the specific type and constant rules below it can correctly overwrite it.

Built-in Types: Removed Nil from the built-in types list (kept it under constants).

Operators: Moved operators to statement so they highlight correctly, and added the missing arithmetic, assignment, and Gleam-specific float operators.

Numbers: Implemented the robust number regexes from the Python syntax file to handle binary, octal, hex, and scientific notation floats.

Attributes: Added a preproc rule (@[a-zA-Z0-9_]+) to highlight attributes like @external and @deprecated.

- comment:
start: "//"
end: "$"
- string:
start: "\""
end: "\""
skip: "\\\\."
- special: "\\b[0-9]+\\.?[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.

Numbers should be constant.number. Gleam also supports a pretty wide range of number literals 1 that this regex doesn't cover. The formats seem to be similar to eg. Python so we can probably just copy them from the Python syntax:

# numbers
- constant.number: "\\b[0-9](_?[0-9])*(\\.([0-9](_?[0-9])*)?)?(e[0-9](_?[0-9])*)?\\b" # decimal
- constant.number: "\\b0b(_?[01])+\\b" # bin
- constant.number: "\\b0o(_?[0-7])+\\b" # oct
- constant.number: "\\b0x(_?[0-9a-fA-F])+\\b" # hex

Footnotes

  1. https://tour.gleam.run/everything/#basics-number-formats

- type: "\\b[A-Z][a-zA-Z0-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.

This overlaps with the definitions for identifier and constant above so those will get colored as type. To fix it you can put this rule before them (later rules are applied on top of earlier ones). It would also make sense to me to change this rule to be identifier, and use type for the built-in types (Int, Float, etc.) that are currently identifier.