-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gleam syntax highlighting (#959)
Resolves #958
- Loading branch information
Showing
3 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<lexer> | ||
<config> | ||
<name>Gleam</name> | ||
<alias>gleam></alias> | ||
<filename>*.gleam</filename> | ||
<mime_type>text/x-gleam</mime_type> | ||
</config> | ||
<rules> | ||
<state name="root"> | ||
<rule pattern="\s+"> | ||
<token type="TextWhitespace"/> | ||
</rule> | ||
<rule pattern="///(.*?)\n"> | ||
<token type="LiteralStringDoc"/> | ||
</rule> | ||
<rule pattern="//(.*?)\n"> | ||
<token type="CommentSingle"/> | ||
</rule> | ||
<rule pattern="(as|assert|case|opaque|panic|pub|todo)\b"> | ||
<token type="Keyword"/> | ||
</rule> | ||
<rule pattern="(import|use)\b"> | ||
<token type="KeywordNamespace"/> | ||
</rule> | ||
<rule pattern="(auto|const|delegate|derive|echo|else|if|implement|macro|test)\b"> | ||
<token type="KeywordReserved"/> | ||
</rule> | ||
<rule pattern="(let)\b"> | ||
<token type="KeywordDeclaration"/> | ||
</rule> | ||
<rule pattern="(fn)\b"> | ||
<token type="Keyword"/> | ||
</rule> | ||
<rule pattern="(type)\b"> | ||
<token type="Keyword"/> | ||
<push state="typename"/> | ||
</rule> | ||
<rule pattern="(True|False)\b"> | ||
<token type="KeywordConstant"/> | ||
</rule> | ||
<rule pattern="0[bB][01](_?[01])*"> | ||
<token type="LiteralNumberBin"/> | ||
</rule> | ||
<rule pattern="0[oO][0-7](_?[0-7])*"> | ||
<token type="LiteralNumberOct"/> | ||
</rule> | ||
<rule pattern="0[xX][\da-fA-F](_?[\dA-Fa-f])*"> | ||
<token type="LiteralNumberHex"/> | ||
</rule> | ||
<rule pattern="\d(_?\d)*\.\d(_?\d)*([eE][-+]?\d(_?\d)*)?"> | ||
<token type="LiteralNumberFloat"/> | ||
</rule> | ||
<rule pattern="\d(_?\d)*"> | ||
<token type="LiteralNumberInteger"/> | ||
</rule> | ||
<rule pattern="""> | ||
<token type="LiteralString"/> | ||
<push state="string"/> | ||
</rule> | ||
<rule pattern="@([a-z_]\w*[!?]?)"> | ||
<token type="NameAttribute"/> | ||
</rule> | ||
<rule pattern="[{}()\[\],]|[#(]|\.\.|<>|<<|>>"> | ||
<token type="Punctuation"/> | ||
</rule> | ||
<rule pattern="[+\-*/%!=<>&|.]|<-"> | ||
<token type="Operator"/> | ||
</rule> | ||
<rule pattern=":|->"> | ||
<token type="Operator"/> | ||
<push state="typename"/> | ||
</rule> | ||
<rule pattern="([a-z_][A-Za-z0-9_]*)(\()"> | ||
<bygroups> | ||
<token type="NameFunction"/> | ||
<token type="Punctuation"/> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="([A-Z][A-Za-z0-9_]*)(\()"> | ||
<bygroups> | ||
<token type="NameClass"/> | ||
<token type="Punctuation"/> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="([a-z_]\w*[!?]?)"> | ||
<token type="Name"/> | ||
</rule> | ||
</state> | ||
<state name="typename"> | ||
<rule pattern="\s+"> | ||
<token type="TextWhitespace"/> | ||
</rule> | ||
<rule pattern="[A-Z][A-Za-z0-9_]*"> | ||
<token type="NameClass"/> | ||
<pop depth="1"/> | ||
</rule> | ||
<rule> | ||
<pop depth="1"/> | ||
</rule> | ||
</state> | ||
<state name="string"> | ||
<rule pattern="""> | ||
<token type="LiteralString"/> | ||
<pop depth="1"/> | ||
</rule> | ||
<rule pattern="\\["\\fnrt]|\\u\{[\da-fA-F]{1,6}\}"> | ||
<token type="LiteralStringEscape"/> | ||
</rule> | ||
<rule pattern="[^\\"]+"> | ||
<token type="LiteralString"/> | ||
</rule> | ||
<rule pattern="\\"> | ||
<token type="LiteralString"/> | ||
</rule> | ||
</state> | ||
</rules> | ||
</lexer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import gleam/io | ||
|
||
@external(erlang, "lists", "reverse") | ||
pub fn reverse_list(items: List(e)) -> List(e) { | ||
tail_recursive_reverse(items, []) | ||
} | ||
|
||
/// Tail recursion! | ||
fn tail_recursive_reverse(items: List(e), reversed: List(e)) -> List(e) { | ||
case items { | ||
[] -> reversed | ||
[first, ..rest] -> tail_recursive_reverse(rest, [first, ..reversed]) | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let _thing = <<"Hello, Joe!":utf8>> | ||
io.debug(reverse_list([1, 2, 3, 4, 5])) | ||
io.debug(reverse_list(["a", "b", "c", "d", "e"])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
[ | ||
{"type":"KeywordNamespace","value":"import"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Name","value":"gleam"}, | ||
{"type":"Operator","value":"/"}, | ||
{"type":"Name","value":"io"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"NameAttribute","value":"@external"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"erlang"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"lists\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"reverse\""}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Keyword","value":"pub"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Keyword","value":"fn"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameFunction","value":"reverse_list"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"items"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"List"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"e"}, | ||
{"type":"Punctuation","value":"))"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"List"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"e"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameFunction","value":"tail_recursive_reverse"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"items"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"[])"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"LiteralStringDoc","value":"/// Tail recursion!\n"}, | ||
{"type":"Keyword","value":"fn"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameFunction","value":"tail_recursive_reverse"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"items"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"List"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"e"}, | ||
{"type":"Punctuation","value":"),"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Name","value":"reversed"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"List"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"e"}, | ||
{"type":"Punctuation","value":"))"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"List"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"e"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Keyword","value":"case"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Name","value":"items"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"[]"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Name","value":"reversed"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"Name","value":"first"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":".."}, | ||
{"type":"Name","value":"rest"}, | ||
{"type":"Punctuation","value":"]"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameFunction","value":"tail_recursive_reverse"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"Name","value":"rest"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"Name","value":"first"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":".."}, | ||
{"type":"Name","value":"reversed"}, | ||
{"type":"Punctuation","value":"])"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"Keyword","value":"pub"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Keyword","value":"fn"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameFunction","value":"main"}, | ||
{"type":"Punctuation","value":"()"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n\t"}, | ||
{"type":"KeywordDeclaration","value":"let"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Name","value":"_thing"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"\u003c\u003c"}, | ||
{"type":"LiteralString","value":"\"Hello, Joe!\""}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Name","value":"utf8"}, | ||
{"type":"Punctuation","value":"\u003e\u003e"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Name","value":"io"}, | ||
{"type":"Operator","value":"."}, | ||
{"type":"NameFunction","value":"debug"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameFunction","value":"reverse_list"}, | ||
{"type":"Punctuation","value":"(["}, | ||
{"type":"LiteralNumberInteger","value":"1"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralNumberInteger","value":"2"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralNumberInteger","value":"3"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralNumberInteger","value":"4"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralNumberInteger","value":"5"}, | ||
{"type":"Punctuation","value":"]))"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Name","value":"io"}, | ||
{"type":"Operator","value":"."}, | ||
{"type":"NameFunction","value":"debug"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameFunction","value":"reverse_list"}, | ||
{"type":"Punctuation","value":"(["}, | ||
{"type":"LiteralString","value":"\"a\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"b\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"c\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"d\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"e\""}, | ||
{"type":"Punctuation","value":"]))"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n"} | ||
] |