add gleam

# Conflicts:
#	CHANGELOG.md
#	README.md
pull/205/head
Jacob Rothstein 2022-03-29 19:45:09 +07:00
parent 04fc2af501
commit 9945270f4b
No known key found for this signature in database
GPG Key ID: C38BA18C6CFE15A5
9 changed files with 135 additions and 0 deletions

@ -1,5 +1,9 @@
## 0.26 (unreleased)
### Parsing
Added Gleam support
## 0.25 (released 31st March 2022)
### Display

@ -189,6 +189,11 @@ fn main() {
src_dir: "vendor/tree-sitter-typescript-src/typescript/src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-gleam",
src_dir: "vendor/tree-sitter-gleam-src",
extra_files: vec![],
},
];
// Only rerun if relevant files in the vendor/ directory change.

@ -124,6 +124,9 @@ c2d6920b57a543172aef2adfb7aa2df5 -
sample_files/text_before.txt sample_files/text_after.txt
d5bc09cc5298b5216e5989a31238be0b -
sample_files/todomvc_before.gleam sample_files/todomvc_after.gleam
5f57fcf8406d38e26a8fbb1552cc7b63 -
sample_files/typing_before.ml sample_files/typing_after.ml
22eec08aa24c88b330061de913dfce7d -

@ -0,0 +1,52 @@
import todomvc/web/routes
import todomvc/log
import gleam/int
import gleam/string
import gleam/result
import gleam/erlang/os
import gleam/http/elli
import gleam/option
import gleam/pgo
pub fn main() {
log.configure_backend()
let port = load_port()
let application_secret = load_application_secret()
let db = start_database_connection_pool()
let web = routes.stack(application_secret, db)
let log_string =
string.concat(["Listening on localhost:", int.to_string(port), " ✨"])
log.info(log_string)
assert Ok(_) = elli.become(web, on_port: port)
}
pub fn start_database_connection_pool() -> pgo.Connection {
let config =
os.get_env("DATABASE_URL")
|> result.then(pgo.url_config)
|> result.lazy_unwrap(fn() {
pgo.Config(
..pgo.default_config(),
host: "0.0.0.0",
database: "gleam_todomvc_dev",
user: "postgres",
password: option.Some("postgres"),
)
})
pgo.connect(pgo.Config(..config, pool_size: 15))
}
fn load_application_secret() -> String {
os.get_env("APPLICATION_SECRET")
|> result.unwrap("27434b28994f498182d459335258fb6e")
}
fn load_port() -> Int {
os.get_env("PORT")
|> result.then(int.parse)
|> result.unwrap(8080)
}

@ -0,0 +1,51 @@
import todomvc/web/routes
import todomvc/log
import gleam/int
import gleam/string
import gleam/result
import gleam/erlang/os
import gleam/http/elli
import gleam/option
import gleam/pgo
pub fn main() {
log.configure_backend()
let port = load_port()
let application_secret = load_application_secret()
let db = start_database_connection_pool()
let web = routes.stack(application_secret, db)
string.concat(["Listening on localhost:", int.to_string(port), " ✨"])
|> log.info
assert Ok(_) = elli.become(web, on_port: port)
}
pub fn start_database_connection_pool() -> pgo.Connection {
let config =
os.get_env("DATABASE_URL")
|> result.then(pgo.url_config)
|> result.lazy_unwrap(fn() {
pgo.Config(
..pgo.default_config(),
host: "localhost",
database: "gleam_todomvc_dev",
user: "postgres",
password: option.Some("postgres"),
)
})
pgo.connect(pgo.Config(..config, pool_size: 15))
}
fn load_application_secret() -> String {
os.get_env("APPLICATION_SECRET")
|> result.unwrap("27434b28994f498182d459335258fb6e")
}
fn load_port() -> Int {
os.get_env("PORT")
|> result.then(int.parse)
|> result.unwrap(3000)
}

@ -28,6 +28,7 @@ pub enum Language {
Dart,
Elixir,
EmacsLisp,
Gleam,
Go,
Haskell,
JanetSimple,
@ -95,6 +96,7 @@ fn from_emacs_mode_header(src: &str) -> Option<Language> {
"c++" => Some(CPlusPlus),
"elixir" => Some(Elixir),
"emacs-lisp" => Some(EmacsLisp),
"gleam" => Some(Gleam),
"go" => Some(Go),
"haskell" => Some(Haskell),
"janet" => Some(JanetSimple),
@ -190,6 +192,7 @@ fn from_extension(extension: &OsStr, src: &str) -> Option<Language> {
"dart" => Some(Dart),
"el" => Some(EmacsLisp),
"ex" | "exs" => Some(Elixir),
"gleam" => Some(Gleam),
"go" => Some(Go),
"hs" => Some(Haskell),
"janet" | "jdn" => Some(JanetSimple),

@ -53,6 +53,7 @@ extern "C" {
fn tree_sitter_dart() -> ts::Language;
fn tree_sitter_elisp() -> ts::Language;
fn tree_sitter_elixir() -> ts::Language;
fn tree_sitter_gleam() -> ts::Language;
fn tree_sitter_go() -> ts::Language;
fn tree_sitter_haskell() -> ts::Language;
fn tree_sitter_janet_simple() -> ts::Language;
@ -240,6 +241,20 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
.unwrap(),
}
}
Gleam => {
let language = unsafe { tree_sitter_gleam() };
TreeSitterConfig {
name: "Gleam",
language,
atom_nodes: ["string"].into(),
delimiter_tokens: vec![("(", ")"), ("[", "]"), ("{", "}")],
highlight_query: ts::Query::new(
language,
include_str!("../vendor/highlights/gleam.scm"),
)
.unwrap(),
}
}
Go => {
let language = unsafe { tree_sitter_go() };
TreeSitterConfig {

@ -0,0 +1 @@
../tree-sitter-gleam/queries/highlights.scm

@ -0,0 +1 @@
tree-sitter-gleam/src