OCamllex cannot import Core package (Go to Python compiler)

130 views Asked by At

I am writing a Go to Python compiler with OCamllex and Menhir but my lexer is failing to import the Core package.

Here is my lex.mll file:

{
   (* Header *)

  open Core.Std
  open Lexing
  open Parser

  exception SyntaxError of string

  let next_line lexbuf =
    let pos = lexbuf.lex_curr_p in
    lexbuf.lex_curr_p <-
      { pos with pos_bol = lexbuf.lex_curr_pos;
             pos_lnum = pos.pos_lnum + 1
      }

  let syntaxError msg = raise (SyntaxError (msg ^ " on line " ^ (string_of_int next_line)))


   (* End Header *)
}

[ lexer rules ]

I have a make file, make.sh to put the lexer and parser together

#! /bin/bash
echo "==Creating compiler=="

echo "- OCamllex : lex.mll -> lex.ml"
ocamllex lex.mll

echo "- OCaml : lex.ml -> lex"
ocamlc lex.ml -o lex

# echo "- OCamlBuild -> main.ml"
# ocamlbuild -use-menhir main.native

But when I run ./make.sh I get this error:

==Creating compiler==
- OCamllex : lex.mll -> lex.ml
1030 states, 16995 transitions, table size 74160 bytes
- OCaml : lex.ml -> lex
File "lex.mll", line 4, characters 7-15:
Error: Unbound module Core

I am able to open Core in the ocaml interpreter, by editing my .ocamlinit file, but how to import Core in a script compiled by ocamlc?

1

There are 1 answers

0
ivg On BEST ANSWER

Remove everything from your script and just use

corebuild -use-menhir main.native

corebuild will infer all dependencies and compile them, and do all the stuff.