src/Pure/Syntax/syntax.ML
changeset 55828 42ac3cfb89f6
parent 52160 7746c9f1baf3
child 55829 b7bdea5336dd
equal deleted inserted replaced
55827:8a881f83e206 55828:42ac3cfb89f6
    12   val root: string Config.T
    12   val root: string Config.T
    13   val ambiguity_warning_raw: Config.raw
    13   val ambiguity_warning_raw: Config.raw
    14   val ambiguity_warning: bool Config.T
    14   val ambiguity_warning: bool Config.T
    15   val ambiguity_limit_raw: Config.raw
    15   val ambiguity_limit_raw: Config.raw
    16   val ambiguity_limit: int Config.T
    16   val ambiguity_limit: int Config.T
    17   val read_token: string -> Symbol_Pos.T list * Position.T
       
    18   val read_token_pos: string -> Position.T
    17   val read_token_pos: string -> Position.T
       
    18   val read_token_source: string -> Symbol_Pos.source
       
    19   val read_token_content: string -> string * Position.T
    19   val parse_token: Proof.context -> (XML.tree list -> 'a) ->
    20   val parse_token: Proof.context -> (XML.tree list -> 'a) ->
    20     Markup.T -> (Symbol_Pos.T list * Position.T -> 'a) -> string -> 'a
    21     (bool -> Markup.T) -> (Symbol_Pos.T list * Position.T -> 'a) -> string -> 'a
    21   val parse_sort: Proof.context -> string -> sort
    22   val parse_sort: Proof.context -> string -> sort
    22   val parse_typ: Proof.context -> string -> typ
    23   val parse_typ: Proof.context -> string -> typ
    23   val parse_term: Proof.context -> string -> term
    24   val parse_term: Proof.context -> string -> term
    24   val parse_prop: Proof.context -> string -> term
    25   val parse_prop: Proof.context -> string -> term
    25   val unparse_sort: Proof.context -> sort -> Pretty.T
    26   val unparse_sort: Proof.context -> sort -> Pretty.T
   157 val ambiguity_limit = Config.int ambiguity_limit_raw;
   158 val ambiguity_limit = Config.int ambiguity_limit_raw;
   158 
   159 
   159 
   160 
   160 (* outer syntax token -- with optional YXML content *)
   161 (* outer syntax token -- with optional YXML content *)
   161 
   162 
       
   163 local
       
   164 
   162 fun token_position (XML.Elem ((name, props), _)) =
   165 fun token_position (XML.Elem ((name, props), _)) =
   163       if name = Markup.tokenN then Position.of_properties props
   166       if name = Markup.tokenN
   164       else Position.none
   167       then (Markup.is_delimited props, Position.of_properties props)
   165   | token_position (XML.Text _) = Position.none;
   168       else (false, Position.none)
   166 
   169   | token_position (XML.Text _) = (false, Position.none);
   167 fun explode_token tree =
   170 
       
   171 fun token_source tree =
   168   let
   172   let
   169     val text = XML.content_of [tree];
   173     val text = XML.content_of [tree];
   170     val pos = token_position tree;
   174     val (delimited, pos) = token_position tree;
   171   in (Symbol_Pos.explode (text, pos), pos) end;
   175   in {delimited = delimited, text = text, pos = pos} end;
   172 
   176 
   173 fun read_token str = explode_token (YXML.parse str handle Fail msg => error msg);
   177 in
   174 fun read_token_pos str = token_position (YXML.parse str handle Fail msg => error msg);
   178 
       
   179 fun read_token_pos str = #2 (token_position (YXML.parse str handle Fail msg => error msg));
       
   180 
       
   181 fun read_token_source str = token_source (YXML.parse str handle Fail msg => error msg);
       
   182 
       
   183 fun read_token_content str =
       
   184   let
       
   185     val {text, pos, ...} = read_token_source str;
       
   186     val syms = Symbol_Pos.explode (text, pos);
       
   187   in (Symbol_Pos.content syms, pos) end;
   175 
   188 
   176 fun parse_token ctxt decode markup parse str =
   189 fun parse_token ctxt decode markup parse str =
   177   let
   190   let
   178     fun parse_tree tree =
   191     fun parse_tree tree =
   179       let
   192       let
   180         val (syms, pos) = explode_token tree;
   193         val {delimited, text, pos} = token_source tree;
   181         val _ = Context_Position.report ctxt pos markup;
   194         val syms = Symbol_Pos.explode (text, pos);
       
   195         val _ = Context_Position.report ctxt pos (markup delimited);
   182       in parse (syms, pos) end;
   196       in parse (syms, pos) end;
   183   in
   197   in
   184     (case YXML.parse_body str handle Fail msg => error msg of
   198     (case YXML.parse_body str handle Fail msg => error msg of
   185       body as [tree as XML.Elem ((name, _), _)] =>
   199       body as [tree as XML.Elem ((name, _), _)] =>
   186         if name = Markup.tokenN then parse_tree tree else decode body
   200         if name = Markup.tokenN then parse_tree tree else decode body
   187     | [tree as XML.Text _] => parse_tree tree
   201     | [tree as XML.Text _] => parse_tree tree
   188     | body => decode body)
   202     | body => decode body)
   189   end;
   203   end;
       
   204 
       
   205 end;
   190 
   206 
   191 
   207 
   192 (* (un)parsing *)
   208 (* (un)parsing *)
   193 
   209 
   194 val parse_sort = operation #parse_sort;
   210 val parse_sort = operation #parse_sort;