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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 344F1BBAF for ; Tue, 16 Sep 2008 11:38:31 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4AANUbz0hRZ90xmmdsb2JhbACJa4kcAQEBAQEIBQgHEQOlL4Fl X-IronPort-AV: E=Sophos;i="4.32,407,1217800800"; d="scan'208";a="29228262" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Sep 2008 11:38:30 +0200 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20080916093821.GYFP10791.mtaout03-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com>; Tue, 16 Sep 2008 10:38:21 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout04-winn.ispmail.ntl.com with ESMTP id <20080916093821.GSNL18637.aamtaout04-winn.ispmail.ntl.com@romulus.metastack.com>; Tue, 16 Sep 2008 10:38:21 +0100 Received: from countertenor ([172.16.0.6]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id m8G9cEXW004750 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Tue, 16 Sep 2008 10:38:18 +0100 From: "David Allsopp" To: "'Dario Teixeira'" , References: <698632.75695.qm@web54606.mail.re2.yahoo.com> Subject: RE: [Caml-list] Parameterised lexer Date: Tue, 16 Sep 2008 10:38:12 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <629B7CBAE27E4325B489E51B90F20E48@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AckWo4E19h/dmMUUSYS1V+Cj2jrH8gAZs3+w In-Reply-To: <698632.75695.qm@web54606.mail.re2.yahoo.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 X-Scanned-By: MIMEDefang 2.64 on 81.102.132.74 X-Cloudmark-Analysis: v=1.0 c=1 a=ZOzjf2MOAAAA:8 a=CjxXgO3LAAAA:8 a=F_2qNL6vLI2YCI9dGCQA:9 a=XNGik8XiwhJQuXVjj_YA:7 a=7p5H00AIGOGlj51VsavbuImwQy0A:4 a=9OHTkwyHC8cA:10 X-Spam: no; 0.00; lexer:01 ocamllex:01 ocamllex:01 regexp:01 'x':01 lexer:01 lexing:01 lexeme:01 lexbuf:01 failwith:01 lexing:01 regexp:01 'a'-'z':01 'a'-'z':01 'x':01 Definitely not possible (directly) with ocamllex - what you're suggesting would involve recompiling the automaton on each call which isn't how ocamllex works. Don't know about ulex. But: do you know enough about the kind of expressions that param could be to use one regexp that would cover them all (e.g. ['x'|'y'|'z'] for the example below)? You could then have a lexer action of the form: rule token param = parse reg-exp-for-params {if Str.string_match param (Lexing.lexeme lexbuf) 0 then () (* Code *) else failwith "lexing: empty token"} | rest-of-the-lexer David -----Original Message----- From: caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inria.fr] On Behalf Of Dario Teixeira Sent: 14 September 2008 21:53 To: caml-list@yquem.inria.fr Subject: [Caml-list] Parameterised lexer Hi, Is it possible to write a ocamllex/ulex scanner where a regexp is a parameter to the lexer function? I'm looking for something like the (invalid) ulex code below demonstrates ("param" is the parameter): let regexp alpha = ['a'-'z' 'A'-'Z'] let regexp whitespace = [' ' '\t' '\n'] let regexp param1 = 'x' let regexp param2 = 'y' let regexp param3 = 'z' let rec token param = lexer | param -> Printf.print "*"; token param lexbuf | alpha+ -> Printf.printf "%s" (Ulexing.utf8_lexeme lexbuf); token param lexbuf | whitespace+ -> Printf.printf " "; token param lexbuf | eof -> Printf.printf "EOF\n" let main () = let lexbuf = Ulexing.from_utf8_channel stdin in token param1 lexbuf let _ = Printexc.print main () Thanks in advance for your help! Kind regards, Dario Teixeira _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs