1Lexing(3)                        OCaml library                       Lexing(3)
2
3
4

NAME

6       Lexing - The run-time library for lexers generated by ocamllex.
7

Module

9       Module   Lexing
10

Documentation

12       Module Lexing
13        : sig end
14
15
16       The run-time library for lexers generated by ocamllex .
17
18
19
20
21
22
23
24
25       === Positions ===
26
27       type position = {
28        pos_fname : string ;
29        pos_lnum : int ;
30        pos_bol : int ;
31        pos_cnum : int ;
32        }
33
34
35       A value of type position describes a point in a source file.  pos_fname
36       is the file name; pos_lnum is the line number; pos_bol is the offset of
37       the  beginning  of the line (number of characters between the beginning
38       of the file and the beginning of the line); pos_cnum is the  offset  of
39       the  position  (number  of characters between the beginning of the file
40       and the position).
41
42
43
44
45       val dummy_pos : position
46
47       A value of type position , guaranteed to be different  from  any  valid
48       position.
49
50
51
52
53
54       === Lexer buffers ===
55
56       type lexbuf = {
57        refill_buff : lexbuf -> unit ;
58
59       mutable lex_buffer : string ;
60
61       mutable lex_buffer_len : int ;
62
63       mutable lex_abs_pos : int ;
64
65       mutable lex_start_pos : int ;
66
67       mutable lex_curr_pos : int ;
68
69       mutable lex_last_pos : int ;
70
71       mutable lex_last_action : int ;
72
73       mutable lex_eof_reached : bool ;
74
75       mutable lex_mem : int array ;
76
77       mutable lex_start_p : position ;
78
79       mutable lex_curr_p : position ;
80        }
81
82
83       The type of lexer buffers. A lexer buffer is the argument passed to the
84       scanning functions defined by the generated scanners.  The lexer buffer
85       holds  the  current state of the scanner, plus a function to refill the
86       buffer from the input.
87
88       Note that the lexing engine will only  manage  the  pos_cnum  field  of
89       lex_curr_p  by updating it with the number of characters read since the
90       start of the lexbuf .  For the other fields to be accurate,  they  must
91       be  initialised  before the first use of the lexbuf, and updated by the
92       lexer actions.
93
94
95
96
97       val from_channel : Pervasives.in_channel -> lexbuf
98
99       Create a lexer buffer on the given input channel.   Lexing.from_channel
100       inchan returns a lexer buffer which reads from the input channel inchan
101       , at the current reading position.
102
103
104
105
106       val from_string : string -> lexbuf
107
108       Create a lexer buffer which reads from the given string. Reading starts
109       from  the  first  character in the string. An end-of-input condition is
110       generated when the end of the string is reached.
111
112
113
114
115       val from_function : (string -> int -> int) -> lexbuf
116
117       Create a lexer buffer with the given function as  its  reading  method.
118       When  the  scanner  needs more characters, it will call the given func‐
119       tion, giving it a character string s and a  character  count  n  .  The
120       function  should  put n characters or less in s , starting at character
121       number 0, and return the number of characters provided. A return  value
122       of 0 means end of input.
123
124
125
126
127
128       === Functions for lexer semantic actions ===
129
130
131
132       ===  The following functions can be called from the semantic actions of
133       lexer definitions (the ML code enclosed in  braces  that  computes  the
134       value  returned by lexing functions). They give access to the character
135       string matched by the regular expression associated with  the  semantic
136       action.  These functions must be applied to the argument lexbuf, which,
137       in the code generated by ocamllex, is bound to the lexer buffer  passed
138       to the parsing function. ===
139
140
141       val lexeme : lexbuf -> string
142
143
144       Lexing.lexeme  lexbuf returns the string matched by the regular expres‐
145       sion.
146
147
148
149
150       val lexeme_char : lexbuf -> int -> char
151
152
153       Lexing.lexeme_char lexbuf i returns character number i in  the  matched
154       string.
155
156
157
158
159       val lexeme_start : lexbuf -> int
160
161
162       Lexing.lexeme_start  lexbuf  returns  the offset in the input stream of
163       the first character of the matched string.  The first character of  the
164       stream has offset 0.
165
166
167
168
169       val lexeme_end : lexbuf -> int
170
171
172       Lexing.lexeme_end  lexbuf returns the offset in the input stream of the
173       character following the last character of the matched string. The first
174       character of the stream has offset 0.
175
176
177
178
179       val lexeme_start_p : lexbuf -> position
180
181       Like  lexeme_start  , but return a complete position instead of an off‐
182       set.
183
184
185
186
187       val lexeme_end_p : lexbuf -> position
188
189       Like lexeme_end , but return a complete position instead of an offset.
190
191
192
193
194
195       === Miscellaneous functions ===
196
197
198       val flush_input : lexbuf -> unit
199
200       Discard the contents of the buffer and reset the current position to 0.
201       The next use of the lexbuf will trigger a refill.
202
203
204
205
206
207
208OCamldoc                          2007-05-24                         Lexing(3)
Impressum