Automatic unit test discovery, improved inclusion system

This commit is contained in:
Denis Merigoux 2020-12-11 21:17:01 +01:00
parent 4c219f81ff
commit 1ddd46af55
13 changed files with 423 additions and 395 deletions

View File

@ -23,7 +23,7 @@ TEST_FILES=$(wildcard */tests/*.catala*)
TEST_FILES_SCOPES=$(foreach TEST_FILE,$(TEST_FILES),\
$(foreach TEST_SCOPE,\
$(shell grep -Po "declaration scope [^:]*" $(TEST_FILE) | cut -d " " -f 3), \
$(word 1,$(subst /, ,$(TEST_FILE))).$(word 3,$(subst /, ,$(TEST_FILE))).$(TEST_SCOPE).run \
$(word 1,$(subst /, ,$(TEST_FILE))).$(word 1,$(subst ., ,$(word 3,$(subst /, ,$(TEST_FILE))))).$(TEST_SCOPE).run \
) \
)

View File

@ -32,8 +32,6 @@ Ils indiquent les montants relatifs aux allocations familiales, à l
Je vous demande de bien vouloir transmettre à la connaissance des organismes débiteurs les présentes instructions.
@@Inclusion: JORFTEXT000000227447@@
/*
# Cependant, le cas de Mayotte n'est pas traité dans la loi et ce sont donc
# les règles de cette annexe qui s'apppliquent.

View File

@ -1,7 +1,6 @@
@Test@
@@Include: ../section_132.catala_en@@
@Test@
/*
declaration scope TestSection132_1:
context section_132 scope QualifiedEmployeeDiscount

View File

@ -209,14 +209,12 @@ type law_include =
| CatalaFile of string Pos.marked
| LegislativeText of string Pos.marked
type law_article_item =
| LawText of string
| CodeBlock of code_block * source_repr
| LawInclude of law_include
type law_article_item = LawText of string | CodeBlock of code_block * source_repr
type law_heading = { law_heading_name : string; law_heading_precedence : int }
type law_structure =
| LawInclude of law_include
| LawHeading of law_heading * law_structure list
| LawArticle of law_article * law_article_item list
| MetadataBlock of code_block * source_repr

View File

@ -556,7 +556,7 @@ let desugar_program (ctxt : Name_resolution.context) (prgm : Ast.program) : Desu
| LawArticle (_, children) ->
List.fold_left (fun prgm child -> processer_article_item prgm child) prgm children
| MetadataBlock (b, c) -> processer_article_item prgm (CodeBlock (b, c))
| IntermediateText _ -> prgm
| IntermediateText _ | LawInclude _ -> prgm
in
let processer_item (prgm : Desugared.Ast.program) (item : Ast.program_item) :

View File

@ -338,7 +338,7 @@ let rec process_law_structure (ctxt : context) (s : Ast.law_structure)
(fun ctxt child -> process_law_article_item ctxt child process_item)
ctxt children
| Ast.MetadataBlock (b, c) -> process_law_article_item ctxt (Ast.CodeBlock (b, c)) process_item
| Ast.IntermediateText _ -> ctxt
| Ast.IntermediateText _ | Ast.LawInclude _ -> ctxt
(** Process a program item *)
let process_program_item (ctxt : context) (item : Ast.program_item)

File diff suppressed because it is too large Load Diff

View File

@ -546,9 +546,6 @@ law_article_item:
let (code, pos) = code_and_pos in
CodeBlock (code, (text, pos))
}
| includ = LAW_INCLUDE {
LawInclude includ
}
law_article:
| title = LAW_ARTICLE {
@ -590,6 +587,9 @@ source_file_item:
let (code, source_repr) = code in
LawStructure (MetadataBlock (code, source_repr))
}
| includ = LAW_INCLUDE {
LawStructure (LawInclude includ)
}
source_file_after_text:
| i = source_file_article f = source_file_after_text {
@ -632,7 +632,7 @@ source_file_or_master:
| [] -> assert false (* there should be at least one rest element *)
| rest_head::rest_tail ->
begin match first_item with
| LawStructure (LawArticle _ | MetadataBlock _ | IntermediateText _) ->
| LawStructure (LawArticle _ | MetadataBlock _ | IntermediateText _ | LawInclude _) ->
(* if an article or an include is just before a new heading or a new article,
then we don't merge it with what comes next *)
first_item::rest_head::rest_tail

View File

@ -154,52 +154,85 @@ let sedlex_with_menhir (lexer' : lexbuf -> Parser.token) (token_list : (string *
with Sedlexing.MalFormed | Sedlexing.InvalidCodepoint _ ->
Lexer.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf)
let rec parse_source_files (source_files : string list) (language : Cli.frontend_lang) : Ast.program
=
match source_files with
| [] -> { program_items = []; program_source_files = [] }
| source_file :: rest -> (
Cli.debug_print (Printf.sprintf "Parsing %s" source_file);
let input = try open_in source_file with Sys_error msg -> Errors.raise_error msg in
let lexbuf = Sedlexing.Utf8.from_channel input in
Sedlexing.set_filename lexbuf source_file;
Parse_utils.current_file := source_file;
let lexer_lang =
match language with
| `Fr -> Lexer_fr.lexer_fr
| `En -> Lexer_en.lexer_en
| `NonVerbose -> Lexer.lexer
let rec parse_source_file (source_file : string) (language : Cli.frontend_lang) : Ast.program =
Cli.debug_print (Printf.sprintf "Parsing %s" source_file);
let input = try open_in source_file with Sys_error msg -> Errors.raise_error msg in
let lexbuf = Sedlexing.Utf8.from_channel input in
Sedlexing.set_filename lexbuf source_file;
Parse_utils.current_file := source_file;
let lexer_lang =
match language with
| `Fr -> Lexer_fr.lexer_fr
| `En -> Lexer_en.lexer_en
| `NonVerbose -> Lexer.lexer
in
let token_list_lang =
match language with
| `Fr -> Lexer_fr.token_list_fr
| `En -> Lexer_en.token_list_en
| `NonVerbose -> Lexer.token_list
in
let commands_or_includes =
sedlex_with_menhir lexer_lang token_list_lang Parser.Incremental.source_file_or_master lexbuf
in
close_in input;
match commands_or_includes with
| Ast.SourceFile commands ->
let program = expand_includes source_file commands language in
{
program_items = program.Ast.program_items;
program_source_files = source_file :: program.Ast.program_source_files;
}
| Ast.MasterFile includes ->
let current_source_file_dirname = Filename.dirname source_file in
let includes =
List.map
(fun includ ->
(if current_source_file_dirname = "./" then "" else current_source_file_dirname ^ "/")
^ Pos.unmark includ)
includes
in
let token_list_lang =
match language with
| `Fr -> Lexer_fr.token_list_fr
| `En -> Lexer_en.token_list_en
| `NonVerbose -> Lexer.token_list
let new_program =
List.fold_left
(fun acc includ_file ->
let includ_program = parse_source_file includ_file language in
{
Ast.program_source_files =
acc.Ast.program_source_files @ includ_program.program_source_files;
Ast.program_items = acc.Ast.program_items @ includ_program.program_items;
})
{ Ast.program_source_files = []; Ast.program_items = [] }
includes
in
let commands_or_includes =
sedlex_with_menhir lexer_lang token_list_lang Parser.Incremental.source_file_or_master
lexbuf
in
close_in input;
match commands_or_includes with
| Ast.SourceFile commands ->
let rest_program = parse_source_files rest language in
{ new_program with program_source_files = source_file :: new_program.program_source_files }
and expand_includes (source_file : string) (commands : Ast.program_item list)
(language : Cli.frontend_lang) : Ast.program =
List.fold_left
(fun acc command ->
match command with
| Ast.LawStructure (LawInclude (Ast.CatalaFile sub_source)) ->
let source_dir = Filename.dirname source_file in
let sub_source = Filename.concat source_dir (Pos.unmark sub_source) in
let includ_program = parse_source_file sub_source language in
{
program_items = commands @ rest_program.Ast.program_items;
program_source_files = source_file :: rest_program.Ast.program_source_files;
Ast.program_source_files =
acc.Ast.program_source_files @ includ_program.program_source_files;
Ast.program_items = acc.Ast.program_items @ includ_program.program_items;
}
| Ast.MasterFile includes ->
let current_source_file_dirname = Filename.dirname source_file in
let includes =
List.map
(fun includ ->
( if current_source_file_dirname = "./" then ""
else current_source_file_dirname ^ "/" )
^ Pos.unmark includ)
includes
| Ast.LawStructure (Ast.LawHeading (heading, commands')) ->
let { Ast.program_items = commands'; Ast.program_source_files = new_sources } =
expand_includes source_file (List.map (fun x -> Ast.LawStructure x) commands') language
in
let new_program = parse_source_files (includes @ rest) language in
{
new_program with
program_source_files = source_file :: new_program.program_source_files;
} )
Ast.program_source_files = acc.Ast.program_source_files @ new_sources;
Ast.program_items =
acc.Ast.program_items
@ [
Ast.LawStructure
(Ast.LawHeading (heading, List.map (fun (Ast.LawStructure x) -> x) commands'));
];
}
| i -> { acc with Ast.program_items = acc.Ast.program_items @ [ i ] })
{ Ast.program_source_files = []; Ast.program_items = [] }
commands

View File

@ -11,146 +11,146 @@ let message s =
| 7 ->
"expected another inclusion of a Catala file, since this file is a master file which can \
only contain inclusions of other Catala files\n"
| 317 -> "expected some text, another heading or a law article\n"
| 322 -> "expected a code block, a metadata block, more law text or a heading\n"
| 318 -> "expected some text, another heading or a law article\n"
| 323 -> "expected a code block, a metadata block, more law text or a heading\n"
| 329 -> "expected a code block, a metadata block, more law text or a heading\n"
| 324 -> "expected a declaration or a scope use\n"
| 21 -> "expected the name of the scope you want to use\n"
| 23 -> "expected a scope use precondition or a colon\n"
| 24 -> "expected an expression which will act as the condition\n"
| 25 -> "expected the first component of the date literal\n"
| 27 -> "expected a \"/\"\n"
| 28 -> "expected the second component of the date literal\n"
| 29 -> "expected a \"/\"\n"
| 30 -> "expected the third component of the date literal\n"
| 31 -> "expected a delimiter to finish the date literal\n"
| 56 -> "expected an operator to compose the expression on the left with\n"
| 62 -> "expected an enum constructor to test if the expression on the left\n"
| 61 -> "expected an operator to compose the expression on the left with\n"
| 117 -> "expected an expression on the right side of the sum or minus operator\n"
| 145 -> "expected an expression on the right side of the logical operator\n"
| 64 -> "expected an expression for the argument of this function call\n"
| 105 -> "expected an expression on the right side of the comparison operator\n"
| 126 -> "expected an expression on the right side of the multiplication or division operator\n"
| 119 -> "expected an operator to compose the expression on the left\n"
| 155 -> "expected an expression standing for the set you want to test for membership\n"
| 57 -> "expected an identifier standing for a struct field or a subscope name\n"
| 197 -> "expected a colon after the scope use precondition\n"
| 59 -> "expected a constructor, to get the payload of this enum case\n"
| 129 -> "expected the \"for\" keyword to spell the aggregation\n"
| 130 -> "expected an identifier for the aggregation bound variable\n"
| 131 -> "expected the \"in\" keyword\n"
| 132 ->
| 22 -> "expected the name of the scope you want to use\n"
| 24 -> "expected a scope use precondition or a colon\n"
| 25 -> "expected an expression which will act as the condition\n"
| 26 -> "expected the first component of the date literal\n"
| 28 -> "expected a \"/\"\n"
| 29 -> "expected the second component of the date literal\n"
| 30 -> "expected a \"/\"\n"
| 31 -> "expected the third component of the date literal\n"
| 32 -> "expected a delimiter to finish the date literal\n"
| 57 -> "expected an operator to compose the expression on the left with\n"
| 63 -> "expected an enum constructor to test if the expression on the left\n"
| 62 -> "expected an operator to compose the expression on the left with\n"
| 118 -> "expected an expression on the right side of the sum or minus operator\n"
| 146 -> "expected an expression on the right side of the logical operator\n"
| 65 -> "expected an expression for the argument of this function call\n"
| 106 -> "expected an expression on the right side of the comparison operator\n"
| 127 -> "expected an expression on the right side of the multiplication or division operator\n"
| 120 -> "expected an operator to compose the expression on the left\n"
| 156 -> "expected an expression standing for the set you want to test for membership\n"
| 58 -> "expected an identifier standing for a struct field or a subscope name\n"
| 198 -> "expected a colon after the scope use precondition\n"
| 60 -> "expected a constructor, to get the payload of this enum case\n"
| 130 -> "expected the \"for\" keyword to spell the aggregation\n"
| 131 -> "expected an identifier for the aggregation bound variable\n"
| 132 -> "expected the \"in\" keyword\n"
| 133 ->
"expected an expression standing for the set over which to compute the aggregation operation\n"
| 134 -> "expected the \"for\" keyword and the expression to compute the aggregate\n"
| 135 -> "expected an expression to compute its aggregation over the set\n"
| 139 -> "expected an expression to take the negation of\n"
| 53 -> "expected an expression to take the opposite of\n"
| 42 -> "expected an expression to match with\n"
| 181 -> "expected a pattern matching case\n"
| 182 -> "expected the name of the constructor for the enum case in the pattern matching\n"
| 188 ->
| 135 -> "expected the \"for\" keyword and the expression to compute the aggregate\n"
| 136 -> "expected an expression to compute its aggregation over the set\n"
| 140 -> "expected an expression to take the negation of\n"
| 54 -> "expected an expression to take the opposite of\n"
| 43 -> "expected an expression to match with\n"
| 182 -> "expected a pattern matching case\n"
| 183 -> "expected the name of the constructor for the enum case in the pattern matching\n"
| 189 ->
"expected a binding for the constructor payload, or a colon and the matching case expression\n"
| 189 -> "expected an identifier for this enum case binding\n"
| 185 -> "expected a colon and then the expression for this matching case\n"
| 191 -> "expected a colon or a binding for the enum constructor payload\n"
| 186 -> "expected an expression for this pattern matching case\n"
| 183 ->
| 190 -> "expected an identifier for this enum case binding\n"
| 186 -> "expected a colon and then the expression for this matching case\n"
| 192 -> "expected a colon or a binding for the enum constructor payload\n"
| 187 -> "expected an expression for this pattern matching case\n"
| 184 ->
"expected another match case or the rest of the expression since the previous match case is \
complete\n"
| 180 -> "expected the \"with patter\" keyword to complete the pattern matching expression\n"
| 43 -> "expected an expression inside the parenthesis\n"
| 178 -> "unmatched parenthesis that should have been closed by here\n"
| 65 -> "expected a unit for this literal, or a valid operator to complete the expression \n"
| 45 -> "expected an expression for the test of the conditional\n"
| 174 -> "expected an expression the for the \"then\" branch of the conditiona\n"
| 175 ->
| 181 -> "expected the \"with patter\" keyword to complete the pattern matching expression\n"
| 44 -> "expected an expression inside the parenthesis\n"
| 179 -> "unmatched parenthesis that should have been closed by here\n"
| 66 -> "expected a unit for this literal, or a valid operator to complete the expression \n"
| 46 -> "expected an expression for the test of the conditional\n"
| 175 -> "expected an expression the for the \"then\" branch of the conditiona\n"
| 176 ->
"expected the \"else\" branch of this conditional expression as the \"then\" branch is \
complete\n"
| 176 -> "expected an expression for the \"else\" branch of this conditional construction\n"
| 173 -> "expected the \"then\" keyword as the conditional expression is complete\n"
| 47 ->
| 177 -> "expected an expression for the \"else\" branch of this conditional construction\n"
| 174 -> "expected the \"then\" keyword as the conditional expression is complete\n"
| 48 ->
"expected the \"all\" keyword to mean the \"for all\" construction of the universal test\n"
| 159 -> "expected an identifier for the bound variable of the universal test\n"
| 160 -> "expected the \"in\" keyword for the rest of the universal test\n"
| 161 -> "expected the expression designating the set on which to perform the universal test\n"
| 162 -> "expected the \"we have\" keyword for this universal test\n"
| 158 -> "expected an expression for the universal test\n"
| 167 -> "expected an identifier that will designate the existential witness for the test\n"
| 168 -> "expected the \"in\" keyword to continue this existential test\n"
| 169 -> "expected an expression that designates the set subject to the existential test\n"
| 170 -> "expected a keyword to form the \"such that\" expression for the existential test\n"
| 171 -> "expected a keyword to complete the \"such that\" construction\n"
| 165 -> "expected an expression for the existential test\n"
| 74 ->
| 160 -> "expected an identifier for the bound variable of the universal test\n"
| 161 -> "expected the \"in\" keyword for the rest of the universal test\n"
| 162 -> "expected the expression designating the set on which to perform the universal test\n"
| 163 -> "expected the \"we have\" keyword for this universal test\n"
| 159 -> "expected an expression for the universal test\n"
| 168 -> "expected an identifier that will designate the existential witness for the test\n"
| 169 -> "expected the \"in\" keyword to continue this existential test\n"
| 170 -> "expected an expression that designates the set subject to the existential test\n"
| 171 -> "expected a keyword to form the \"such that\" expression for the existential test\n"
| 172 -> "expected a keyword to complete the \"such that\" construction\n"
| 166 -> "expected an expression for the existential test\n"
| 75 ->
"expected a payload for the enum case constructor, or the rest of the expression (with an \
operator ?)\n"
| 149 -> "expected an expression for the content of this enum case\n"
| 150 ->
| 150 -> "expected an expression for the content of this enum case\n"
| 151 ->
"the expression for the content of the enum case is already well-formed, expected an \
operator to form a bigger expression\n"
| 52 -> "expected the keyword following cardinal to compute the number of elements in a set\n"
| 198 -> "expected a scope use item: a rule, definition or assertion\n"
| 199 -> "expected the name of the variable subject to the rule\n"
| 218 ->
| 53 -> "expected the keyword following cardinal to compute the number of elements in a set\n"
| 199 -> "expected a scope use item: a rule, definition or assertion\n"
| 200 -> "expected the name of the variable subject to the rule\n"
| 219 ->
"expected a condition or a consequence for this rule, or the rest of the variable qualified \
name\n"
| 213 -> "expected a condition or a consequence for this rule\n"
| 204 -> "expected filled or not filled for a rule consequence\n"
| 214 -> "expected the name of the parameter for this dependent variable \n"
| 201 -> "expected the expression of the rule\n"
| 207 -> "expected the filled keyword the this rule \n"
| 219 -> "expected a struct field or a sub-scope context item after the dot\n"
| 221 -> "expected the name of the variable you want to define\n"
| 222 -> "expected the defined as keyword to introduce the definition of this variable\n"
| 224 -> "expected an expression for the consequence of this definition under condition\n"
| 223 ->
| 214 -> "expected a condition or a consequence for this rule\n"
| 205 -> "expected filled or not filled for a rule consequence\n"
| 215 -> "expected the name of the parameter for this dependent variable \n"
| 202 -> "expected the expression of the rule\n"
| 208 -> "expected the filled keyword the this rule \n"
| 220 -> "expected a struct field or a sub-scope context item after the dot\n"
| 222 -> "expected the name of the variable you want to define\n"
| 223 -> "expected the defined as keyword to introduce the definition of this variable\n"
| 225 -> "expected an expression for the consequence of this definition under condition\n"
| 224 ->
"expected a expression for defining this function, introduced by the defined as keyword\n"
| 225 -> "expected an expression for the definition\n"
| 228 -> "expected an expression that shoud be asserted during execution\n"
| 229 -> "expecting the name of the varying variable\n"
| 231 -> "the variable varies with an expression that was expected here\n"
| 232 -> "expected an indication about the variation sense of the variable, or a new scope item\n"
| 230 -> "expected an indication about what this variable varies with\n"
| 202 -> "expected an expression for this condition\n"
| 210 -> "expected a consequence for this definition under condition\n"
| 241 -> "expected an expression for this definition under condition\n"
| 237 -> "expected the name of the variable that should be fixed\n"
| 238 -> "expected the legislative text by which the value of the variable is fixed\n"
| 226 -> "expected an expression for the definition\n"
| 229 -> "expected an expression that shoud be asserted during execution\n"
| 230 -> "expecting the name of the varying variable\n"
| 232 -> "the variable varies with an expression that was expected here\n"
| 233 -> "expected an indication about the variation sense of the variable, or a new scope item\n"
| 231 -> "expected an indication about what this variable varies with\n"
| 203 -> "expected an expression for this condition\n"
| 211 -> "expected a consequence for this definition under condition\n"
| 242 -> "expected an expression for this definition under condition\n"
| 238 -> "expected the name of the variable that should be fixed\n"
| 239 -> "expected the legislative text by which the value of the variable is fixed\n"
| 245 -> "expected a new scope use item \n"
| 248 -> "expected the kind of the declaration (struct, scope or enum)\n"
| 249 -> "expected the struct name\n"
| 250 -> "expected a colon\n"
| 251 -> "expected struct data or condition\n"
| 252 -> "expected the name of this struct data \n"
| 253 -> "expected the type of this struct data, introduced by the content keyword\n"
| 254 -> "expected the type of this struct data\n"
| 279 -> "expected the name of this struct condition\n"
| 272 -> "expected a new struct data, or another declaration or scope use\n"
| 273 -> "expected the type of the parameter of this struct data function\n"
| 277 -> "expected a new struct data, or another declaration or scope use\n"
| 266 -> "expected a new struct data, or another declaration or scope use\n"
| 269 -> "expected a new struct data, or another declaration or scope use\n"
| 282 -> "expected the name of the scope you are declaring\n"
| 283 -> "expected a colon followed by the list of context items of this scope\n"
| 284 -> "expected a context item introduced by \"context\"\n"
| 285 -> "expected the name of this new context item\n"
| 286 -> "expected the kind of this context item: is it a condition, a sub-scope or a data?\n"
| 287 -> "expected the name of the subscope for this context item\n"
| 294 -> "expected the next context item, or another declaration or scope use\n"
| 289 -> "expected the type of this context item\n"
| 290 -> "expected the next context item or a dependency declaration for this item\n"
| 292 -> "expected the next context item or a dependency declaration for this item\n"
| 297 -> "expected the name of your enum\n"
| 298 -> "expected a colon\n"
| 299 -> "expected an enum case\n"
| 300 -> "expected the name of an enum case \n"
| 301 -> "expected a payload for your enum case, or another case or declaration \n"
| 302 -> "expected a content type\n"
| 307 -> "expected another enum case, or a new declaration or scope use\n"
| 17 -> "expected a declaration or a scope use\n"
| 19 -> "expected a declaration or a scope use\n"
| 313 ->
| 240 -> "expected the legislative text by which the value of the variable is fixed\n"
| 246 -> "expected a new scope use item \n"
| 249 -> "expected the kind of the declaration (struct, scope or enum)\n"
| 250 -> "expected the struct name\n"
| 251 -> "expected a colon\n"
| 252 -> "expected struct data or condition\n"
| 253 -> "expected the name of this struct data \n"
| 254 -> "expected the type of this struct data, introduced by the content keyword\n"
| 255 -> "expected the type of this struct data\n"
| 280 -> "expected the name of this struct condition\n"
| 273 -> "expected a new struct data, or another declaration or scope use\n"
| 274 -> "expected the type of the parameter of this struct data function\n"
| 278 -> "expected a new struct data, or another declaration or scope use\n"
| 267 -> "expected a new struct data, or another declaration or scope use\n"
| 270 -> "expected a new struct data, or another declaration or scope use\n"
| 283 -> "expected the name of the scope you are declaring\n"
| 284 -> "expected a colon followed by the list of context items of this scope\n"
| 285 -> "expected a context item introduced by \"context\"\n"
| 286 -> "expected the name of this new context item\n"
| 287 -> "expected the kind of this context item: is it a condition, a sub-scope or a data?\n"
| 288 -> "expected the name of the subscope for this context item\n"
| 295 -> "expected the next context item, or another declaration or scope use\n"
| 290 -> "expected the type of this context item\n"
| 291 -> "expected the next context item or a dependency declaration for this item\n"
| 293 -> "expected the next context item or a dependency declaration for this item\n"
| 298 -> "expected the name of your enum\n"
| 299 -> "expected a colon\n"
| 300 -> "expected an enum case\n"
| 301 -> "expected the name of an enum case \n"
| 302 -> "expected a payload for your enum case, or another case or declaration \n"
| 303 -> "expected a content type\n"
| 308 -> "expected another enum case, or a new declaration or scope use\n"
| 18 -> "expected a declaration or a scope use\n"
| 20 -> "expected a declaration or a scope use\n"
| 314 ->
"should not happen, please file an issue at https://github.com/CatalaLang/catala/issues\n"
| _ -> raise Not_found

View File

@ -46,7 +46,7 @@ let driver (source_file : string) (debug : bool) (unstyled : bool) (wrap_weaved_
Errors.raise_error
(Printf.sprintf "The selected backend (%s) is not supported by Catala" backend)
in
let program = Surface.Parser_driver.parse_source_files [ source_file ] language in
let program = Surface.Parser_driver.parse_source_file source_file language in
match backend with
| Cli.Makefile ->
let backend_extensions_list = [ ".tex" ] in

View File

@ -150,7 +150,6 @@ let law_article_item_to_html (custom_pygments : string option) (language : C.bac
Format.fprintf fmt "<div class='code-wrapper'>\n<div class='filename'>%s</div>\n%s\n</div>"
(Pos.get_file (Pos.get_position c))
(pygmentize_code (Pos.same_pos_as ("/*" ^ pprinted_c ^ "*/") c) language custom_pygments)
| A.LawInclude _ -> ()
let rec law_structure_to_html (custom_pygments : string option) (language : C.backend_lang)
(fmt : Format.formatter) (i : A.law_structure) : unit =
@ -164,6 +163,7 @@ let rec law_structure_to_html (custom_pygments : string option) (language : C.ba
~pp_sep:(fun fmt () -> Format.fprintf fmt "\n")
(law_structure_to_html custom_pygments language)
fmt children
| A.LawInclude _ -> ()
| A.LawArticle (a, children) ->
Format.fprintf fmt
"<div class='article-container'>\n\n<div class='article-title'><a href='%s'>%s</a></div>\n"

View File

@ -135,15 +135,6 @@ let law_article_item_to_latex (language : C.backend_lang) (fmt : Format.formatte
(Pos.get_start_line (Pos.get_position c))
(match language with `Fr -> "catala_fr" | `En -> "catala_en")
(math_syms_replace (Pos.unmark c))
| A.LawInclude (A.PdfFile ((file, _), page)) ->
let label = file ^ match page with None -> "" | Some p -> Format.sprintf "_page_%d," p in
Format.fprintf fmt
"\\begin{center}\\textit{Annexe incluse, retranscrite page \\pageref{%s}}\\end{center} \
\\begin{figure}[p]\\begin{center}\\includegraphics[%swidth=\\textwidth]{%s}\\label{%s}\\end{center}\\end{figure}"
label
(match page with None -> "" | Some p -> Format.sprintf "page=%d," p)
file label
| A.LawInclude (A.CatalaFile _ | A.LegislativeText _) -> ()
let rec law_structure_to_latex (language : C.backend_lang) (fmt : Format.formatter)
(i : A.law_structure) : unit =
@ -160,6 +151,15 @@ let rec law_structure_to_latex (language : C.backend_lang) (fmt : Format.formatt
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "\n\n")
(law_structure_to_latex language) fmt children
| A.LawInclude (A.PdfFile ((file, _), page)) ->
let label = file ^ match page with None -> "" | Some p -> Format.sprintf "_page_%d," p in
Format.fprintf fmt
"\\begin{center}\\textit{Annexe incluse, retranscrite page \\pageref{%s}}\\end{center} \
\\begin{figure}[p]\\begin{center}\\includegraphics[%swidth=\\textwidth]{%s}\\label{%s}\\end{center}\\end{figure}"
label
(match page with None -> "" | Some p -> Format.sprintf "page=%d," p)
file label
| A.LawInclude (A.CatalaFile _ | A.LegislativeText _) -> ()
| A.LawArticle (article, children) ->
Format.fprintf fmt "\\paragraph{%s}\n\n" (pre_latexify (Pos.unmark article.law_article_name));
Format.pp_print_list