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=2.7 required=5.0 tests=AWL,DNS_FROM_RFC_POST, 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 54514BBAF; Sun, 8 Mar 2009 12:07:06 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AroBAHdDs0lKfU4ak2dsb2JhbACUaj8BAQEBCQkKCREDrgCBB44+AQMBA4QCBoMT X-IronPort-AV: E=Sophos;i="4.38,324,1233529200"; d="scan'208";a="36245746" Received: from ey-out-2122.google.com ([74.125.78.26]) by mail4-smtp-sop.national.inria.fr with ESMTP; 08 Mar 2009 12:07:06 +0100 Received: by ey-out-2122.google.com with SMTP id 25so105800eya.33 for ; Sun, 08 Mar 2009 04:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=h48uQ3oErA45bTvoGeCXAolXYtU4WNlETrpuTqpDwus=; b=JBmGEBeNc7P0EKwqR0mcJuM9plHO5pt1c98lm5Y1iAJf5cQnMJg7Ldbmew49vIZrIE 50WSzYLVa6MGjDvCPT/IoOK9mPwgseQx7mqGrLXIxIVZ9+tu+L1UAipTX66HaG6IfTJu Zl9OZirhmjTHTPrQ+ilUL9KDtPrK8XHbs6cKE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=hTlAQfmlWLbidvU0UtAbgF9nJCs8ldMNfTSP+T88V2YzZ1MHb4Iv7LiaMRw5cdZekl WEjQKJ00CcOVQuN91/afzc9n0rwn4qpj7n5Kicwjb4cC4YmlM+FMw21IX/0r4nylfFSe FUq7WcQMWtcnJ41hewFuY1eiiWFHXfdQ53Yfc= Received: by 10.210.88.7 with SMTP id l7mr1549970ebb.7.1236510425516; Sun, 08 Mar 2009 04:07:05 -0700 (PDT) Received: from ?10.10.30.5? (94.Red-88-6-143.staticIP.rima-tde.net [88.6.143.94]) by mx.google.com with ESMTPS id 7sm5532507nfv.25.2009.03.08.04.07.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 08 Mar 2009 04:07:05 -0700 (PDT) Message-Id: <61F9655B-4190-4639-8753-5982FCE553C3@gmail.com> From: Joel Reymont To: Daniel de Rauglaudre , caml-list List In-Reply-To: <35E3A172-40D9-4FA8-9C1D-1D7C114ED2D0@gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Re : [Caml-list] Re: camlp4 stream parser syntax Date: Sun, 8 Mar 2009 11:07:02 +0000 References: <24D11586-4F15-4B6E-8FB7-58651317164D@gmail.com> <46331.52510.qm@web27007.mail.ukl.yahoo.com> <0B508092-FD71-4733-BC95-B6B87A6D3E6B@gmail.com> <154139.25342.qm@web27007.mail.ukl.yahoo.com> <46FCBABD-7E4A-4077-8227-3816FD6D635D@gmail.com> <20090308093756.GB5433@yquem.inria.fr> <046C7516-62FF-4F46-B2D9-CEA1045132CD@gmail.com> <20090308102724.GC5433@yquem.inria.fr> <35E3A172-40D9-4FA8-9C1D-1D7C114ED2D0@gmail.com> X-Mailer: Apple Mail (2.930.3) X-Spam: no; 0.00; camlp:01 parser:01 syntax:01 lexer:01 camlp:01 struct:01 struct:01 sig:01 kwd:01 bool:01 mutable:01 kwd:01 bool:01 ocaml:01 hash:01 On Mar 8, 2009, at 10:35 AM, Joel Reymont wrote: > The filter module nested in the token module seems like a good > candidate. What functions of the lexer or filter are accessed when a > string keyword (e.g. "delay") is found in the camlp4 grammar? The filter portion of the token module looks like this (more below) ... module Token = struct module Loc = Loc type t = token ... module Filter = struct type token_filter = (t, Loc.t) Camlp4.Sig.stream_filter type t = { is_kwd : string -> bool; mutable filter : token_filter } let mk is_kwd = { is_kwd = is_kwd; filter = fun s -> s } let keyword_conversion tok is_kwd = match tok with SYMBOL s | IDENT s when is_kwd s -> KEYWORD s | _ -> tok ... end end The relevant part here is the function is_kwd : (string -> bool) that's passed to Filter.mk. Within the bowels of OCaml a keyword hash table is set up and used to manage keywords, e.g gkeywords in gram below. The functions using and removing (below) can be used to add and remove keywords. module Structure = struct open Sig.Grammar module type S = sig module Loc : Sig.Loc module Token : Sig.Token with module Loc = Loc module Lexer : Sig.Lexer with module Loc = Loc and module Token = Token module Context : Context.S with module Token = Token module Action : Sig.Grammar.Action type gram = { gfilter : Token.Filter.t; gkeywords : (string, int ref) Hashtbl.t; glexer : Loc.t -> char Stream.t -> (Token.t * Loc.t) Stream.t; warning_verbose : bool ref; error_verbose : bool ref } type efun = Context.t -> (Token.t * Loc.t) Stream.t -> Action.t type token_pattern = ((Token.t -> bool) * string) type internal_entry = ... type production_rule = ((symbol list) * Action.t) ... val get_filter : gram -> Token.Filter.t val using : gram -> string -> unit val removing : gram -> string -> unit end Matthieu is using this bit to parse let parse_arg str = parse_with_msg Gram.parse arg (Loc.mk str) (Stream.of_string str) Should I just invoke Gram.using ... ? I feel that the solution is staring me in the face here but I still can't recognize it. Help!!! Thanks, Joel --- http://tinyco.de Mac, C++, OCaml