From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA26187; Wed, 25 Feb 2004 20:23:14 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA23063 for ; Wed, 25 Feb 2004 20:23:12 +0100 (MET) Received: from localhost (adsl-64-162-212-212.dsl.snfc21.pacbell.net [64.162.212.212]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i1PJNAae013369 for ; Wed, 25 Feb 2004 20:23:11 +0100 Received: by localhost (Postfix, from userid 1000) id D83F66A4CDE; Wed, 25 Feb 2004 11:23:09 -0800 (PST) Date: Wed, 25 Feb 2004 11:23:09 -0800 From: Kenneth Knowles To: caml-list@inria.fr Subject: Re: [Caml-list] start conditions in ocamllex Message-ID: <20040225192309.GA22138@tallman.kefka.frap.net> References: <20040225180744.GA23865@ccs.neu.edu> <20040225190056.GE27866@speakeasy.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040225190056.GE27866@speakeasy.org> User-Agent: Mutt/1.5.5.1i X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; knowles:99 caml-list:01 passing:01 entrypoint:01 entrypoint:01 token:01 token:01 syntax:02 match:02 thread:02 external:03 lexbuf:03 lexbuf:03 let:04 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > Has anyone thought of implementing start conditions for ocamllex? > Can't you get the same effect with multiple entrypoints? Though this syntax > is probably cleaner. > I disagree; I think different entry points are cleaner. In some recent release they added the ability to pass your own parameter to the rules, and so I maintain state by passing a reference to the state. I don't think the below code is thread safe, but it could easily be made so by keeping the state ref external to the entire lexer: { type state_t = StartCondition1 | StartCondition2 } rule entrypoint1 state_ref = parse 'a' { state_ref := StartCondition2; A_TOKEN } and entrypoint2 state_ref = parse 'a' { state_ref := StartCondition1; B_TOKEN } { let next_token start_start = let state_ref = ref start_state in (fun lexbuf -> match !state_ref with | StartCondition1 -> entrypoint1 state_ref lexbuf | StartCondition2 -> entrypoint2 state_ref lexbuf } ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners