diff -r 321e220a6baa -r 034150db9d91 ProgTutorial/Recipes/Antiquotes.thy --- a/ProgTutorial/Recipes/Antiquotes.thy Tue May 21 16:22:30 2019 +0200 +++ b/ProgTutorial/Recipes/Antiquotes.thy Wed May 22 12:38:51 2019 +0200 @@ -46,12 +46,14 @@ fun output_ml ctxt code_txt = let - val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags (Input.pos_of code_txt) (ml_val code_txt) + val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags + (Input.pos_of code_txt) (ml_val code_txt) in Pretty.str (fst (Input.source_content code_txt)) end -val ml_checked_setup = Thy_Output.antiquotation_pretty_source @{binding "ML_checked"} (Scan.lift Args.text_input) output_ml\ +val ml_checked_setup = Thy_Output.antiquotation_pretty_source + @{binding "ML_checked"} (Scan.lift Args.text_input) output_ml\ setup \ml_checked_setup\ @@ -80,25 +82,7 @@ information about the line number, in case an error is detected. We can improve the code above slightly by writing \ -(* FIXME: remove -ML%linenosgray{*fun output_ml ctxt (code_txt, pos) = -let - val srcpos = {delimited = false, pos = pos, text = ml_val code_txt} -in - (ML_Context.eval_source_in (SOME ctxt) ML_Compiler.flags srcpos; - code_txt - |> space_explode "\n" - |> map Pretty.str - |> Pretty.list "" "" - |> Document_Antiquotation.output ctxt - |> Latex.string) -end -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 @@ -129,16 +113,11 @@ \ ML%linenosgray\fun ml_pat pat code = - ML_Lex.read "val" @ ML_Lex.read_source pat @ ML_Lex.read " = " @ ML_Lex.read_source code\ + ML_Lex.read "val" @ + ML_Lex.read_source pat @ + ML_Lex.read " = " @ + ML_Lex.read_source code\ -(* -ML %grayML{*fun ml_pat code_txt pat = -let val pat' = - implode (map (fn "\" => "_" | s => s) (Symbol.explode pat)) -in - ml_enclose ("val " ^ pat' ^ " = ") "" code_txt -end*} -*) text \ Next we add a response indicator to the result using: \ @@ -153,36 +132,21 @@ ML %linenosgray\ fun output_ml_resp ctxt (code_txt, pat) = let - val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags (Input.pos_of code_txt) (ml_pat pat code_txt) + val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags + (Input.pos_of code_txt) (ml_pat pat code_txt) val code = space_explode "\n" (fst (Input.source_content code_txt)) val resp = add_resp (space_explode "\n" (fst (Input.source_content pat))) in Pretty.str (cat_lines (code @ resp)) end -val ml_response_setup = Thy_Output.antiquotation_pretty_source @{binding "ML_resp"} (Scan.lift (Args.text_input -- Args.text_input)) output_ml_resp +val ml_response_setup = Thy_Output.antiquotation_pretty_source + @{binding "ML_resp"} + (Scan.lift (Args.text_input -- Args.text_input)) + output_ml_resp \ -(* -ML %linenosgray{*fun output_ml_resp {context = ctxt, ...} ((code_txt, pat), pos) = - (let - val srcpos = {delimited = false, text = ml_pat (code_txt, pat), pos = pos} - in - ML_Context.eval_source_in (SOME ctxt) ML_Compiler.flags srcpos - end; - let - val code_output = space_explode "\n" code_txt - val resp_output = add_resp (space_explode "\n" pat) - in - Thy_Output.output ctxt (map Pretty.str (code_output @ resp_output)) - end) - - -val ml_resp_setup = Thy_Output.antiquotation @{binding "ML_resp"} - (Scan.lift (Parse.position (Args.text_input -- Args.text_input))) - output_ml_resp*} -*) setup \ml_response_setup\ (* FIXME *)