From 4e6e532ce8370f9e078e6b3e4174838b140a48b4 Mon Sep 17 00:00:00 2001 From: EmileRolley Date: Sat, 15 May 2021 15:14:37 +0200 Subject: [PATCH] feat(lexer): allows to use '`' inside law text --- src/catala/surface/lexer.ml | 4 ++- .../good/output/test_spe_char.catala.Test.out | 2 ++ tests/test_literate/good/test_spe_char.catala | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/test_literate/good/output/test_spe_char.catala.Test.out create mode 100644 tests/test_literate/good/test_spe_char.catala diff --git a/src/catala/surface/lexer.ml b/src/catala/surface/lexer.ml index 91e7afb3..cd65a777 100644 --- a/src/catala/surface/lexer.ml +++ b/src/catala/surface/lexer.ml @@ -554,7 +554,9 @@ let lex_law (lexbuf : lexbuf) : token = LAW_INCLUDE (Ast.PdfFile ((name, Pos.from_lpos pos), pages)) else LAW_INCLUDE (Ast.CatalaFile (name, Pos.from_lpos pos)) | Plus '#', Star white_space, Plus (Compl '\n'), Star white_space, '\n' -> get_law_heading lexbuf - | Plus (Compl ('#' | '`' | '>')) -> LAW_TEXT (Utf8.lexeme lexbuf) + | Plus (Compl ('#' | '`' | '>') | Rep ('`', 1 .. 2), Compl '`' | "```", (Plus white_space | '\n')) + -> + LAW_TEXT (Utf8.lexeme lexbuf) | _ -> raise_lexer_error (Pos.from_lpos prev_pos) prev_lexeme (** Entry point of the lexer, distributes to {!val: lex_code} or {!val: lex_law} depending of {!val: diff --git a/tests/test_literate/good/output/test_spe_char.catala.Test.out b/tests/test_literate/good/output/test_spe_char.catala.Test.out new file mode 100644 index 00000000..a658dffc --- /dev/null +++ b/tests/test_literate/good/output/test_spe_char.catala.Test.out @@ -0,0 +1,2 @@ +[RESULT] Computation successful! Results: +[RESULT] literate_parsing_is_ok = true diff --git a/tests/test_literate/good/test_spe_char.catala b/tests/test_literate/good/test_spe_char.catala new file mode 100644 index 00000000..a7654bac --- /dev/null +++ b/tests/test_literate/good/test_spe_char.catala @@ -0,0 +1,26 @@ +## Law text should be able to contain '`'. + +This is a block of law text containing `. +This allows to: + +* use `Markdown` code block inside `Catala` files, + +* _escape_ special characters such as `#` or `>`, + +* use Fenced Code Blocks: + +``` +let () = print_endline "Hello world!" +``` + +**Remark**: for Fenced Code Blocks, ``` must be followed by a space or a new line. + +```catala +new scope Test : + param literate_parsing_is_ok content bool + +scope Test : + def literate_parsing_is_ok := true +``` + +Even after `Catala` code block.