src/Pure/Isar/value_parse.ML
changeset 29308 ddf7fad4448c
child 29458 98d749ae5edc
equal deleted inserted replaced
29307:3a0b38b7fbb4 29308:ddf7fad4448c
       
     1 (*  Title:      Pure/Isar/value_parse.ML
       
     2     Author:     Makarius
       
     3 
       
     4 Outer syntax parsers for basic ML values.
       
     5 *)
       
     6 
       
     7 signature VALUE_PARSE =
       
     8 sig
       
     9   type 'a parser = 'a OuterParse.parser
       
    10   val comma: 'a parser -> 'a parser
       
    11   val equal: 'a parser -> 'a parser
       
    12   val parens: 'a parser -> 'a parser
       
    13   val pair: 'a parser -> 'b parser -> ('a * 'b) parser
       
    14   val triple: 'a parser -> 'b parser -> 'c parser -> ('a * 'b * 'c) parser
       
    15   val properties: Properties.T parser
       
    16 end;
       
    17 
       
    18 structure ValueParse: VALUE_PARSE =
       
    19 struct
       
    20 
       
    21 structure P = OuterParse;
       
    22 type 'a parser = 'a P.parser;
       
    23 
       
    24 
       
    25 (* syntax utilities *)
       
    26 
       
    27 fun comma p = P.$$$ "," |-- P.!!! p;
       
    28 fun equal p = P.$$$ "=" |-- P.!!! p;
       
    29 fun parens p = P.$$$ "(" |-- P.!!! (p --| P.$$$ ")");
       
    30 
       
    31 
       
    32 (* tuples *)
       
    33 
       
    34 val unit = parens (Scan.succeed ());
       
    35 fun pair p1 p2 = parens (p1 -- comma p2);
       
    36 fun triple p1 p2 p3 = parens (p1 -- comma p2 -- comma p3) >> P.triple1;
       
    37 
       
    38 
       
    39 (* lists *)
       
    40 
       
    41 fun list p = parens (P.enum "," p);
       
    42 val properties = list (P.string -- equal P.string);
       
    43 
       
    44 end;
       
    45