added Lexicon.encode_position, Lexicon.decode_position;
authorwenzelm
Mon, 21 Mar 2011 23:38:32 +0100
changeset 42046 6341c23baf10
parent 42045 fda09013c496
child 42047 a7a4e04b5386
added Lexicon.encode_position, Lexicon.decode_position;
src/Pure/Syntax/lexicon.ML
--- a/src/Pure/Syntax/lexicon.ML	Mon Mar 21 21:16:39 2011 +0100
+++ b/src/Pure/Syntax/lexicon.ML	Mon Mar 21 23:38:32 2011 +0100
@@ -42,6 +42,8 @@
     case_fixed: string -> 'a,
     case_default: string -> 'a} -> string -> 'a
   val is_marked: string -> bool
+  val encode_position: Position.T -> string
+  val decode_position: string -> Position.T option
 end;
 
 signature LEXICON =
@@ -449,6 +451,19 @@
   in
    {mant = sign * #1 (Library.read_int (intpart @ fracpart)),
     exp = length fracpart}
-  end
+  end;
+
+
+(* positions *)
+
+fun encode_position pos =
+  op ^ (YXML.output_markup (Position.markup pos Markup.position));
+
+fun decode_position str =
+  (case YXML.parse_body str handle Fail msg => error msg of
+    [XML.Elem ((name, props), [])] =>
+      if name = Markup.positionN then SOME (Position.of_properties props)
+      else NONE
+  | _ => NONE);
 
 end;