picty / parsifal

Parsifal : an OCaml-based parsing engine
Other
61 stars 8 forks source link

Allow direct access to fields in dump functions #12

Open pictyeye opened 10 years ago

pictyeye commented 10 years ago

In struct dump functions, the fields are not easily available as dump arguments. Today, a structure defined as follow is invalid

struct s {
  s_type : uint8;
  s_content : other_struct [s_type];
}

Indeed, in the generated parse function, the expression

let s_content = parse_other_struct s_type input

correctly refers to the first field that has just been parsed.

However, the generated dump function contains the expression

dump_other_struct s_type buf s.s_content

which should be

dump_other_struct s.s_type buf s.s_content

To allow direct and intuitive access to fields while dumping, it is proposed to prepend the dump calls in parse_struct with local definitions :

let s_type = s.s_type
and s_content = s.s_content in