2007-02-07 00:59:16 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 07:47:00 -07:00
|
|
|
(* *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* ocamlbuild *)
|
|
|
|
(* *)
|
|
|
|
(* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-03-03 08:54:58 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
(* Original author: Nicolas Pouillard *)
|
|
|
|
{
|
2013-09-15 04:36:56 -07:00
|
|
|
exception Error of (string * Loc.location)
|
2012-12-31 20:53:51 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
let error source lexbuf fmt =
|
|
|
|
Printf.ksprintf (fun s ->
|
|
|
|
raise (Error (s, Loc.of_lexbuf source lexbuf))
|
|
|
|
) fmt
|
2012-12-31 20:53:51 -08:00
|
|
|
|
2007-11-21 13:03:14 -08:00
|
|
|
open Glob_ast
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
type conf_values =
|
2013-09-15 04:36:50 -07:00
|
|
|
{ plus_tags : (string * Loc.location) list;
|
|
|
|
minus_tags : (string * Loc.location) list }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
type conf = (Glob.globber * conf_values) list
|
|
|
|
|
2010-01-22 06:36:57 -08:00
|
|
|
let empty = { plus_tags = []; minus_tags = [] }
|
2013-09-15 04:36:50 -07:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
let locate source lexbuf txt =
|
|
|
|
(txt, Loc.of_lexbuf source lexbuf)
|
|
|
|
|
|
|
|
let sublex lexer s = lexer (Lexing.from_string s)
|
2007-02-07 00:59:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
let newline = ('\n' | '\r' | "\r\n")
|
|
|
|
let space = [' ' '\t' '\012']
|
2008-07-25 07:24:29 -07:00
|
|
|
let space_or_esc_nl = (space | '\\' newline)
|
2014-08-22 06:45:02 -07:00
|
|
|
let sp = space_or_esc_nl
|
2007-02-07 00:59:16 -08:00
|
|
|
let blank = newline | space
|
|
|
|
let not_blank = [^' ' '\t' '\012' '\n' '\r']
|
|
|
|
let not_space_nor_comma = [^' ' '\t' '\012' ',']
|
|
|
|
let not_newline = [^ '\n' '\r' ]
|
|
|
|
let not_newline_nor_colon = [^ '\n' '\r' ':' ]
|
|
|
|
let normal_flag_value = [^ '(' ')' '\n' '\r']
|
|
|
|
let normal = [^ ':' ',' '(' ')' ''' ' ' '\n' '\r']
|
2010-01-22 06:36:57 -08:00
|
|
|
let tag = normal+ | ( normal+ ':' normal+ ) | normal+ '(' [^ ')' ]* ')'
|
2007-11-21 13:03:14 -08:00
|
|
|
let variable = [ 'a'-'z' 'A'-'Z' '_' '-' '0'-'9' ]*
|
|
|
|
let pattern = ([^ '(' ')' '\\' ] | '\\' [ '(' ')' ])*
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
rule ocamldep_output source = parse
|
|
|
|
| ([^ ':' '\n' '\r' ]+ as k) ':' { let x = (k, space_sep_strings_nl source lexbuf) in x :: ocamldep_output source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting colon followed by space-separated module name list" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and space_sep_strings_nl source = parse
|
|
|
|
| space* (not_blank+ as word) { word :: space_sep_strings_nl source lexbuf }
|
2012-12-31 20:53:51 -08:00
|
|
|
| space* newline { Lexing.new_line lexbuf; [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting space-separated strings terminated with newline" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and space_sep_strings source = parse
|
|
|
|
| space* (not_blank+ as word) { word :: space_sep_strings source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| space* newline? eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting space-separated strings" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and blank_sep_strings source = parse
|
|
|
|
| blank* '#' not_newline* newline { blank_sep_strings source lexbuf }
|
2007-11-26 05:28:18 -08:00
|
|
|
| blank* '#' not_newline* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| blank* (not_blank+ as word) { word :: blank_sep_strings source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| blank* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting blank-separated strings" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and comma_sep_strings source = parse
|
2007-02-07 00:59:16 -08:00
|
|
|
| space* (not_space_nor_comma+ as word) space* eof { [word] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| space* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting comma-separated strings (1)" }
|
|
|
|
and comma_sep_strings_aux source = parse
|
|
|
|
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| space* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting comma-separated strings (2)" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and comma_or_blank_sep_strings source = parse
|
2007-02-16 02:35:10 -08:00
|
|
|
| space* (not_space_nor_comma+ as word) space* eof { [word] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux source lexbuf }
|
2007-02-16 02:35:10 -08:00
|
|
|
| space* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting (comma|blank)-separated strings (1)" }
|
|
|
|
and comma_or_blank_sep_strings_aux source = parse
|
|
|
|
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux source lexbuf }
|
|
|
|
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux source lexbuf }
|
2007-02-16 02:35:10 -08:00
|
|
|
| space* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Expecting (comma|blank)-separated strings (2)" }
|
2007-02-16 02:35:10 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and parse_environment_path_w source = parse
|
|
|
|
| ([^ ';']* as word) { word :: parse_environment_path_aux_w source lexbuf }
|
|
|
|
| ';' ([^ ';']* as word) { "" :: word :: parse_environment_path_aux_w source lexbuf }
|
2012-03-29 05:36:37 -07:00
|
|
|
| eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
and parse_environment_path_aux_w source = parse
|
|
|
|
| ';' ([^ ';']* as word) { word :: parse_environment_path_aux_w source lexbuf }
|
2012-03-29 05:36:37 -07:00
|
|
|
| eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Impossible: expecting colon-separated strings" }
|
2012-03-29 05:36:37 -07:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and parse_environment_path source = parse
|
|
|
|
| ([^ ':']* as word) { word :: parse_environment_path_aux source lexbuf }
|
|
|
|
| ':' ([^ ':']* as word) { "" :: word :: parse_environment_path_aux source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
and parse_environment_path_aux source = parse
|
|
|
|
| ':' ([^ ':']* as word) { word :: parse_environment_path_aux source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Impossible: expecting colon-separated strings" }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and conf_lines dir source = parse
|
|
|
|
| space* '#' not_newline* newline { Lexing.new_line lexbuf; conf_lines dir source lexbuf }
|
2007-11-26 05:28:18 -08:00
|
|
|
| space* '#' not_newline* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| space* newline { Lexing.new_line lexbuf; conf_lines dir source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| space* eof { [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| space* (not_newline_nor_colon+ as k) (sp* as s1) ':' (sp* as s2)
|
2007-02-07 00:59:16 -08:00
|
|
|
{
|
2012-12-31 20:53:51 -08:00
|
|
|
let bexpr =
|
|
|
|
try Glob.parse ?dir k
|
2014-08-22 06:45:02 -07:00
|
|
|
with exn -> error source lexbuf "Invalid globbing pattern %S" k (Printexc.to_string exn)
|
2012-12-31 20:53:51 -08:00
|
|
|
in
|
2014-08-22 06:45:02 -07:00
|
|
|
sublex (count_lines lexbuf) s1; sublex (count_lines lexbuf) s2;
|
|
|
|
let v1 = conf_value empty source lexbuf in
|
|
|
|
let v2 = conf_values v1 source lexbuf in
|
|
|
|
let rest = conf_lines dir source lexbuf in (bexpr,v2) :: rest
|
2007-02-07 00:59:16 -08:00
|
|
|
}
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Invalid line syntax" }
|
|
|
|
|
|
|
|
and conf_value x source = parse
|
|
|
|
| '-' (tag as tag) { { (x) with minus_tags = locate source lexbuf tag :: x.minus_tags } }
|
|
|
|
| '+'? (tag as tag) { { (x) with plus_tags = locate source lexbuf tag :: x.plus_tags } }
|
|
|
|
| (_ | eof) { error source lexbuf "Invalid tag modifier only '+ or '-' are allowed as prefix for tag" }
|
|
|
|
|
|
|
|
and conf_values x source = parse
|
|
|
|
| (sp* as s1) ',' (sp* as s2) {
|
|
|
|
sublex (count_lines lexbuf) s1; sublex (count_lines lexbuf) s2;
|
|
|
|
conf_values (conf_value x source lexbuf) source lexbuf
|
|
|
|
}
|
|
|
|
| newline { Lexing.new_line lexbuf; x }
|
|
|
|
| eof { x }
|
|
|
|
| _ { error source lexbuf "Only ',' separated tags are alllowed" }
|
|
|
|
|
|
|
|
and path_scheme patt_allowed source = parse
|
2007-02-07 00:59:16 -08:00
|
|
|
| ([^ '%' ]+ as prefix)
|
2014-08-22 06:45:02 -07:00
|
|
|
{ `Word prefix :: path_scheme patt_allowed source lexbuf }
|
2007-11-21 13:03:14 -08:00
|
|
|
| "%(" (variable as var) ')'
|
2014-08-22 06:45:02 -07:00
|
|
|
{ `Var (var, Bool.True) :: path_scheme patt_allowed source lexbuf }
|
2007-11-21 13:03:14 -08:00
|
|
|
| "%(" (variable as var) ':' (pattern as patt) ')'
|
|
|
|
{ if patt_allowed then
|
|
|
|
let patt = My_std.String.implode (unescape (Lexing.from_string patt)) in
|
2014-08-22 06:45:02 -07:00
|
|
|
`Var (var, Glob.parse patt) :: path_scheme patt_allowed source lexbuf
|
2012-12-31 20:53:51 -08:00
|
|
|
else
|
2014-08-22 06:45:02 -07:00
|
|
|
error source lexbuf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)" var patt }
|
2007-02-07 00:59:16 -08:00
|
|
|
| '%'
|
2014-08-22 06:45:02 -07:00
|
|
|
{ `Var ("", Bool.True) :: path_scheme patt_allowed source lexbuf }
|
2007-02-07 00:59:16 -08:00
|
|
|
| eof
|
|
|
|
{ [] }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Bad pathanme scheme" }
|
2007-11-21 13:03:14 -08:00
|
|
|
|
|
|
|
and unescape = parse
|
|
|
|
| '\\' (['(' ')'] as c) { c :: unescape lexbuf }
|
|
|
|
| _ as c { c :: unescape lexbuf }
|
|
|
|
| eof { [] }
|
2010-01-22 06:36:57 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and ocamlfind_query source = parse
|
2010-01-22 06:36:57 -08:00
|
|
|
| newline*
|
|
|
|
"package:" space* (not_newline* as n) newline+
|
|
|
|
"description:" space* (not_newline* as d) newline+
|
|
|
|
"version:" space* (not_newline* as v) newline+
|
|
|
|
"archive(s):" space* (not_newline* as a) newline+
|
|
|
|
"linkopts:" space* (not_newline* as lo) newline+
|
|
|
|
"location:" space* (not_newline* as l) newline+
|
|
|
|
{ n, d, v, a, lo, l }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Bad ocamlfind query" }
|
2010-01-22 06:36:57 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and trim_blanks source = parse
|
2010-01-22 06:36:57 -08:00
|
|
|
| blank* (not_blank* as word) blank* { word }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Bad input for trim_blanks" }
|
2010-01-22 06:36:57 -08:00
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
and tag_gen source = parse
|
2010-01-22 06:36:57 -08:00
|
|
|
| (normal+ as name) ('(' ([^')']* as param) ')')? { name, param }
|
2014-08-22 06:45:02 -07:00
|
|
|
| _ { error source lexbuf "Not a valid parametrized tag" }
|
|
|
|
|
|
|
|
and count_lines lb = parse
|
|
|
|
| space* { count_lines lb lexbuf }
|
|
|
|
| '\\' newline { Lexing.new_line lb; count_lines lb lexbuf }
|
|
|
|
| eof { () }
|