File: leftbin.doc

package info (click to toggle)
hol-light 20131026-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,264 kB
  • ctags: 4,620
  • sloc: ml: 400,325; cpp: 438; java: 279; lisp: 261; makefile: 256; sh: 190; yacc: 108; perl: 78; ansic: 57; sed: 39
file content (41 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
\DOC leftbin

\TYPE {leftbin : ('a -> 'b * 'c) -> ('c -> 'd * 'a) -> ('d -> 'b -> 'b -> 'b) -> string -> 'a -> 'b * 'c}

\SYNOPSIS
Parses iterated left-associated binary operator.

\DESCRIBE
If {p} is a parser for ``items'' of some kind, {s} is a parser for some 
``separator'', {c} is a `constructor' function taking an element as parsed by 
{s} and two other elements as parsed by {p} and giving a new such element, and 
{e} is an error message, then {leftbin p s c e} will parse an iterated sequence 
of items by {p} and separated by something parsed with {s}. It will repeatedly 
apply the constructor function {c} to compose these elements into one, 
associating to the left. For example, the input:
{
  <p1> <s1> <p2> <s2> <p3> <s3> <p4>
}
meaning successive segments {pi} that are parsed by {p} and {sj} that are
parsed by {s}, will result in 
{
  c (c s2 (c s1 p1 p2) p3) p4
}

\FAILURE
The call {leftbin p s c e} never fails, though the resulting parser may.

\COMMENTS
This is one of a suite of combinators for manipulating ``parsers''. A parser is
simply a function whose OCaml type is some instance of
{:('a)list -> 'b * ('a)list}. The function should take a list of objects of
type {:'a} (e.g. characters or tokens), parse as much of it as possible from
left to right, and return a pair consisting of the object derived from parsing
(e.g. a term or a special syntax tree) and the list of elements that were not
processed.

\SEEALSO
++, ||, >>, a, atleast, elistof, finished, fix, listof, many, nothing,
possibly, rightbin, some.

\ENDDOC