caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joel Reymont <joelr1@gmail.com>
To: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>,
	caml-list List <caml-list@inria.fr>
Subject: Re: Re : [Caml-list] Re: camlp4 stream parser syntax
Date: Sun, 8 Mar 2009 11:07:02 +0000	[thread overview]
Message-ID: <61F9655B-4190-4639-8753-5982FCE553C3@gmail.com> (raw)
In-Reply-To: <35E3A172-40D9-4FA8-9C1D-1D7C114ED2D0@gmail.com>


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




  reply	other threads:[~2009-03-08 11:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-07 22:38 Joel Reymont
2009-03-07 22:52 ` Joel Reymont
2009-03-07 23:21   ` Re : [Caml-list] " Matthieu Wipliez
2009-03-07 23:42     ` Joel Reymont
2009-03-08  0:40     ` Joel Reymont
2009-03-08  1:08       ` Re : " Matthieu Wipliez
2009-03-08  8:25         ` Joel Reymont
2009-03-08  9:37           ` Daniel de Rauglaudre
2009-03-08  9:51             ` Joel Reymont
2009-03-08 10:27               ` Daniel de Rauglaudre
2009-03-08 10:35                 ` Joel Reymont
2009-03-08 11:07                   ` Joel Reymont [this message]
2009-03-08 11:28                     ` Daniel de Rauglaudre
2009-03-08 11:45           ` Re : Re : " Matthieu Wipliez
2009-03-08 11:52             ` Joel Reymont
2009-03-08 13:33               ` Re : " Matthieu Wipliez
2009-03-08 13:59                 ` Joel Reymont
2009-03-08 14:09                   ` Re : " Matthieu Wipliez
2009-03-08 14:30                     ` Joel Reymont
2009-03-08 15:07                       ` Re : " Matthieu Wipliez
2009-03-08 15:24                         ` Joel Reymont
2009-03-08 15:32                           ` Re : " Matthieu Wipliez
2009-03-08 15:39                             ` Joel Reymont
2009-03-08 15:46                             ` Joel Reymont
2009-03-08 15:55                               ` Re : " Matthieu Wipliez
2009-03-08 16:58                                 ` Joel Reymont
2009-03-08 17:04                                   ` Re : " Matthieu Wipliez
2009-03-08 17:15                                     ` Joel Reymont
2009-03-08  9:34         ` Joel Reymont
2009-03-07 23:52 ` [Caml-list] " Jon Harrop
2009-03-07 23:53   ` Joel Reymont
2009-03-08  0:12     ` Jon Harrop
2009-03-08  0:20       ` Re : " Matthieu Wipliez
2009-03-08  0:29         ` Jon Harrop
2009-03-08  0:30         ` Re : " Joel Reymont
2009-03-08  0:37           ` Re : " Matthieu Wipliez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61F9655B-4190-4639-8753-5982FCE553C3@gmail.com \
    --to=joelr1@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).