src/Pure/RAW/ml_positions.ML
author wenzelm
Thu, 03 Mar 2016 11:12:02 +0100
changeset 62501 98fa1f9a292f
parent 61925 ab52f183f020
permissions -rw-r--r--
discontinued polyml-5.3.0;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61925
ab52f183f020 clarified directory structure;
wenzelm
parents: 56437
diff changeset
     1
(*  Title:      Pure/RAW/ml_positions.ML
56435
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     3
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     4
Approximate ML antiquotation @{here} for Isabelle/Pure bootstrap.
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     5
*)
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     6
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     7
fun ml_positions start_line name txt =
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     8
  let
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
     9
    fun positions line (#"@" :: #"{" :: #"h" :: #"e" :: #"r" :: #"e" :: #"}" :: cs) res =
56437
b14bd153a753 clarified position: no offset here;
wenzelm
parents: 56435
diff changeset
    10
          let val s = "(Position.line_file_only " ^ Int.toString line ^ " \"" ^ name ^ "\")"
56435
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    11
          in positions line cs (s :: res) end
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    12
      | positions line (c :: cs) res =
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    13
          positions (if c = #"\n" then line + 1 else line) cs (str c :: res)
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    14
      | positions _ [] res = rev res;
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    15
  in String.concat (positions start_line (String.explode txt) []) end;
28b34e8e4a80 approximate ML antiquotation @{here} for Isabelle/Pure bootstrap;
wenzelm
parents:
diff changeset
    16