Debian Codegraph @

lib/mllpt-lib/ml-lpt/doc/ml-lpt-lib.tex

raw
1 %!TEX root = manual.tex
2 %
3 \chapter{The {\tt ml-lpt-lib} library}
4 \label{ch:ml-lpt-lib}
5
6 To use the output of \ulex{} or \mlantlr{} in an SML program requires including the
7 \texttt{ml-opt-lib} library.
8 This library includes the \texttt{AntlrStreamPos} structure, which manages tracking
9 positions in the input stream, and the \texttt{AntlrRepair} structure, which defines
10 a representation of \mlantlr{}'s error-repair actions that can be used to generate
11 error messages.
12
13 \section{Usage}
14 For SML/NJ, you should include the following line in your CM file:
15 \begin{lstlisting}[language=CM]
16 $/ml-lpt-lib.cm
17 \end{lstlisting}%
18 The SML/NJ Compilation Manager also understands how to generate SML files from \ulex{} and
19 \mlantlr{} files.
20 For example, if you include
21 \begin{lstlisting}
22 foo.grm : ml-antlr
23 foo.lex : ml-ulex
24 \end{lstlisting}%
25 in the list of sources in a CM file, then CM will run the \ulex{} (reps.\ \mlantlr{})
26 to produce \texttt{foo.lex.sml} (resp.\ \texttt{foo.grm.sml}).
27
28 If you are using MLton SML compiler, then you will need to include the following line
29 in your MLB file:
30 \begin{lstlisting}
31 $(SML_LIB)/mllpt-lib/mllpt-lib.mlb
32 \end{lstlisting}%
33
34 \section{The {\tt AntlrStreamPos} structure}
35
36 \begin{lstlisting}
37 structure AntlrStreamPos : sig
38
39 type pos = int
40 type span = pos * pos
41 type sourceloc = { fileName : string option, lineNo : int, colNo : int }
42 type sourcemap
43
44 (* the result of moving forward an integer number of characters *)
45 val forward : pos * int -> pos
46
47 val mkSourcemap : unit -> sourcemap
48 val mkSourcemap' : string -> sourcemap
49
50 val same : sourcemap * sourcemap -> bool
51
52 (* log a new line occurence *)
53 val markNewLine : sourcemap -> pos -> unit
54 (* resychronize to a full source location *)
55 val resynch : sourcemap -> pos * sourceloc -> unit
56
57 val sourceLoc : sourcemap -> pos -> sourceloc
58 val fileName : sourcemap -> pos -> string option
59 val lineNo : sourcemap -> pos -> int
60 val colNo : sourcemap -> pos -> int
61 val toString : sourcemap -> pos -> string
62 val spanToString : sourcemap -> span -> string
63
64 end
65 \end{lstlisting}%
66
67
68 \section{The {\tt AntlrRepair} structure}
69
70 \begin{lstlisting}
71 structure AntlrRepair : sig
72
73 datatype 'tok repair_action
74 = Insert of 'tok list
75 | Delete of 'tok list
76 | Subst of {
77 old : 'tok list,
78 new : 'tok list
79 }
80 | FailureAt of 'tok
81
82 type 'a repair = AntlrStreamPos.pos * 'tok repair_action
83
84 val actionToString : ('tok -> string)
85 -> 'tok repair_action
86 -> string
87
88 val repairToString : ('tok -> string)
89 -> AntlrStreamPos.sourcemap
90 -> 'tok repair -> string
91
92 datatype add_or_delete = ADD | DEL
93
94 (* return a string representation of the repair action. This version
95 * uses the add_or_delete information to allow different token names
96 * for deletion (more specific) and addition (more general).
97 *)
98 val actionToString' : (add_or_delete -> 'tok -> string)
99 -> 'tok repair_action -> string
100 val repairToString' : (add_or_delete -> 'tok -> string)
101 -> AntlrStreamPos.sourcemap -> 'tok repair -> string
102
103 end
104 \end{lstlisting}%