[erlang-questions] [ANN] ETP - An Erlang Term Parser for Java

Dave Parfitt dparfitt@REDACTED
Mon Apr 29 22:59:10 CEST 2013

Hello -

I'd like to announce the release of ETP v0.3. ETP is a parser for Java
built with Antlr 4 that can parse a string representation of an Erlang
term. The parsed model can be manipulated in Java, and rendered back to a
string by calling toString().

The source can be found online at:

The Maven artifact is available from the Sonatype OSS repository.


Here's a simple example:

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

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

which 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"}

Cheers -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130429/ed0b57b3/attachment.htm>

More information about the erlang-questions mailing list