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.8 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 57067BC0A for ; Tue, 17 Apr 2007 08:35:11 +0200 (CEST) Received: from mail.rsise.anu.edu.au (mail.rsise.anu.edu.au [150.203.208.4]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3H6Z4QB023559 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 17 Apr 2007 08:35:10 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 8D113541E3 for ; Tue, 17 Apr 2007 16:35:02 +1000 (EST) Received: from mail.rsise.anu.edu.au ([150.203.208.4]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08106-06 for ; Tue, 17 Apr 2007 16:35:02 +1000 (EST) Received: from pulp.rsise.anu.edu.au (pulp.rsise.anu.edu.au [150.203.208.49]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 73693540E0 for ; Tue, 17 Apr 2007 16:34:55 +1000 (EST) Received: by pulp.rsise.anu.edu.au (Postfix, from userid 1560) id 7F903A0BC9E; Tue, 17 Apr 2007 16:34:55 +1000 (EST) Date: Tue, 17 Apr 2007 16:34:55 +1000 From: Pietro Abate To: ocaml ml Subject: tricky camlp4 question. Message-ID: <20070417063455.GA29940@pulp.rsise.anu.edu.au> Mail-Followup-To: Pietro Abate , ocaml ml MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mail.rsise.anu.edu.au X-Miltered: at concorde with ID 46246A99.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 camlp:01 bounded:01 grammatical:01 polluting:01 parser:01 hendrik:01 tews:01 hashtbl:01 hashtbl:01 parser:01 strm:01 strm:01 lident:01 pcaml:01 Hi all, I wrote a small camlp4 extension that by using a specification that is at the beginning of the input file, extends itself and to parse the rest of the file. My problem is that by giving the user the file to extend the grammar with which the input file is parsed, I indirectly give him/her also the power to introduce new keywords. This is very annoying as if the user define a new keyword, say "a", then the variable "a" cannot be used anywhere in the file, except that as a keyword. This restriction makes sense most of the time, but it would be great if keywords were bounded within their grammatical scope, instead of been global. A simple trick to avoid polluting the grammar with out-of-scope keywords is not to use Gramext.Stoken (that is not to specify the keyword as a string in the EXTEND statement), but to generate an entry from a parser that matches exactly that keyword (from Hendrik Tews). Since I extend the grammar on the fly, I have a function that given the specification generates for me the extension. In this function, associated with a symbol s (given by the user), I generated an entry that look like this: Gramext.Snterm (Grammar.Entry.obj (Hashtbl.find symbol_table s)) where symbol_table of type (string, 'a Grammar.Entry.e) Hashtbl.t and 'a is the type of the resulting action that is not important here. Now to generate one entry for each user provided keyword and I use the function add_symbol_table that gets a string and generates an entry using the parser checksym. let checksym sym strm = let s = match Stream.peek strm with |Some("",s) when s = sym -> s |Some("LIDENT",s) |Some("UIDENT",s) when s = sym -> s |_ -> raise Stream.Failure in try Stream.junk strm; s with Stream.Failure -> raise Stream.Failure let add_symbol_table s = let e = Grammar.Entry.of_parser Pcaml.gram ("__entry"^s) (checksym s) in Hashtbl.add symbol_table s e This is all well and good. Everything type-checks correctly, but when I try to use any of these entries generated using Grammar.Entry.of_parser I get a sigsegv. I think the problem is with the function Grammar.Entry.obj but I don't understand why this is wrong... any suggestions ? p -- ++ Blog: http://blog.rsise.anu.edu.au/?q=pietro ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html