src/Pure/ML-Systems/ml_positions.ML
author wenzelm
Sat, 23 May 2015 17:19:37 +0200
changeset 60299 5ae2a2e74c93
parent 56437 b14bd153a753
permissions -rw-r--r--
clarified NEWS: document_files are officially required since Isabelle2014, but the absence was tolerated as legacy feature;

(*  Title:      Pure/ML-Systems/ml_positions.ML
    Author:     Makarius

Approximate ML antiquotation @{here} for Isabelle/Pure bootstrap.
*)

fun ml_positions start_line name txt =
  let
    fun positions line (#"@" :: #"{" :: #"h" :: #"e" :: #"r" :: #"e" :: #"}" :: cs) res =
          let val s = "(Position.line_file_only " ^ Int.toString line ^ " \"" ^ name ^ "\")"
          in positions line cs (s :: res) end
      | positions line (c :: cs) res =
          positions (if c = #"\n" then line + 1 else line) cs (str c :: res)
      | positions _ [] res = rev res;
  in String.concat (positions start_line (String.explode txt) []) end;