Better printing, tests, fix parser ommission

This commit is contained in:
Denis Merigoux 2022-02-04 15:10:47 +01:00
parent d8c120bf97
commit 11d4a34783
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
7 changed files with 52 additions and 20 deletions

View File

@ -78,11 +78,20 @@ let rec format_typ (ctx : Ast.decl_ctx) (fmt : Format.formatter) (typ : typ Pos.
~pp_sep:(fun fmt () -> Format.fprintf fmt "@ *@ ")
(fun fmt t -> Format.fprintf fmt "%a" format_typ t))
ts
| TTuple (args, Some s) ->
Format.fprintf fmt "%a {%a}" Ast.StructName.format_t s
(Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "@ ;@ ") format_typ)
args
| TEnum (_, e) -> Format.fprintf fmt "%a" Ast.EnumName.format_t e
| TTuple (_args, Some s) ->
Format.fprintf fmt "%a{%a}" Ast.StructName.format_t s
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@ ;@ ")
(fun fmt (field, typ) ->
Format.fprintf fmt "%a: %a" StructFieldName.format_t field format_typ typ))
(StructMap.find s ctx.ctx_structs)
| TEnum (_, e) ->
Format.fprintf fmt "%a[%a]" Ast.EnumName.format_t e
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@ |@ ")
(fun fmt (case, typ) ->
Format.fprintf fmt "%a: %a" EnumConstructor.format_t case format_typ typ))
(EnumMap.find e ctx.ctx_enums)
| TArrow (t1, t2) ->
Format.fprintf fmt "@[<hov 2>%a %a@ %a@]" format_typ_with_parens t1 format_punctuation ""
format_typ t2

View File

@ -361,6 +361,15 @@ let rec lex_code (lexbuf : lexbuf) : token =
| MR_CONTEXT ->
L.update_acc lexbuf;
CONTEXT
| MR_INPUT ->
L.update_acc lexbuf;
INPUT
| MR_OUTPUT ->
L.update_acc lexbuf;
OUTPUT
| MR_INTERNAL ->
L.update_acc lexbuf;
INTERNAL
| MR_DECREASING ->
L.update_acc lexbuf;
DECREASING

View File

@ -500,7 +500,6 @@ scope_decl_item_attribute:
| INPUT { Input, Pos.from_lpos $sloc }
| OUTPUT { Output, Pos.from_lpos $sloc }
| INTERNAL { Internal, Pos.from_lpos $sloc }
| { Context, Pos.from_lpos $sloc }
scope_decl_item:
| attr = scope_decl_item_attribute i = ident CONTENT t = typ func_typ = option(struct_scope_func) { (ContextData ({

View File

@ -1,8 +1,9 @@
let
TestBool_6 :
TestBool_in {unit → bool ; unit → integer} → TestBool_out {bool ;
integer} =
λ (TestBool_in_7: TestBool_in {unit → bool ; unit → integer}) →
TestBool_in{foo_in: unit → bool ; bar_in: unit → integer} →
TestBool_out{foo_out: bool ; bar_out: integer} =
λ (TestBool_in_7: TestBool_in{foo_in: unit → bool ;
bar_in: unit → integer}) →
let foo_8 : unit → bool = TestBool_in_7."foo_in"
in
let bar_9 : unit → integer = TestBool_in_7."bar_in"

View File

@ -2,17 +2,17 @@
```catala
declaration scope Callee:
context input content integer depends on boolean
context output content integer
context input_v content integer depends on boolean
context output_v content integer
declaration scope Caller:
context sub scope Callee
context y content integer
scope Callee:
definition input of b equals if b then 0 else 1
definition output equals input of true + 1
definition input_v of b equals if b then 0 else 1
definition output_v equals input_v of true + 1
scope Caller:
definition y equals sub.output
```
definition y equals sub.output_v
```

View File

@ -3,8 +3,8 @@
```catala
declaration scope Callee:
context function condition depends on integer
context input content integer
context output condition
context input_v content integer
context output_v condition
declaration scope Caller:
context callee scope Callee
@ -12,9 +12,9 @@ declaration scope Caller:
scope Callee:
rule function of x under condition x = 0 consequence fulfilled
definition output equals function of input
definition output_v equals function of input_v
scope Caller:
definition callee.input equals 0
assertion callee.output
definition callee.input_v equals 0
assertion callee.output_v
```

View File

@ -0,0 +1,14 @@
## Test
```catala
declaration scope A:
context a content integer
input b content integer
output c content integer
internal d content integer
scope A:
definition a equals 0
definition c equals b + d
definition d equals 1 + a
```