feat(lexer): allows to use '`' inside law text

This commit is contained in:
EmileRolley 2021-05-15 15:14:37 +02:00
parent 54067f337f
commit 4e6e532ce8
3 changed files with 31 additions and 1 deletions

View File

@ -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:

View File

@ -0,0 +1,2 @@
[RESULT] Computation successful! Results:
[RESULT] literate_parsing_is_ok = true

View File

@ -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.