View on GitHub


Erlang Term Parser

Download this project as a .zip file Download this project as a tar.gz file

ETP: An Erlang Term Parser for Java.

Given a String of Erlang terms, ETP will parse the string into a tree of ETP Java objects. Calling toString() on an ETP object will render a tree as an Erlang term.


You'll need Maven to build etp.

mvn package

Also, ETP is available via the Sonatype OSS repository:



EPTTerm com.metadave.etp.ETP.parse(String s)

EPTTerm com.metadave.etp.ETP.parse(InputStream is)

An ETP term is made up of any of these classes:


Call toString() on a ETPTerm object will render a valid Erlang term to a String. Note - at the moment, ETP doesn't prevent you setting invalid values on an ETPTerm object. Validation coming soon.


Antlr 4 grammar here


// at the moment, whitespace and comments between terms aren't retained
ETPTuple tuple = (ETPTuple)ETP.parse("{mylist, [1,2,3,4], \n" +
                                      "my_string, \"Hello world\"}");
// All ETP objects subclass ETPTerm
// you can use "instanceof" to see what the result of the parse is

ETPAtom atom = (ETPAtom)tuple.getValue(0);
System.out.println("Atom = " + atom);

ETPList list = (ETPList)tuple.getValue(1);
// use getValue() to access the list of terms
for(ETPTerm v : list.getValue()) {
    System.out.println("  List item " + v);
ETPAtom my_string_atom = (ETPAtom)tuple.getValue(2);

ETPString s = (ETPString)tuple.getValue(3);
System.out.println(s.getValue()); // getValue() gets the "raw" value
System.out.println(s.toString()); // toString() gets the string representation

// you can set values on the ETP structure and call toString() to render
// a new Erlang term
list.getValue().add(new ETPLong(100));

yields the following output:

Atom = mylist
  List item 1
  List item 2
  List item 3
  List item 4
Hello world
"Hello world"
{new_atom_value,[1,2,3,4,100],my_string,"Hello world"}

Status & TODO


Fork this repo, create a branch with

git checkout -b your_branch_name

Submit a pull request when your code is ready for review.


© 2013 Dave Parfitt