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
_______________________________________________
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