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

detect:
filename: "\\.moon$"

rules:
# Block comments like --[[ ... ]]
- comment:
start: "--\\[\\["
end: "\\]\\]"
rules: []

# Line comments like -- ...
- comment:
start: "--"
end: "$"
rules: []

# Long bracket strings like [[ ... ]] or [==[ ... ]==]
- constant.string:
start: "\\[=*\\["
end: "\\]=*\\]"
rules: []
Comment on lines +19 to +23

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This would work better as separate rules for [[ ... ]] and [==[ ... ]==]. I assume the main reason to use [==[ ... ]==] is to include ]] somewhere inside so you don't want that to end the string.


# Double-quoted strings (with #{} interpolation and escapes)
- constant.string:
start: "\""
end: "\""
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."
- default:
start: "#\\{"
end: "\\}"
rules: []
Comment on lines +32 to +35

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be better to simply match #\\{[^\\}]*\\} because handling of regions inside regions is currently pretty buggy in our highlighter.

Example of said bugs causing weird things to happen:
screenshot of a part of a comment getting highlighted when it's on the same line as a string interpolation


# Single-quoted strings (no interpolation, but escapes still work)
- constant.string:
start: "'"
end: "'"
skip: "\\\\."
rules:
- constant.specialChar: "\\\\."

# Numbers (int, float, hex, scientific notation)
- constant.number: "\\b(0x[0-9a-fA-F]+|[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?|\\.[0-9]+)\\b"

# Booleans, nil
- constant.bool: "\\b(true|false|nil)\\b"

# self, @ references
# (using "special" instead of "identifier.var" since most colorschemes
# define a distinct color for "special" but leave subgroups like
# "identifier.var" to fall back to plain "identifier")
- special: "@@?[A-Za-z_][A-Za-z0-9_]*"
- special: "\\bself\\b"

# Keywords, control flow
- statement: "\\b(if|then|else|elseif|unless|switch|when|for|while|until|do|in|and|or|not|return|break|continue|export|import|from|local|using|with)\\b"

# Class-related keywords
- statement: "\\b(class|extends|super|new)\\b"

# Function definition arrows
- statement: "(->|=>)"

# Table, class member access
- identifier: "\\.[A-Za-z_][A-Za-z0-9_]*"

# Function calls: name(...)
- identifier: "[A-Za-z_][A-Za-z0-9_]*\\("

# Table key shorthand, e.g. `key:` in table literals, includes the colon
- identifier: "\\b[A-Za-z_][A-Za-z0-9_]*:"

# Operators and punctuation
- symbol.operator: "(\\+|-|\\*|/|%|\\^|#|==|~=|<=|>=|<|>|=|:|\\\\|\\.\\.\\.?|::|!)"

# Braces, brackets, parens
- symbol.brackets: "[{}()\\[\\]]"