stedolan / malfunction

Malfunctional Programming
Other
340 stars 19 forks source link

"module path required" #3

Closed olleharstedt closed 8 years ago

olleharstedt commented 8 years ago

I keep getting the error "module path required" after trying to hard-code the hello world-example in sexp format:

let dum = (Lexing.dummy_pos, Lexing.dummy_pos)

let test_code =
  (dum, List ([
    (dum, Atom "module");
    (dum, List [
      (dum, Atom "_");
      (dum, List [
          (dum, Atom "apply");
          (dum, List [
              (dum, Atom "global");
              (dum, Atom "$Pervasives");
              (dum, Atom "$print_string")
          ]);
          (dum, String "Hello, world!\n");
      ])
    ]);
    (dum, List [
      (dum, Atom "export");
    ])
  ]))

Then doing

let e = Malfunction_parser.parse_mod test_code in

after I've added parse_mod to the mli, I get the error. Any tips? How is module path supposed to look like?

stedolan commented 8 years ago

The error is with Atom "$Pervasives", which should be Var "Pervasives". The lexer (src/malfunction_sexp.mll) distinguishes between "atoms" (without $) and "variables" (with $).

If you're generating terms programmatically, it's probably easier to build a Malfunction.t directly instead of making sexps.

olleharstedt commented 8 years ago

Thanks, that work. Will checkout Malfunction.t.