erl_pp

Crates.ioerl_pp
lib.rserl_pp
version0.2.0
sourcesrc
created_at2017-06-14 20:31:44.241141
updated_at2021-10-17 23:44:53.487427
descriptionErlang source code preprocessor
homepagehttps://github.com/sile/erl_pp
repositoryhttps://github.com/sile/erl_pp
max_upload_size
id18989
size83,674
Takeru Ohta (sile)

documentation

README

erl_pp

erl_pp Documentation Actions Status Coverage Status License: MIT

An Erlang source code preprocessor written in Rust.

Documentation

References

Examples

Preprocesses an Erlang source code snippet.

use erl_pp::Preprocessor;
use erl_tokenize::Lexer;

let src = r#"-define(FOO(A), {A, ?LINE}). io:format("Hello: ~p", [?FOO(bar)])."#;
let pp = Preprocessor::new(Lexer::new(src));
let tokens = pp.collect::<Result<Vec<_>, _>>().unwrap();

assert_eq!(tokens.iter().map(|t| t.text()).collect::<Vec<_>>(),
           ["io", ":", "format", "(", r#""Hello: ~p""#, ",",
            "[", "{", "bar", ",", "1", "}", "]", ")", "."]);

Executes the example pp command:

$ cargo run --example pp -- /dev/stdin <<EOS
-define(FOO, foo).
-define(BAR(A), {bar, A}).

-ifdef(FOO).

foo() ->
  ?FOO + ?BAR(baz).

-endif.
EOS

[Position { filepath: Some("stdin"), offset: 61, line: 6, column: 1 }] "foo"
[Position { filepath: Some("stdin"), offset: 64, line: 6, column: 4 }] "("
[Position { filepath: Some("stdin"), offset: 65, line: 6, column: 5 }] ")"
[Position { filepath: Some("stdin"), offset: 67, line: 6, column: 2 }] "->"
[Position { filepath: Some("stdin"), offset: 13, line: 1, column: 2 }] "foo"
[Position { filepath: Some("stdin"), offset: 77, line: 7, column: 2 }] "+"
[Position { filepath: Some("stdin"), offset: 35, line: 2, column: 2 }] "{"
[Position { filepath: Some("stdin"), offset: 36, line: 2, column: 3 }] "bar"
[Position { filepath: Some("stdin"), offset: 39, line: 2, column: 6 }] ","
[Position { filepath: Some("stdin"), offset: 84, line: 7, column: 7 }] "baz"
[Position { filepath: Some("stdin"), offset: 42, line: 2, column: 3 }] "}"
[Position { filepath: Some("stdin"), offset: 88, line: 7, column: 11 }] "."
TOKEN COUNT: 12
ELAPSED: 0.001244 seconds
Commit count: 54

cargo fmt