(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
{
open Lexing open Coqpp_parse
type mode =
| OCaml
| Extend
exception Lex_error of Coqpp_ast.loc * string
let loc lexbuf = {
Coqpp_ast.loc_start = lexeme_start_p lexbuf;
Coqpp_ast.loc_end = lexeme_end_p lexbuf;
}
let newline lexbuf = let pos = lexbuf.lex_curr_p in let pos = { pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum } in
lexbuf.lex_curr_p <- pos
let num_comments = ref 0 let num_braces = ref 0 let ocaml_start_pos = ref Lexing.dummy_pos
let mode () = if !num_braces = 0 then Extend else OCaml
let comment_buf = Buffer.create 512 let ocaml_buf = Buffer.create 512 let string_buf = Buffer.create 512
let lex_error lexbuf msg = raise (Lex_error (loc lexbuf, msg))
let lex_unexpected_eof lexbuf where =
lex_error lexbuf (Printf.sprintf "Unexpected end of file in %s" where)
let start_comment _ = let () = incr num_comments in
Buffer.add_string comment_buf "(*"
let end_comment lexbuf = let () = decr num_comments in let () = Buffer.add_string comment_buf "*)"in if !num_comments < 0 then lex_error lexbuf "Unexpected end of comment" elseif !num_comments = 0 then let s = Buffer.contents comment_buf in let () = Buffer.reset comment_buf in
Some (COMMENT s) else
None
let start_ocaml lexbuf = let () = match mode () with
| OCaml -> Buffer.add_string ocaml_buf "{"
| Extend -> ocaml_start_pos := lexeme_start_p lexbuf in
incr num_braces
let end_ocaml lexbuf = let () = decr num_braces in if !num_braces < 0 then lex_error lexbuf "Unexpected end of OCaml code" elseif !num_braces = 0 then let s = Buffer.contents ocaml_buf in let () = Buffer.reset ocaml_buf in let loc = Some {
Coqpp_ast.loc_start = !ocaml_start_pos;
Coqpp_ast.loc_end = lexeme_end_p lexbuf
} in
Some (CODE { Coqpp_ast.code = s; loc }) else let () = Buffer.add_string ocaml_buf "}"in
None
}
let letter = ['a'-'z''A'-'Z'] let letterlike = ['_''a'-'z''A'-'Z'] let alphanum = ['_''a'-'z''A'-'Z''0'-'9''\''] let ident = letterlike alphanum* let qualid = ident ('.' ident)* let space = [' ''\t''\r'] let number = [ '0'-'9' ]
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.