Guest User

Hack for trailing separator

a guest
Oct 21st, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.79 KB | None | 0 0
  1. (* [jmseparated_list(separator, X)] recognizes a possibly empty list of
  2.    [X]'s, separated with [separator]'s. It produces a value of type
  3.    ['a list] if [X] produces a value of type ['a]. The front element
  4.    of the list is the first element that was parsed. *)
  5.  
  6. %public %inline jmseparated_list(separator, X):
  7.   xs = loption(jmseparated_nonempty_list(separator, X))
  8.     { xs }
  9.  
  10. (* [separated_nonempty_list(separator, X)] recognizes a nonempty list
  11.    of [X]'s, separated with [separator]'s. It produces a value of type
  12.    ['a list] if [X] produces a value of type ['a]. The front element
  13.    of the list is the first element that was parsed. *)
  14.  
  15. %public jmseparated_nonempty_list(separator, X):
  16.   x = X
  17.     { [ x ] }
  18. | x = X; separator; xs = jmseparated_list(separator, X)
  19.     { x :: xs }
Add Comment
Please, Sign In to add comment