diff --git a/lexers/embedded/gleam.xml b/lexers/embedded/gleam.xml new file mode 100644 index 000000000..c706e9620 --- /dev/null +++ b/lexers/embedded/gleam.xml @@ -0,0 +1,117 @@ + + + Gleam + gleam> + *.gleam + text/x-gleam + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/testdata/gleam.actual b/lexers/testdata/gleam.actual new file mode 100644 index 000000000..cdcf1d384 --- /dev/null +++ b/lexers/testdata/gleam.actual @@ -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"])) +} diff --git a/lexers/testdata/gleam.expected b/lexers/testdata/gleam.expected new file mode 100644 index 000000000..30776e3f8 --- /dev/null +++ b/lexers/testdata/gleam.expected @@ -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"} +]