Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Genlex (question and problem)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeremy Fincher <fincher.8@o...>
Subject: [Caml-list] Genlex (question and problem)
I've just started using the Genlex module for some simple configuration file parsing, and I've run into a problem.

First, however, is the question: What's to happen to Genlex once camlp4 is integrated into the standard compiler distribution?  Will it be deprecated, will it require me to preprocess my files with camlp4; how will I have to change my Genlex-using source when I upgrade to 3.03?

As far as the probem goes, I can't do much better than include the source that's giving me the type error I can't figure out, so here goes:

----------
let record_lexer = make_lexer ["{"; "}"; "="; ";"] (* this is the lexer I use *)
type channel_user_stats =
    {
      msgs : int;
      chars : int;
      words : int;
      actions : int;
      kicks : int;
      modes : int;
      topics : int;
      joins : int;
    }

let default_channel_user_stats =
  {
    msgs = 0;
    chars = 0;
    words = 0;
    actions = 0;
    kicks = 0;
    modes = 0;
    topics = 0;
    joins = 0;
  }

type channel_user =
    {
      seen : float;
      flags : string;
      karma : int;
      stats : channel_user_stats;
    }

let default_channel_user =
  {
    seen = 0.;
    flags = "";
    karma = 0;
    stats = default_channel_user_stats;
  }

let parse_channel_user =
  let parse_stats =
    let rec parse_inside stats = parser
      | [< 'Ident "msgs"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with msgs = i } rest
      | [< 'Ident "chars"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with chars = i } rest
      | [< 'Ident "words"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with words = i } rest
      | [< 'Ident "actions"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with actions = i } rest
      | [< 'Ident "kicks"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with kicks = i } rest
      | [< 'Ident "modes"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with modes = i } rest
      | [< 'Ident "topics"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with topics = i } rest
      | [< 'Ident "joins"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	  parse_inside { stats with joins = i } rest
      | [< >] -> stats
    in
      parser
	| [< 'Kwd "{"; stats = parse_inside default_channel_user_stats;
	     'Kwd "}" >] -> stats
  in
  let rec parse_inside cu = parser
    | [< 'Ident "seen"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	parse_inside { cu with seen = (float_of_int i) } rest
    | [< 'Ident "flags"; 'Kwd "="; 'String flags; 'Kwd ";"; rest >] ->
	parse_inside { cu with flags = flags } rest
    | [< 'Ident "stats"; 'Kwd "="; stats = parse_stats; Kwd ";"; rest >] ->
	parse_inside { cu with stats = stats } rest
    | [< 'Ident "karma"; 'Kwd "="; 'Int i; 'Kwd ";"; rest >] ->
	parse_inside { cu with karma = i } rest
    | [< >] -> cu
  in
    parser
      | [< 'Kwd "{"; cu = parse_inside default_channel_user; 'Kwd "}" >] -> cu
----------

I get "This pattern matches values of type Genlex.token option but is here used to match values of type Genlex.token Stream.t option", which I *cannot* figure out.

Thanks,
Jeremy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr