<html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <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="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="Lexer buffers" rel="Section" href="#6_Lexerbuffers"> <link title="Functions for lexer semantic actions" rel="Section" href="#6_Functionsforlexersemanticactions"> <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="type">sig end</code></pre><div class="info"> The run-time library for lexers generated by <code class="code">ocamllex</code>.<br> </div> <hr width="100%"> <br> <br> <a name="6_Lexerbuffers"></a> <table cellpadding=5 cellspacing=5 width="100%"> <tr class="title6"><td><div align=center> <span class="title6">Lexer buffers</span> </div> </td> </tr> </table> <br><br> <br><code><span class="keyword">type</span> <a name="TYPElexbuf"></a>lexbuf = {<br></code><table border="0" cellpadding="1"> <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></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.<br> </div> <br> <pre><span class="keyword">val</span> <a name="VALfrom_channel"></a>from_channel : <code class="type"><a href="Pervasives.html#TYPEin_channel">Pervasives.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> <br> <a name="6_Functionsforlexersemanticactions"></a> <table cellpadding=5 cellspacing=5 width="100%"> <tr class="title6"><td><div align=center> <span class="title6">Functions for lexer semantic actions</span> </div> </td> </tr> </table> <br><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><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 position in the input stream of the first character of the matched string. The first character of the stream has position 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 position in the input stream of the character following the last character of the matched string. The first character of the stream has position 0.<br> </div> </body></html>