package csexp

  1. Overview
  2. Docs

Parsing stack

type t =
  1. | Empty
  2. | Open of t
  3. | Sexp of sexp * t
val to_list : t -> sexp list

Extract the list of full S-expressions contained in a stack.

For instance:

# to_list (Sexp (Atom "y", Sexp (Atom "x", Empty)));;
- : Stack.t list = [Atom "x"; Atom "y"]
  • raises Parse_error

    if the stack contains open parentheses that has not been closed.

val open_paren : t -> t

Add a left parenthesis.

val close_paren : t -> t

Add a right parenthesis. Raise Parse_error if the stack contains no opened parentheses.

For instance:

# close_paren (Sexp (Atom "y", Sexp (Atom "x", Open Empty)));;
- : Stack.t = Sexp (List [Atom "x"; Atom "y"], Empty)
  • raises Parse_error

    if the stack contains no open open parenthesis.

val add_atom : string -> t -> t

Insert an atom in the parsing stack:

# add_atom "foo" Empty;;
- : Stack.t = Sexp (Atom "foo", Empty)
val add_token : [ `other ] Lexer.token -> t -> t

Add a token as returned by the lexer.

  • raises Parse_error