(* Title: HOL/SPARK/Tools/fdl_lexer.ML Author: Stefan Berghofer Copyright: secunet Security Networks AG
Lexical analyzer for fdl files.
*)
signature FDL_LEXER = sig type T type chars type banner type date type time datatype kind = Keyword | Ident | Long_Ident | Traceability | Number | Comment | EOF val tokenize: (chars -> 'a * chars) -> (chars -> T * chars) ->
Position.T -> string -> 'a * T list val position_of: T -> Position.T val pos_of: T -> string val is_eof: T -> bool val stopper: T Scan.stopper val kind_of: T -> kind val content_of: T -> string val unparse: T -> string val is_proper: T -> bool val is_digit: string -> bool val c_comment: chars -> T * chars val curly_comment: chars -> T * chars val percent_comment: chars -> T * chars val vcg_header: chars -> (banner * (date * time) option) * chars val siv_header: chars ->
(banner * (date * time) * (date * time) * (string * string)) * chars end;
fun keyword s = Scan.literal lexicon :|--
(fn xs => ifmap symbol xs = raw_explode s then Scan.succeed xs else Scan.fail);
fun is_digit x = "0" <= x andalso x <= "9"; fun is_alpha x = "a" <= x andalso x <= "z" orelse "A" <= x andalso x <= "Z"; val is_underscore = equal "_"; val is_tilde = equal "~"; val is_newline = equal "\n"; val is_tab = equal "\t"; val is_space = equal " "; val is_whitespace = is_space orf is_tab orf is_newline; val is_whitespace' = is_space orf is_tab;
val number = Scan.many1 (is_digit o symbol);
val identifier =
Scan.one (is_alpha o symbol) :::
Scan.many
((is_alpha orf is_digit orf is_underscore) o symbol) @@@
Scan.optional (Scan.one (is_tilde o symbol) >> single) [];
val long_identifier =
identifier @@@ Scan.repeats1 ($$$ "." @@@ identifier);
val whitespace = Scan.many (is_whitespace o symbol); val whitespace1 = Scan.many1 (is_whitespace o symbol); val whitespace' = Scan.many (is_whitespace' o symbol); val newline = Scan.one (is_newline o symbol);
fun beginning n cs = let val drop_blanks = drop_suffix is_whitespace; val all_cs = drop_blanks cs; val dots = if length all_cs > n then" ..."else""; in
(drop_blanks (take n all_cs)
|> map (fn c => if is_whitespace c then" "else c)
|> implode) ^ dots end;
fun !!! text scan = let fun get_pos [] = " (end-of-input)"
| get_pos ((_, pos) :: _) = Position.here pos;
fun err (syms, msg) = fn () =>
text ^ get_pos syms ^ " at " ^ beginning 10 (map symbol syms) ^
(case msg of NONE => "" | SOME m => "\n" ^ m ()); in Scan.!! err scan end;
val any_line' =
Scan.many (not o (Scan.is_stopper char_stopper orf (is_newline o symbol)));
val any_line = whitespace' |-- any_line' --|
newline >> (implode o map symbol);
fun gen_comment a b = $$$ a |-- !!! "unclosed comment"
(Scan.repeat (Scan.unless ($$$ b) any) --| $$$ b) >> make_token Comment;
val c_comment = gen_comment "/*""*/"; val curly_comment = gen_comment "{""}";
val percent_comment = $$$ "%" |-- any_line' >> make_token Comment;
fun repeatn 0 _ = Scan.succeed []
| repeatn n p = Scan.one p ::: repeatn (n-1) p;
(** header of *.vcg and *.siv files (see simplifier/load_provenance.pro) **)
type banner = string * string * string; type date = string * string * string; type time = string * string * string * stringoption;
val asterisks = Scan.repeat1 (Scan.one (equal "*" o symbol));
fun alphan n = repeatn n (is_alpha o symbol) >> (implode o map symbol); fun digitn n = repeatn n (is_digit o symbol) >> (implode o map symbol);
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.