src/Pure/Isar/parse_value.ML
changeset 36951 985c197f2fe9
parent 36950 75b8f26f2f07
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Isar/parse_value.ML	Sat May 15 23:23:45 2010 +0200
     1.3 @@ -0,0 +1,42 @@
     1.4 +(*  Title:      Pure/Isar/parse_value.ML
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Outer syntax parsers for basic ML values.
     1.8 +*)
     1.9 +
    1.10 +signature PARSE_VALUE =
    1.11 +sig
    1.12 +  val comma: 'a parser -> 'a parser
    1.13 +  val equal: 'a parser -> 'a parser
    1.14 +  val parens: 'a parser -> 'a parser
    1.15 +  val unit: unit parser
    1.16 +  val pair: 'a parser -> 'b parser -> ('a * 'b) parser
    1.17 +  val triple: 'a parser -> 'b parser -> 'c parser -> ('a * 'b * 'c) parser
    1.18 +  val list: 'a parser -> 'a list parser
    1.19 +  val properties: Properties.T parser
    1.20 +end;
    1.21 +
    1.22 +structure Parse_Value: PARSE_VALUE =
    1.23 +struct
    1.24 +
    1.25 +(* syntax utilities *)
    1.26 +
    1.27 +fun comma p = Parse.$$$ "," |-- Parse.!!! p;
    1.28 +fun equal p = Parse.$$$ "=" |-- Parse.!!! p;
    1.29 +fun parens p = Parse.$$$ "(" |-- Parse.!!! (p --| Parse.$$$ ")");
    1.30 +
    1.31 +
    1.32 +(* tuples *)
    1.33 +
    1.34 +val unit = parens (Scan.succeed ());
    1.35 +fun pair p1 p2 = parens (p1 -- comma p2);
    1.36 +fun triple p1 p2 p3 = parens (p1 -- comma p2 -- comma p3) >> Parse.triple1;
    1.37 +
    1.38 +
    1.39 +(* lists *)
    1.40 +
    1.41 +fun list p = parens (Parse.enum "," p);
    1.42 +val properties = list (Parse.string -- equal Parse.string);
    1.43 +
    1.44 +end;
    1.45 +