From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 38F2ABC0A for ; Fri, 6 Apr 2007 22:14:21 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.239]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l36KEJHe029206 for ; Fri, 6 Apr 2007 22:14:20 +0200 Received: by wr-out-0506.google.com with SMTP id l58so650464wrl for ; Fri, 06 Apr 2007 13:14:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=VzTuOGlXuJCxVnVHqwdfVL8YS0xfjCtTK9AIvXabG4jo8tfsYFcwghu4EugM/8uU+wsktbsRwhEWUnS7azBNoupJZSHJOSr+mnBy4Oeb9ljqfJ4WOr/OSSqoHso8zDzpBLupKA4h5croIXn65lVQ2CKgQ6xuXw5llztR9P2Vyyc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Ps7yb8jlhR0upVNWv6MQlnBHrRgFs6w+eGjqiEtogbIicwkDygyRLeuauxILDZyG0Jkz57Pk/Y8k+7STntKaKkaT00QelciCsl9opFnArcXxJ7JsYVukW3AEyMqgD8HslBCl8FFmNS9RtOaWGRF3Bf8gsncZ63j8OsnPHvm1Vpc= Received: by 10.114.158.1 with SMTP id g1mr1359797wae.1175890458785; Fri, 06 Apr 2007 13:14:18 -0700 (PDT) Received: by 10.114.72.17 with HTTP; Fri, 6 Apr 2007 13:14:18 -0700 (PDT) Message-ID: <700d600f0704061314q2fd177bdnc918e6a1d811423b@mail.gmail.com> Date: Fri, 6 Apr 2007 23:14:18 +0300 From: "Janne Hellsten" To: "David Allsopp" Subject: Re: [Caml-list] Matching start of input in lexer created with ocamllex Cc: caml-list@yquem.inria.fr In-Reply-To: <011c01c7781e$e74a80c0$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070405205804.90509BC76@yquem.inria.fr> <011c01c7781e$e74a80c0$6a7ba8c0@treble> X-j-chkmail-Score: MSGID : 4616AA1B.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 4616AA1B.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lexer:01 ocamllex:01 lexer:01 ocamllex:01 simulate:01 bool:01 lexers:01 reuse:01 lexers:01 wrote:01 preprocessor:01 caml-list:01 parameter:02 match:02 slightly:03 On 4/6/07, David Allsopp wrote: > > I'd like to match the beginning of input (or beginning of line) in my > > lexer. Is there an easy way to do that? > Ocamllex doesn't have a notion for beginning of line. Three possible > solutions: > > 1. You can simulate it with a bool ref parameter to your lexer that gets set > to true by each rule to indicate that you're no longer at the beginning of a > line - the "!for" rule than raises Failure if it matches when this ref is > true. Slightly tedious for code maintenance... > 2. You use two lexers - one with the "!for" rule and one without and call > one lexer from the other (not very nice, because ocamllex doesn't support > code reuse between lexers so you'll be duplicating a lot of code). > 3. Pre-process the input to ocamllex to include a special character that > cannot appear in your text and place that at the beginning of the line (e.g. > one of the control characters in 0..31). Thanks, my program was already running its input through a preprocessor and I thus chose to use solution #3. I had already considered solution #2 but came to the same conclusion: it leads to code duplication. Janne