Select lexer based on dune vs jbuild
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
e7e662e0bd
commit
7d33cb2275
|
@ -1349,7 +1349,7 @@ module Stanzas = struct
|
||||||
|
|
||||||
exception Include_loop of Path.t * (Loc.t * Path.t) list
|
exception Include_loop of Path.t * (Loc.t * Path.t) list
|
||||||
|
|
||||||
let rec parse stanza_parser ~current_file ~include_stack sexps =
|
let rec parse stanza_parser ~lexer ~current_file ~include_stack sexps =
|
||||||
List.concat_map sexps ~f:(Sexp.Of_sexp.parse stanza_parser Univ_map.empty)
|
List.concat_map sexps ~f:(Sexp.Of_sexp.parse stanza_parser Univ_map.empty)
|
||||||
|> List.concat_map ~f:(function
|
|> List.concat_map ~f:(function
|
||||||
| Include (loc, fn) ->
|
| Include (loc, fn) ->
|
||||||
|
@ -1361,20 +1361,22 @@ module Stanzas = struct
|
||||||
(Path.to_string_maybe_quoted current_file);
|
(Path.to_string_maybe_quoted current_file);
|
||||||
if List.exists include_stack ~f:(fun (_, f) -> f = current_file) then
|
if List.exists include_stack ~f:(fun (_, f) -> f = current_file) then
|
||||||
raise (Include_loop (current_file, include_stack));
|
raise (Include_loop (current_file, include_stack));
|
||||||
let sexps = Io.Sexp.load current_file ~mode:Many in
|
let sexps = Io.Sexp.load ~lexer current_file ~mode:Many in
|
||||||
parse stanza_parser sexps ~current_file ~include_stack
|
parse stanza_parser sexps ~lexer ~current_file ~include_stack
|
||||||
| stanza -> [stanza])
|
| stanza -> [stanza])
|
||||||
|
|
||||||
let parse ~file ~kind (project : Dune_project.t) sexps =
|
let parse ~file ~kind (project : Dune_project.t) sexps =
|
||||||
let stanza_parser =
|
let (stanza_parser, lexer) =
|
||||||
Dune_project.set project
|
let (parser, lexer) =
|
||||||
(match (kind : File_tree.Dune_file.Kind.t) with
|
match (kind : File_tree.Dune_file.Kind.t) with
|
||||||
| Jbuild -> jbuild_parser
|
| Jbuild -> (jbuild_parser, Usexp.Lexer.jbuild_token)
|
||||||
| Dune -> project.stanza_parser)
|
| Dune -> (project.stanza_parser, Usexp.Lexer.token)
|
||||||
|
in
|
||||||
|
(Dune_project.set project parser, lexer)
|
||||||
in
|
in
|
||||||
let stanzas =
|
let stanzas =
|
||||||
try
|
try
|
||||||
parse stanza_parser sexps ~include_stack:[] ~current_file:file
|
parse stanza_parser sexps ~lexer ~include_stack:[] ~current_file:file
|
||||||
with
|
with
|
||||||
| Include_loop (_, []) -> assert false
|
| Include_loop (_, []) -> assert false
|
||||||
| Include_loop (file, last :: rest) ->
|
| Include_loop (file, last :: rest) ->
|
||||||
|
|
Loading…
Reference in New Issue