aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nix/nix.ml
blob: 39dc94c53490bb6ba3bf76c7b5987059aa1002ec (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
open Core
module Ast = Types
module Printer = Printer

exception ParseError of string

let parse ~filename (data : string) =
  let lexbuf = Lexer.set_filename filename (Lexing.from_string data)
  and q, s = (Stdlib.Queue.create (), ref []) in
  try Parser.main (Lexer.next_token q s) lexbuf with
  | Lexer.Error msg ->
      let msg' = String.rstrip msg in
      raise (ParseError (sprintf "Lexing error: %s" msg'))
  | Parser.Error ->
      let msg = sprintf "Parse error at %s" (Lexer.print_position lexbuf) in
      raise (ParseError msg)

let elaborate = Elaborator.process

exception ElaborateError = Elaborator.ElaborateError