diff -r 817ecad4cf72 -r f65b9f14d5de ProgTutorial/Recipes/Antiquotes.thy --- a/ProgTutorial/Recipes/Antiquotes.thy Tue Jun 28 08:44:34 2011 +0100 +++ b/ProgTutorial/Recipes/Antiquotes.thy Tue Jun 28 09:22:00 2011 +0100 @@ -46,7 +46,9 @@ (ML_Context.eval_text_in (SOME ctxt) false Position.none (ml_val code_txt); Thy_Output.output ctxt (map Pretty.str (space_explode "\n" code_txt))) -val _ = Thy_Output.antiquotation "ML_checked" (Scan.lift Args.name) output_ml*} +val ml_checked_setup = Thy_Output.antiquotation @{binding "ML_checked"} (Scan.lift Args.name) output_ml*} + +setup {* ml_checked_setup *} text {* The parser @{ML "(Scan.lift Args.name)"} in Line 7 parses a string, in this @@ -77,16 +79,18 @@ (ML_Context.eval_text_in (SOME ctxt) false pos (ml_val code_txt); Thy_Output.output ctxt (map Pretty.str (space_explode "\n" code_txt))) -val _ = Thy_Output.antiquotation "ML_checked" +val ml_checked_setup2 = Thy_Output.antiquotation @{binding "ML_checked2"} (Scan.lift (Parse.position Args.name)) output_ml *} +setup {* ml_checked_setup2 *} + text {* where in Lines 1 and 2 the positional information is properly treated. The parser @{ML Parse.position} encodes the positional information in the result. - We can now write @{text "@{ML_checked \"2 + 3\"}"} in a document in order to - obtain @{ML_checked "2 + 3"} and be sure that this code compiles until + We can now write @{text "@{ML_checked2 \"2 + 3\"}"} in a document in order to + obtain @{ML_checked2 "2 + 3"} and be sure that this code compiles until somebody changes the definition of addition. @@ -102,7 +106,7 @@ give a partial specification by using ellipses. For example @{text "(\, \)"} for specifying a pair. In order to check consistency between the pattern and the output of the code, we have to change the ML-expression that is sent - to the compiler: in @{text "ML_checked"} we sent the expression @{text [quotes] + to the compiler: in @{text "ML_checked2"} we sent the expression @{text [quotes] "val _ = a_piece_of_code"} to the compiler; now the wildcard @{text "_"} must be be replaced by the given pattern. However, we have to remove all ellipses from it and replace them by @{text [quotes] "_"}. The following @@ -136,12 +140,14 @@ Thy_Output.output ctxt (map Pretty.str (code_output @ resp_output)) end) -val _ = Thy_Output.antiquotation "ML_resp" +val ml_resp_setup = Thy_Output.antiquotation @{binding "ML_resp"} (Scan.lift (Parse.position (Args.name -- Args.name))) output_ml_resp*} +setup {* ml_resp_setup *} + text {* - In comparison with @{text "ML_checked"}, we only changed the line about + In comparison with @{text "ML_checked2"}, we only changed the line about the compiler (Line~2), the lines about the output (Lines 4 to 7) and the parser in the setup (Line 11). Now you can write