Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] a few lexing questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-30 (12:32)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] a few lexing questions
Michal Moskal wrote:

> On Mon, Apr 28, 2003 at 02:13:48PM -0400, Alan Schmitt wrote:
>>A second question is about integration this code with other lexing code
>>or streams. An iCalendar file cannot have a line that is longer than 75
>>bytes, excluding line break. A line may be broken anywhere as long as
>>there is a space at the beginning of the next line, as in:
>>this is a very lo
>> ng line
>>represents "this is a very long line". As this break may occur anywhere
>>(even inside keywords), I assume when writing the lexer these kind of
>>lines have been already merged together. I know how to implement the
>>merging using a temp file, but I'm looking for a nicer solution (like
>>using a stream, or using one lexer to feed the current lexer). Any
>>suggestion ?
> Maybe Lexing.from_function ? 

Yes, I do this. In the lexer:

| "(" { fun state -> state#inbody; [LPAR (state#get_srcref lexbuf)] }

Notice each executable section is a function accepting
the state object. You can form a closure of a method
of a lexer state class and pass that to Lexing.from_function,
and you call the lexer function with an extra arguemnt like:

lex_my_stuff lexbuf state

In that way you can

(a) pre-process the input
(b) maintain state such as the original line number

John Max Skaller,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: