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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="Lazy.html">
<link rel="next" href="List.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Arith_status" rel="Chapter" href="Arith_status.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Big_int" rel="Chapter" href="Big_int.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Dbm" rel="Chapter" href="Dbm.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Graphics" rel="Chapter" href="Graphics.html">
<link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Num" rel="Chapter" href="Num.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Pervasives" rel="Chapter" href="Pervasives.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Sort" rel="Chapter" href="Sort.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Tk" rel="Chapter" href="Tk.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Positions" rel="Section" href="#6_Positions">
<link title="Lexer buffers" rel="Section" href="#6_Lexerbuffers">
<link title="Functions for lexer semantic actions" rel="Section" href="#6_Functionsforlexersemanticactions">
<link title="Miscellaneous functions" rel="Section" href="#6_Miscellaneousfunctions">
<title>Lexing</title>
</head>
<body>
<div class="navbar"><a href="Lazy.html">Previous</a>
<a href="index.html">Up</a>
<a href="List.html">Next</a>
</div>
<center><h1>Module <a href="type_Lexing.html">Lexing</a></h1></center>
<br>
<pre><span class="keyword">module</span> Lexing: <code class="code"><span class="keyword">sig</span></code> <a href="Lexing.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>The run-time library for lexers generated by <code class="code">ocamllex</code>.<br>
<hr width="100%">
<br>
<a name="6_Positions"></a>
<h6>Positions</h6><br>
<br><code><span class="keyword">type</span> <a name="TYPEposition"></a><code class="type"></code>position = {</code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code>pos_fname : <code class="type">string</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code>pos_lnum : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code>pos_bol : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code>pos_cnum : <code class="type">int</code>;</code></td>
</tr></table>
}
<div class="info">
A value of type <code class="code">position</code> describes a point in a source file.
<code class="code">pos_fname</code> is the file name; <code class="code">pos_lnum</code> is the line number;
<code class="code">pos_bol</code> is the offset of the beginning of the line (number
of characters between the beginning of the file and the beginning
of the line); <code class="code">pos_cnum</code> is the offset of the position (number of
characters between the beginning of the file and the position).
<p>
See the documentation of type <code class="code">lexbuf</code> for information about
how the lexing engine will manage positions.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALdummy_pos"></a>dummy_pos : <code class="type"><a href="Lexing.html#TYPEposition">position</a></code></pre><div class="info">
A value of type <code class="code">position</code>, guaranteed to be different from any
valid position.<br>
</div>
<br>
<a name="6_Lexerbuffers"></a>
<h6>Lexer buffers</h6><br>
<br><code><span class="keyword">type</span> <a name="TYPElexbuf"></a><code class="type"></code>lexbuf = {</code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code>refill_buff : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_buffer : <code class="type">string</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_buffer_len : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_abs_pos : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_start_pos : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_curr_pos : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_last_pos : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_last_action : <code class="type">int</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_eof_reached : <code class="type">bool</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_mem : <code class="type">int array</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_start_p : <code class="type"><a href="Lexing.html#TYPEposition">position</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code> </code></td>
<td align="left" valign="top" >
<code><span class="keyword">mutable </span>lex_curr_p : <code class="type"><a href="Lexing.html#TYPEposition">position</a></code>;</code></td>
</tr></table>
}
<div class="info">
The type of lexer buffers. A lexer buffer is the argument passed
to the scanning functions defined by the generated scanners.
The lexer buffer holds the current state of the scanner, plus
a function to refill the buffer from the input.
<p>
Note that the lexing engine will only change the <code class="code">pos_cnum</code> field
of <code class="code">lex_curr_p</code> by updating it with the number of characters read
since the start of the <code class="code">lexbuf</code>. The other fields are copied
without change by the lexing engine. In order to keep them
accurate, they must be initialised before the first use of the
lexbuf, and updated by the relevant lexer actions (i.e. at each
end of line).<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_channel"></a>from_channel : <code class="type"><a href="Pervasives.html#TYPEin_channel">in_channel</a> -> <a href="Lexing.html#TYPElexbuf">lexbuf</a></code></pre><div class="info">
Create a lexer buffer on the given input channel.
<code class="code"><span class="constructor">Lexing</span>.from_channel inchan</code> returns a lexer buffer which reads
from the input channel <code class="code">inchan</code>, at the current reading position.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_string"></a>from_string : <code class="type">string -> <a href="Lexing.html#TYPElexbuf">lexbuf</a></code></pre><div class="info">
Create a lexer buffer which reads from
the given string. Reading starts from the first character in
the string. An end-of-input condition is generated when the
end of the string is reached.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_function"></a>from_function : <code class="type">(string -> int -> int) -> <a href="Lexing.html#TYPElexbuf">lexbuf</a></code></pre><div class="info">
Create a lexer buffer with the given function as its reading method.
When the scanner needs more characters, it will call the given
function, giving it a character string <code class="code">s</code> and a character
count <code class="code">n</code>. The function should put <code class="code">n</code> characters or less in <code class="code">s</code>,
starting at character number 0, and return the number of characters
provided. A return value of 0 means end of input.<br>
</div>
<br>
<a name="6_Functionsforlexersemanticactions"></a>
<h6>Functions for lexer semantic actions</h6><br>
<br>
The following functions can be called from the semantic actions
of lexer definitions (the ML code enclosed in braces that
computes the value returned by lexing functions). They give
access to the character string matched by the regular expression
associated with the semantic action. These functions must be
applied to the argument <code class="code">lexbuf</code>, which, in the code generated by
<code class="code">ocamllex</code>, is bound to the lexer buffer passed to the parsing
function.<br>
<pre><span class="keyword">val</span> <a name="VALlexeme"></a>lexeme : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> string</code></pre><div class="info">
<code class="code"><span class="constructor">Lexing</span>.lexeme lexbuf</code> returns the string matched by
the regular expression.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlexeme_char"></a>lexeme_char : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> int -> char</code></pre><div class="info">
<code class="code"><span class="constructor">Lexing</span>.lexeme_char lexbuf i</code> returns character number <code class="code">i</code> in
the matched string.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlexeme_start"></a>lexeme_start : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> int</code></pre><div class="info">
<code class="code"><span class="constructor">Lexing</span>.lexeme_start lexbuf</code> returns the offset in the
input stream of the first character of the matched string.
The first character of the stream has offset 0.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlexeme_end"></a>lexeme_end : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> int</code></pre><div class="info">
<code class="code"><span class="constructor">Lexing</span>.lexeme_end lexbuf</code> returns the offset in the input stream
of the character following the last character of the matched
string. The first character of the stream has offset 0.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlexeme_start_p"></a>lexeme_start_p : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> <a href="Lexing.html#TYPEposition">position</a></code></pre><div class="info">
Like <code class="code">lexeme_start</code>, but return a complete <code class="code">position</code> instead
of an offset.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlexeme_end_p"></a>lexeme_end_p : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> <a href="Lexing.html#TYPEposition">position</a></code></pre><div class="info">
Like <code class="code">lexeme_end</code>, but return a complete <code class="code">position</code> instead
of an offset.<br>
</div>
<br>
<a name="6_Miscellaneousfunctions"></a>
<h6>Miscellaneous functions</h6><br>
<pre><span class="keyword">val</span> <a name="VALflush_input"></a>flush_input : <code class="type"><a href="Lexing.html#TYPElexbuf">lexbuf</a> -> unit</code></pre><div class="info">
Discard the contents of the buffer and reset the current
position to 0. The next use of the lexbuf will trigger a
refill.<br>
</div>
</body></html>
|