erl_tokenize

erl_tokenize Documentation Build Status License: MIT

Erlang source code tokenizer written in Rust.

Documentation

Examples

Tokenizes the Erlang code io:format("Hello").:

```rust use erl_tokenize::{Tokenizer, TokenKind};

let src = r#"io:format("Hello")."#; let tokenizer = Tokenizer::new(src); let tokens = tokenizer.collect::, _>>().unwrap();

assert_eq!(tokens.iter().map(|t| t.kind()).collect::>(), [TokenKind::Atom, TokenKind::Symbol, TokenKind::Atom, TokenKind::Symbol, TokenKind::String, TokenKind::Symbol, TokenKind::Symbol]);

assert_eq!(tokens.iter().map(|t| t.text()).collect::>(), ["io", ":", "format", "(", r#""Hello""#, ")", "."]); ```

Executes the example tokenize command:

```bash $ cargo run --example tokenize -- /dev/stdin <

-export([bar/0]).

bar() -> qux. EOS

[line:1] Symbol(SymbolToken { value: Hyphen, text: "-" }) [line:1] Atom(AtomToken { value: "module", text: "module" }) [line:1] Symbol(SymbolToken { value: OpenParen, text: "(" }) [line:1] Atom(AtomToken { value: "foo", text: "foo" }) [line:1] Symbol(SymbolToken { value: CloseParen, text: ")" }) [line:1] Symbol(SymbolToken { value: Dot, text: "." }) [line:1] Whitespace(WhitespaceToken { value: Newline, text: "\n" }) [line:2] Whitespace(WhitespaceToken { value: Newline, text: "\n" }) [line:3] Symbol(SymbolToken { value: Hyphen, text: "-" }) [line:3] Atom(AtomToken { value: "export", text: "export" }) [line:3] Symbol(SymbolToken { value: OpenParen, text: "(" }) [line:3] Symbol(SymbolToken { value: OpenSquare, text: "[" }) [line:3] Atom(AtomToken { value: "bar", text: "bar" }) [line:3] Symbol(SymbolToken { value: Slash, text: "/" }) [line:3] Integer(IntegerToken { value: BigUint { data: [] }, text: "0" }) [line:3] Symbol(SymbolToken { value: CloseSquare, text: "]" }) [line:3] Symbol(SymbolToken { value: CloseParen, text: ")" }) [line:3] Symbol(SymbolToken { value: Dot, text: "." }) [line:3] Whitespace(WhitespaceToken { value: Newline, text: "\n" }) [line:4] Whitespace(WhitespaceToken { value: Newline, text: "\n" }) [line:5] Atom(AtomToken { value: "bar", text: "bar" }) [line:5] Symbol(SymbolToken { value: OpenParen, text: "(" }) [line:5] Symbol(SymbolToken { value: CloseParen, text: ")" }) [line:5] Whitespace(WhitespaceToken { value: Space, text: " " }) [line:5] Symbol(SymbolToken { value: RightAllow, text: "->" }) [line:5] Whitespace(WhitespaceToken { value: Space, text: " " }) [line:5] Atom(AtomToken { value: "qux", text: "qux" }) [line:5] Symbol(SymbolToken { value: Dot, text: "." }) [line:5] Whitespace(WhitespaceToken { value: Newline, text: "\n" }) ```

References