···11-# pearl
11+# Pearl
22+33+An Erlang lexer and syntax highlighter for Gleam!
2435[](https://hex.pm/packages/pearl)
46[](https://hexdocs.pm/pearl/)
5788+Pearl is a lexer and syntax highlighter for Erlang, written in Gleam.
99+The `pearl` module, based on [`glexer`](https://hexdocs.mp/glexer) and
1010+[`just`](https://hexdocs.mp/just), exposes a
1111+standard lexer API, allowing you to convert Erlang source code into tokens.
1212+The `pearl/highlight` module allows you to highlight Erlang code using ansi
1313+colours, html or a custom format. Heavily inspired by [`contour`](https://hexdocs.pm/contour).
1414+615```sh
716gleam add pearl@1
817```
1818+919```gleam
1020import pearl
2121+import pearl/highlight
11221212-pub fn main() -> Nil {
1313- // TODO: An example of the project in use
2323+pub fn main() {
2424+ let code = "console.log('Hello, world!');"
2525+2626+ let lexer = pearl.new(code)
2727+ // Lex syntax tokens for parsing or other uses
2828+ let #(tokens, errors) = pearl.tokenise(lexer)
2929+ let assert [] = errors
3030+ parse_erlang(tokens)
3131+3232+ // Highlight with ansi codes to print in the terminal
3333+ let highlighted = highlight.ansi(code)
3434+ io.println(highlighted)
3535+3636+ // Render to html to show in the browser
3737+ let html = highlight.html(code)
3838+ io.println("<pre><code>" <> html <> "</code></pre>")
3939+4040+ // Convert to "highlighting tokens" to highlight in some other way
4141+ let highlight_tokens = highlight.tokens(code)
4242+ highlight_tokens_some_other_way(highlight_tokens)
1443}
1544```
16451746Further documentation can be found at <https://hexdocs.pm/pearl>.
18471919-## Development
4848+### Feature completeness
20492121-```sh
2222-gleam run # Run the project
2323-gleam test # Run the tests
2424-```
5050+As far as I can tell, `pearl` can lex all valid Erlang programs. However, I
5151+couldn't find a technical specification for Erlang syntax so what I've implemented
5252+is based on the Erlang documentation and other Erlang parsers. If there is
5353+something missing, please open an issue and I'll implement it as soon as possible.
+6-10
gleam.toml
···11name = "pearl"
22version = "1.0.0"
3344-# Fill out these fields if you intend to generate HTML documentation or publish
55-# your project to the Hex package manager.
66-#
77-# description = ""
88-# licences = ["Apache-2.0"]
99-# repository = { type = "github", user = "", repo = "" }
1010-# links = [{ title = "Website", href = "" }]
1111-#
1212-# For a full reference of all the available options, you can have a look at
1313-# https://gleam.run/writing-gleam/gleam-toml/.
44+description = "An Erlang lexer and syntax highlighter for Gleam!"
55+licences = ["Apache-2.0"]
66+repository = { type = "github", user = "GearsDatapacks", repo = "pearl" }
77+links = [
88+ { title = "Sponsor", href = "https://github.com/sponsors/GearsDatapacks" },
99+]
14101511[dependencies]
1612gleam_stdlib = ">= 0.44.0 and < 2.0.0"