mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Beginning to parse
This commit is contained in:
parent
71e5d89fac
commit
e901408620
@ -29,7 +29,7 @@ let source_file_item_to_latex (i: A.source_file_item) : string =
|
||||
| A.LawCode c -> P.sprintf "\\subsection{%s}" c
|
||||
| A.LawText t -> t
|
||||
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" a
|
||||
| A.CodeBlock -> P.sprintf "\\begin{lstlisting}\n%s\n\\end{lstlisting}" "code"
|
||||
| A.CodeBlock c -> P.sprintf "\\begin{lstlisting}%s\\end{lstlisting}" c
|
||||
|
||||
let ast_to_latex (file : A.source_file) : string =
|
||||
String.concat "\n\n" (List.map (fun i ->
|
||||
|
@ -20,6 +20,6 @@ type source_file_item =
|
||||
| LawCode of string
|
||||
| LawArticle of string
|
||||
| LawText of string
|
||||
| CodeBlock
|
||||
| CodeBlock of string
|
||||
|
||||
type source_file = source_file_item list
|
||||
|
@ -23,22 +23,52 @@ open Sedlex_menhir
|
||||
module R = Re.Pcre
|
||||
|
||||
let is_code : bool ref = ref false
|
||||
let code_string_acc : string ref = ref ""
|
||||
|
||||
let rec lex_code_as_string lexbuf acc =
|
||||
let buf = lexbuf.stream in
|
||||
match%sedlex buf with
|
||||
| "*/" -> update lexbuf; END_CODE (acc ^ (Sedlexing.Utf8.lexeme buf))
|
||||
| any -> update lexbuf; lex_code_as_string lexbuf (acc ^ (Sedlexing.Utf8.lexeme buf))
|
||||
| _ -> raise_ParseError lexbuf
|
||||
|
||||
let update_and_acc lexbuf =
|
||||
update lexbuf;
|
||||
code_string_acc := !code_string_acc ^ (Sedlexing.Utf8.lexeme lexbuf.stream)
|
||||
|
||||
let rec lex_code lexbuf =
|
||||
let buf = lexbuf.stream in
|
||||
match%sedlex buf with
|
||||
| '\n' -> update lexbuf ; new_line lexbuf; lex_code lexbuf
|
||||
| ' ' | '\t' -> update lexbuf; lex_code lexbuf
|
||||
| "*/" -> update lexbuf; is_code:= false; lex_law lexbuf
|
||||
| "code" -> update lexbuf; CODE
|
||||
| any -> update lexbuf; lex_code lexbuf
|
||||
| '\n' -> update_and_acc lexbuf ; new_line lexbuf; lex_code lexbuf
|
||||
| white_space -> update_and_acc lexbuf; lex_code lexbuf
|
||||
| "*/" ->
|
||||
update lexbuf;
|
||||
is_code:= false;
|
||||
END_CODE !code_string_acc
|
||||
| "choix" -> update_and_acc lexbuf; CHOICE
|
||||
| "situation" -> update_and_acc lexbuf; SITUATION
|
||||
| "source" -> update_and_acc lexbuf; SOURCE
|
||||
| "donnee" -> update_and_acc lexbuf; DATA (* TODO: Find the unicode point of é to enable donnée *)
|
||||
| "de" -> update_and_acc lexbuf; OF
|
||||
| ';' -> update_and_acc lexbuf; SEMICOLON
|
||||
| ':' -> update_and_acc lexbuf; COLON
|
||||
| '.' -> update_and_acc lexbuf; POINT
|
||||
| "--" -> update_and_acc lexbuf; ALT
|
||||
| uppercase , Star (uppercase | lowercase) ->
|
||||
update_and_acc lexbuf; CONSTRUCTOR (Sedlexing.Utf8.lexeme buf)
|
||||
| lowercase , Star (lowercase | '_' | '\'') ->
|
||||
update_and_acc lexbuf; IDENT (Sedlexing.Utf8.lexeme buf)
|
||||
| _ -> raise_ParseError lexbuf
|
||||
|
||||
and lex_law lexbuf =
|
||||
let rec lex_law lexbuf =
|
||||
let buf = lexbuf.stream in
|
||||
match%sedlex buf with
|
||||
| '\n' -> update lexbuf ; new_line lexbuf; lex_law lexbuf
|
||||
| "/*" -> update lexbuf; is_code := true; lex_code lexbuf
|
||||
| "/*" ->
|
||||
update lexbuf;
|
||||
is_code := true;
|
||||
code_string_acc := "";
|
||||
BEGIN_CODE
|
||||
| eof -> update lexbuf ; EOF
|
||||
| "@@", Star white_space, Star (Compl '@'), Star white_space, "@@" ->
|
||||
let extract_code_title =
|
||||
|
@ -24,7 +24,11 @@
|
||||
%token<string> LAW_ARTICLE
|
||||
%token<string> LAW_CODE
|
||||
%token<string> LAW_TEXT
|
||||
%token CODE
|
||||
%token<string> CONSTRUCTOR IDENT
|
||||
%token<string> END_CODE
|
||||
%token BEGIN_CODE CHOICE
|
||||
%token COLON ALT POINT SITUATION SOURCE DATA
|
||||
%token OF SEMICOLON
|
||||
|
||||
%type <Ast.source_file> source_file
|
||||
|
||||
@ -32,11 +36,32 @@
|
||||
|
||||
%%
|
||||
|
||||
choice:
|
||||
| CONSTRUCTOR {}
|
||||
|
||||
choices:
|
||||
| ALT choice choices {}
|
||||
| {}
|
||||
|
||||
situation_type:
|
||||
| CHOICE IDENT {}
|
||||
|
||||
situation:
|
||||
| DATA IDENT OF situation_type {}
|
||||
|
||||
code_item:
|
||||
| CHOICE IDENT COLON choices POINT { }
|
||||
| SITUATION CONSTRUCTOR SOURCE IDENT COLON situation POINT { }
|
||||
|
||||
code:
|
||||
| code_item code {}
|
||||
| {}
|
||||
|
||||
source_file_item:
|
||||
| title = LAW_ARTICLE { LawArticle title }
|
||||
| code = LAW_CODE { LawCode code }
|
||||
| text = LAW_TEXT { LawText text }
|
||||
| CODE { CodeBlock }
|
||||
| BEGIN_CODE code text = END_CODE { CodeBlock text }
|
||||
|
||||
source_file:
|
||||
| i = source_file_item f = source_file { i::f }
|
||||
|
@ -1,6 +1,5 @@
|
||||
@@Code de la sécurité sociale@@
|
||||
|
||||
|
||||
@Article L511-1@ Les prestations familiales comprennent :
|
||||
1°) la prestation d'accueil du jeune enfant ;
|
||||
2°) les allocations familiales ;
|
||||
@ -11,7 +10,20 @@
|
||||
7°) l'allocation de rentrée scolaire ;
|
||||
8°) (Abrogé) ;
|
||||
9°) l'allocation journalière de présence parentale.
|
||||
/*
|
||||
choix prestation:
|
||||
-- PrestationAccueilJeuneEnfant
|
||||
-- AllocationsFamiliales
|
||||
-- ComplementFamilial
|
||||
-- AllocationLogement
|
||||
-- AllocationEducationEnfantHandicape
|
||||
-- AllocationSoutienFamilial
|
||||
-- AllocationRentreeScolaire
|
||||
-- AllocationJournalierePresenceParentale.
|
||||
|
||||
situation ContextePrestationsFamiliales source loi :
|
||||
donnee prestation_courante de choix prestation.
|
||||
*/
|
||||
|
||||
@Article L512-3@ Sous réserve des règles particulières à chaque prestation, ouvre droit aux prestations familiales :
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user