2019-12-23 18:18:32 +04:00
|
|
|
open Trace
|
|
|
|
open Test_helpers
|
|
|
|
|
|
|
|
module SnippetsGroup = Map.Make(struct type t = (string * string) let compare a b = compare a b end)
|
|
|
|
|
|
|
|
let failed_to_compile_md_file md_file (s,group,prg) =
|
2019-12-24 19:10:31 +04:00
|
|
|
let title () = "Failed to compile ```"^s^" block (group '"^group^"') in file '"^md_file^"'" in
|
2019-12-26 17:22:13 +04:00
|
|
|
let content () = "\n"^prg in
|
|
|
|
error title content
|
2019-12-23 18:18:32 +04:00
|
|
|
|
2020-01-09 13:33:44 +04:00
|
|
|
let bad_code_block_argument arg =
|
|
|
|
let title () = Format.asprintf "Bad code block argument '%s'" arg in
|
|
|
|
let content () = "only 'group=NAME' or 'skip' are allowed" in
|
|
|
|
error title content
|
|
|
|
|
2019-12-23 18:18:32 +04:00
|
|
|
(**
|
|
|
|
binds the snippets by (syntax, group_name)
|
|
|
|
e.g. :(pascaligo, a) -> "let .. in let .. in"
|
|
|
|
(cameligo, a) -> "let .. in let .. in"
|
|
|
|
syntax and group_name being retrieved from the .md file header & arguments
|
|
|
|
e.g. : ```syntax group=group_name ...some code ... ```
|
|
|
|
**)
|
|
|
|
let get_groups md_file =
|
|
|
|
let channel = open_in md_file in
|
|
|
|
let lexbuf = Lexing.from_channel channel in
|
|
|
|
let code_blocks = Md.token lexbuf in
|
2020-01-09 13:33:44 +04:00
|
|
|
bind_fold_list
|
2019-12-23 18:18:32 +04:00
|
|
|
(fun (grp_map: _ SnippetsGroup.t) (el:Md.block) ->
|
|
|
|
match el.header with
|
2020-01-09 13:33:44 +04:00
|
|
|
| Some ("pascaligo" as s) | Some ("cameligo" as s) | Some ("reasonligo" as s) -> (
|
|
|
|
let%bind () = bind_iter_list
|
|
|
|
(fun arg -> match arg with
|
|
|
|
| Md.Field "" | Md.Field "skip" | Md.NameValue ("group",_) -> ok ()
|
|
|
|
| Md.Field f | Md.NameValue (f,_) -> fail @@ bad_code_block_argument f)
|
|
|
|
el.arguments in
|
2019-12-24 19:10:31 +04:00
|
|
|
match el.arguments with
|
2020-01-09 13:33:44 +04:00
|
|
|
| [Md.Field ""] ->
|
|
|
|
ok @@ SnippetsGroup.update (s,"ungrouped")
|
2019-12-24 19:10:31 +04:00
|
|
|
(fun arg_content ->
|
|
|
|
match arg_content with
|
|
|
|
| Some ct -> Some (String.concat "\n" (ct::el.contents))
|
|
|
|
| None -> Some (String.concat "\n" el.contents)
|
|
|
|
)
|
|
|
|
grp_map
|
2020-01-09 13:33:44 +04:00
|
|
|
| [Md.Field "skip"] -> ok grp_map
|
|
|
|
| _ -> bind_fold_list
|
2019-12-23 18:18:32 +04:00
|
|
|
(fun grp_map arg -> match arg with
|
|
|
|
| Md.NameValue ("group", name) ->
|
2020-01-09 13:33:44 +04:00
|
|
|
ok @@ SnippetsGroup.update (s,name)
|
2019-12-23 18:18:32 +04:00
|
|
|
(fun arg_content ->
|
|
|
|
match arg_content with
|
|
|
|
| Some ct -> Some (String.concat "\n" (ct::el.contents))
|
|
|
|
| None -> Some (String.concat "\n" el.contents)
|
|
|
|
)
|
|
|
|
grp_map
|
2020-01-09 13:33:44 +04:00
|
|
|
| _ -> ok grp_map
|
2019-12-23 18:18:32 +04:00
|
|
|
)
|
2019-12-24 19:10:31 +04:00
|
|
|
grp_map el.arguments )
|
2020-01-09 13:33:44 +04:00
|
|
|
| None | Some _ -> ok grp_map
|
2019-12-23 18:18:32 +04:00
|
|
|
)
|
|
|
|
SnippetsGroup.empty code_blocks
|
|
|
|
|
|
|
|
(**
|
|
|
|
evaluate each expression in each programs from the snippets group map
|
|
|
|
**)
|
2019-12-24 19:10:31 +04:00
|
|
|
let compile_groups _filename grp_list =
|
|
|
|
let%bind (_michelsons : Compiler.compiled_expression list list) = bind_map_list
|
2019-12-26 17:22:13 +04:00
|
|
|
(fun ((s,grp),contents) ->
|
|
|
|
trace (failed_to_compile_md_file _filename (s,grp,contents)) @@
|
2019-12-23 18:18:32 +04:00
|
|
|
let%bind v_syntax = Compile.Helpers.syntax_to_variant (Syntax_name s) None in
|
|
|
|
let%bind simplified = Compile.Of_source.compile_string contents v_syntax in
|
|
|
|
let%bind typed,_ = Compile.Of_simplified.compile simplified in
|
|
|
|
let%bind mini_c = Compile.Of_typed.compile typed in
|
|
|
|
bind_map_list
|
2020-01-16 23:36:04 +04:00
|
|
|
(fun ((_, _, exp),_) -> Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp)
|
2019-12-23 18:18:32 +04:00
|
|
|
mini_c
|
2019-12-24 19:10:31 +04:00
|
|
|
)
|
2019-12-23 18:18:32 +04:00
|
|
|
grp_list in
|
|
|
|
ok ()
|
|
|
|
|
2019-12-24 19:10:31 +04:00
|
|
|
let compile filename () =
|
2020-01-09 13:33:44 +04:00
|
|
|
let%bind groups = get_groups filename in
|
|
|
|
let groups_map = SnippetsGroup.bindings groups in
|
|
|
|
let%bind () = compile_groups filename groups_map in
|
2019-12-23 18:18:32 +04:00
|
|
|
ok ()
|
|
|
|
|
2019-12-24 19:10:31 +04:00
|
|
|
(*
|
|
|
|
find ./gitlab-pages/ -iname "*.md"
|
|
|
|
*)
|
|
|
|
let md_files = [
|
|
|
|
"/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md";
|
|
|
|
"/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md";
|
|
|
|
"/gitlab-pages/docs/intro/installation.md";
|
|
|
|
"/gitlab-pages/docs/intro/editor-support.md";
|
2020-03-03 09:42:45 +04:00
|
|
|
"/gitlab-pages/docs/intro/ligo-intro.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/math-numbers-tez.md";
|
2019-12-26 17:22:13 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/functions.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/boolean-if-else.md";
|
|
|
|
"/gitlab-pages/docs/language-basics/types.md";
|
2019-12-26 17:22:13 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/strings.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/maps-records.md";
|
|
|
|
"/gitlab-pages/docs/language-basics/variables-and-constants.md";
|
2020-01-21 15:13:57 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/sets-lists-tuples.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/operators.md";
|
|
|
|
"/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md";
|
2020-01-02 23:38:45 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/loops.md";
|
2020-01-21 14:45:38 +04:00
|
|
|
"/gitlab-pages/docs/language-basics/tezos-specific.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
"/gitlab-pages/docs/contributors/big-picture/back-end.md";
|
|
|
|
"/gitlab-pages/docs/contributors/big-picture/vendors.md";
|
|
|
|
"/gitlab-pages/docs/contributors/big-picture/front-end.md";
|
|
|
|
"/gitlab-pages/docs/contributors/big-picture/overview.md";
|
|
|
|
"/gitlab-pages/docs/contributors/big-picture/middle-end.md";
|
|
|
|
"/gitlab-pages/docs/contributors/documentation-and-releases.md";
|
|
|
|
"/gitlab-pages/docs/contributors/getting-started.md";
|
|
|
|
"/gitlab-pages/docs/contributors/philosophy.md";
|
|
|
|
"/gitlab-pages/docs/contributors/ligo_test_guide.md";
|
|
|
|
"/gitlab-pages/docs/contributors/road-map/short-term.md";
|
|
|
|
"/gitlab-pages/docs/contributors/road-map/long-term.md";
|
|
|
|
"/gitlab-pages/docs/contributors/origin.md";
|
|
|
|
"/gitlab-pages/docs/advanced/first-contract.md";
|
|
|
|
"/gitlab-pages/docs/advanced/entrypoints-contracts.md";
|
|
|
|
"/gitlab-pages/docs/advanced/timestamps-addresses.md";
|
|
|
|
"/gitlab-pages/docs/api/cli-commands.md";
|
|
|
|
"/gitlab-pages/docs/api/cheat-sheet.md";
|
2020-02-08 08:17:13 +04:00
|
|
|
"/gitlab-pages/docs/reference/list.md";
|
2020-02-11 08:51:48 +04:00
|
|
|
"/gitlab-pages/docs/reference/map.md";
|
2020-02-12 05:39:41 +04:00
|
|
|
"/gitlab-pages/docs/reference/set.md";
|
2020-02-11 13:03:46 +04:00
|
|
|
"/gitlab-pages/docs/reference/big_map.md";
|
2020-02-07 17:27:23 +04:00
|
|
|
"/gitlab-pages/docs/reference/string.md";
|
2020-02-12 06:47:54 +04:00
|
|
|
"/gitlab-pages/docs/reference/crypto.md";
|
2020-02-25 17:26:04 +04:00
|
|
|
"/gitlab-pages/docs/reference/current.md";
|
2019-12-24 19:10:31 +04:00
|
|
|
]
|
|
|
|
|
2019-12-23 18:18:32 +04:00
|
|
|
let md_root = "../../gitlab-pages/docs/language-basics/"
|
2019-12-24 19:10:31 +04:00
|
|
|
let main = test_suite "Markdown files"
|
|
|
|
(List.map (fun md_file ->
|
|
|
|
let test_name = "File : \"."^md_file^"\"" in
|
|
|
|
let md_path = "../.."^md_file in
|
|
|
|
test test_name (compile md_path))
|
|
|
|
md_files)
|