/sexp-parse

S-expression parsing library (without base dependency)

Primary LanguageOCamlMIT LicenseMIT

Build Status

sexp-parse

S-expression parsing library without the base dependency.

Untyped s-expressions

Untyped s-expressions rely on the type definitions in the sexplib0 library.

Untyped.of_string
  {|((data "quoted data" 123 4.5)
     (data (!@# (4.5) "(more" "data)")))|}

will generate:

Ok
  Typed.[
    List [
      List [
        Atom "data";
        Atom {|"quoted data"|};
        Atom "123";
        Atom "4.5";
      ];
      List [
        Atom "data";
        List [
          Atom "!@#";
          List [ Atom "4.5" ];
          Atom {|"(more"|};
          Atom {|"data)"|};
        ]
      ]
    ]
  ]

Typed s-expressions

In typed s-expressions the atoms can be either of type string, int, float or symbol (unquoted string).

Typed.of_string
  {|((data "quoted data" 123 4.5)
     (data (!@# (4.5) "(more" "data)")))|}

will generate:

Ok
  Typed.[
    List [
      List [
        Atom (Symbol "data");
        Atom (String {|quoted data|});
        Atom (Int 123);
        Atom (Float 4.5);
      ];
      List [
        Atom (Symbol "data");
        List [
          Atom (Symbol "!@#");
          List [ Atom (Float 4.5) ];
          Atom (String "(more");
          Atom (String "data)");
        ]
      ]
    ]
  ]