Add function to parse version header from sexp files
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
d7796156fd
commit
e706421893
|
@ -6,5 +6,9 @@ type first_line =
|
||||||
; version : Loc.t * string
|
; version : Loc.t * string
|
||||||
}
|
}
|
||||||
|
|
||||||
(** Parse the first line of a dune-project file. *)
|
(** Parse the first line of a versioned file. *)
|
||||||
val first_line : Lexing.lexbuf -> first_line
|
val first_line : Lexing.lexbuf -> first_line
|
||||||
|
|
||||||
|
(** Parse the first line of a versioned file but do not fail if it
|
||||||
|
doesn't start with [(lang ...)]. *)
|
||||||
|
val maybe_first_line : Lexing.lexbuf -> first_line option
|
||||||
|
|
|
@ -23,18 +23,16 @@ rule is_script = parse
|
||||||
| "(* -*- tuareg -*- *)" { true }
|
| "(* -*- tuareg -*- *)" { true }
|
||||||
| "" { false }
|
| "" { false }
|
||||||
|
|
||||||
and first_line = parse
|
and maybe_first_line = parse
|
||||||
| '(' blank* "lang"
|
| '(' blank* "lang"
|
||||||
{ let start = Lexing.lexeme_start_p lexbuf in
|
{ let start = Lexing.lexeme_start_p lexbuf in
|
||||||
let lang = atom start lexbuf in
|
let lang = atom start lexbuf in
|
||||||
let version = atom start lexbuf in
|
let version = atom start lexbuf in
|
||||||
first_line_end start lexbuf;
|
first_line_end start lexbuf;
|
||||||
{ lang; version }
|
Some { lang; version }
|
||||||
}
|
}
|
||||||
| ""
|
| ""
|
||||||
{ let start = Lexing.lexeme_start_p lexbuf in
|
{ None
|
||||||
to_eol lexbuf;
|
|
||||||
invalid_lang_line start lexbuf
|
|
||||||
}
|
}
|
||||||
|
|
||||||
and atom start = parse
|
and atom start = parse
|
||||||
|
@ -62,3 +60,13 @@ and to_eol = parse
|
||||||
| [^'\r' '\n']*
|
| [^'\r' '\n']*
|
||||||
{ ()
|
{ ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let first_line lb =
|
||||||
|
match maybe_first_line lb with
|
||||||
|
| Some x -> x
|
||||||
|
| None ->
|
||||||
|
let start = Lexing.lexeme_start_p lb in
|
||||||
|
to_eol lb;
|
||||||
|
invalid_lang_line start lb
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue