Commit Graph

232 Commits

Author SHA1 Message Date
Louis Gesbert
22045a2f06 Tests and fixes on structures across modules 2023-10-03 18:43:14 +02:00
Louis Gesbert
a79acd1fa8 Reformat 2023-09-27 13:19:04 +02:00
Louis Gesbert
dbe0990163 Rework module includes CLI in Catala
Rather than require all files to be listed on the command-line (and having to
check consistency with `> Using` directives), the main catala CLI is now a bit
more clever.

⇒ There is a new assumption that a module name definition must match the file
name (up to case and extension) — with appropriate error handling to enforce it.

In exchange, `> Using` directives are now used to more transparently lookup the
appropriate `.catala_*` interfaces and the compiled artifacts for the used modules (handling transitive dependencies), with just standard `-I` flags for when they need to be looked up in different places.
2023-09-27 13:14:40 +02:00
Louis Gesbert
4bce4e6322 Reformat 2023-09-27 13:14:38 +02:00
Louis Gesbert
f162f6e9bd Improve handling of module name definitions
and add some sanity-checks for consistency of used modules w.r.t. actually
loaded modules.
2023-09-27 13:14:03 +02:00
Louis Gesbert
f8e3774662 Fix lookup of built modules in Catala 2023-09-27 13:08:15 +02:00
Louis Gesbert
bf048f0a74 Add a lightweight lexer for dependency extraction in Clerk
The base is there but not fully used yet in Clerk
2023-09-27 13:08:15 +02:00
Louis Gesbert
9aed2c7479 support for parsing Module directives 2023-09-27 13:08:11 +02:00
Denis Merigoux
9cecf5587a
Register surface syntax languge in program troughout the compilation chain 2023-09-22 18:05:26 +02:00
Louis Gesbert
4910158aea Reformat 2023-09-01 16:24:27 +02:00
Louis Gesbert
fe2c66af12 Select colors for Uids upon instanciation
This way different Uid kinds will have a consistent color across error messages,
AST dumps, etc.
2023-09-01 14:41:56 +02:00
Louis Gesbert
544e18e110 Fixes related to environments and lookups 2023-08-31 18:31:48 +02:00
Louis Gesbert
ff60aee5ef Improve module error messages 2023-08-31 18:31:48 +02:00
Louis Gesbert
e75ea3da07 Cleanup tmp debug code 2023-08-31 18:31:48 +02:00
Louis Gesbert
8e33355ead Reformat 2023-08-31 18:31:48 +02:00
Louis Gesbert
7db63e5f78 Simplification: store paths in Uids
rather than scattered in structures

The context is still hierarchical for defs though, so one needs to retrieve the
path to lookup in the correct context for info. Exceptions are enums and struct
defs, which are re-exposed at toplevel.
2023-08-31 18:31:48 +02:00
Louis Gesbert
17172cf47d Some fixes & cleanup after early review 2023-08-31 17:55:36 +02:00
Louis Gesbert
72882f82df Reformat 2023-08-31 17:55:36 +02:00
Louis Gesbert
c58e76f4e5 Gather the maps for subscope vars to the top level
(they use UIDs so this doesn't jeopardize proper name resolution ; and it allows
resolution of subscope calls without further code modifications)
2023-08-31 17:55:36 +02:00
Louis Gesbert
bcde10242f Specialise the Map.Not_found exception raised by Map.find
... and add a custom printer

Since this is a very common bug, this patch should gain us a lot of time when
debugging uncaught Not_found errors, because the element not found can now be
printed straight away without the need for further debugging.

The small cost is that one should remember to catch the correct specialised
`Foo.Map.Not_found _` exception rather than the standard `Not_found` (which
would type-check but not catch the exception). Using `find_opt` should be
preferred anyway.

Note that the other functions from the module `Map` that raise `Not_found` are
not affected ; these functions are `choose`, `min/max_binding`,
`find_first/last` which either take a predicate or fail on the empty map, so it
wouldn't make sense for them (and we probably don't use them much).
2023-08-31 17:55:36 +02:00
Louis Gesbert
9bac045d03 Implement module lookups for scopes, structs, and enums 2023-08-31 17:54:39 +02:00
Aminata-Dev
94f8eac858 Better indications for the user :
- We're able to say from the parser what the user could have written. It may not be complete due to the acceptable function of Menhir : it is only an indication given to the user (and not intended to be an adaptive documentation)
- .mli file added : module interface for suggestions
- Add a test that provides a typographical or a logical error.
- Documentation and type / name changes for suggestions
2023-07-12 16:32:55 +02:00
Louis Gesbert
c96c6e187f Re-implement the GNU message output format 2023-07-12 13:57:58 +02:00
Aminata-Dev
17469565ec Improve the implementation of suggestions
- suggestions.ml : improve details + algorithm implementation (see @Altgr reviews) + comments
- suggestions implementation : since we want to keep the same structure to display suggestion messages, Suggestion is no longer a formatted string but a string list. The goal is to have a similar formatted string for each suggestion, no matter what the error message is.
--> This involves changes to suggestions.mli, compiler/desugared/from_surface.ml (most important one) and compiler/surface/parser_driver.ml
2023-07-12 11:55:11 +02:00
Aminata-Dev
b087ca4f47 Improve suggestions
- Improved implementation of suggestions (suggestion_minimum_levenshtein_distance_association > suggestions.ml)
- Magnifying glass emoji added for suggestions
- Improve display by...
	- Fixing "Pos.ml" (pretty-printing box not closed)
	- Remove unnecessary spaces
- compiler/surface/parserdriver.ml
	- Optionnal suggestions added when raising a parser error
	- Function "levenshtein_distance" removed and replaced by "Suggestions.levenshtein_distance"
- Tests updated (mostly line breaks and spacing changes)
- Variable names renamed for greater clarity
- (Based on commit 0813f5c36e)
2023-07-12 11:55:11 +02:00
Aminata-Dev
75b6251b43 Match the compiler code to the new type of error message content 2023-07-12 11:55:11 +02:00
Denis Merigoux
4cdd2fce0f With @aminata-dev, implemented first error message improvement! 2023-07-12 11:55:11 +02:00
Aminata-Dev
0360568e8e actual changes 2023-07-12 11:55:11 +02:00
Louis Gesbert
f2fc79f640 Add some helper functions in a wrapper Map module
and use them throughout. No more `List.map fst (Map.bindings m)` !

Also adds some facilities for direct formatting without going through a list.
2023-07-12 11:51:15 +02:00
Louis Gesbert
4ae949f7f8 Fix formatting of exception trees 2023-07-07 14:56:54 +02:00
Louis Gesbert
237dca2e75 Some commented code cleanup and clarifications 2023-06-19 16:36:09 +02:00
Louis Gesbert
da59076223 Add a command-line option ('--use') for module linking 2023-06-15 17:58:46 +02:00
Louis Gesbert
ec97c386c3 Reformat + regen 2023-06-15 17:57:01 +02:00
Louis Gesbert
26c75af2ae Allow declaration of toplevel values without definition 2023-06-15 17:57:01 +02:00
Louis Gesbert
e224e87f71 Wip support for modules
(first working dynload test with compilation done by manual calls to ocaml)

A few pieces of the puzzle:

* Loading of interfaces only from Catala files
* Registration of toplevel values in modules compiled to OCaml, to allow access
  using dynlink
* Shady conversion from OCaml runtime values to/from Catala expressions, to
  allow interop (ffi) of compiled modules and the interpreter
2023-06-15 17:56:57 +02:00
Louis Gesbert
2b7beeefb2 Rename 'IdentName' to 'Ident' 2023-06-15 17:55:49 +02:00
Denis Merigoux
385e19b9e1 Formatting 2023-06-15 10:51:31 +02:00
Aminata-Dev
10d147a8b1 Messages renamed to Message (lighter syntax) 2023-06-13 11:50:56 +02:00
Louis Gesbert
16c93fbb0c Reformat 2023-06-08 12:14:11 +02:00
Louis Gesbert
deaf40761e Use ocolor instead of ANSITerminal 2023-06-08 12:11:55 +02:00
Louis Gesbert
7aa7bfb8fa
Fix most doc errors (#471) 2023-06-05 10:51:59 +02:00
Denis Merigoux
d1a836c646 Removing less precise message 2023-06-03 18:04:41 +02:00
Denis Merigoux
09bcefbcc1 Update tests 2023-06-03 18:02:57 +02:00
Denis Merigoux
79801292e9
Fix most doc errors 2023-06-02 17:17:45 +02:00
Denis Merigoux
4e6efe08da All renamings done, on with actual refactor 2023-06-02 10:50:33 +02:00
Denis Merigoux
0faa97b8fc Abstract messages interface 2023-06-02 10:50:29 +02:00
Denis Merigoux
8987d358e7
Implement the rest 2023-05-26 16:54:52 +02:00
Denis Merigoux
1f23f701bc
Move types 2023-05-26 16:03:26 +02:00
Louis Gesbert
209be6b758 Improve integration of marks into the main AST
Two interdependent changes here:
1. Enforce all instances of Shared_ast.gexpr to use the generic type for marks.
   This makes the interfaces a tad simpler to manipulate: you now write
   `('a, 'm) gexpr` rather than `('a, 'm mark) gexpr`.
2. Define a polymorphic `Custom` mark case for use by pass-specific annotations.
   And leverage this in the typing module
2023-05-17 17:37:00 +02:00
Louis Gesbert
fc531777c0 Rework and normalise the Marked interface
The module is renamed to `Mark`, and functions renamed to avoid redundancy:

`Marked.mark` is now `Mark.add`
`Marked.unmark` is now `Mark.remove`
`Marked.map_under_mark` is now simply `Mark.map`
etc.

`Marked.same_mark_as` is replaced by `Mark.copy`, but with the arguments
swapped (which seemed more convenient throughout)

Since a type `Mark.t` would indicate a mark, and to avoid confusion, the type
`Marked.t` is renamed to `Mark.ed` as a shorthand for `Mark.marked` ; this part
can easily be removed if that's too much quirkiness.
2023-05-17 17:37:00 +02:00
Denis Merigoux
a5d4f54115
Push some fixes suggested by @altgr 2023-05-04 18:28:24 +02:00
Denis Merigoux
8d7666ee92
Interleave assertions with rules from desugared to scopelang 2023-04-28 14:15:43 +02:00
Denis Merigoux
a954942fd9
Bug in the law found with proof mode? 2023-04-27 16:58:40 +02:00
Denis Merigoux
7788bf9e73
Error message when two same states 2023-04-27 15:37:11 +02:00
Denis Merigoux
9b056f3ca1
Update assets and fix errors after rebase 2023-04-27 12:18:50 +02:00
Denis Merigoux
e7f56b4310
Removed useless variable 2023-04-27 12:13:19 +02:00
Denis Merigoux
19b33eaa96
Add lint and fix bugs related 2023-04-27 12:09:22 +02:00
Denis Merigoux
0266252854
Refactoring for cleaner exception graph building 2023-04-18 11:06:58 +02:00
Denis Merigoux
57da622567
Refactoring changes after @altgr's suggestions 2023-04-18 10:31:44 +02:00
Denis Merigoux
39f1704d76
Last fixes 2023-04-18 09:59:24 +02:00
Denis Merigoux
ecccb5fb91
Last changes 2023-04-18 09:59:24 +02:00
Denis Merigoux
6479c3c10b
Print exception tree 2023-04-18 09:59:24 +02:00
Denis Merigoux
2afb6fc20c
I/O plumbing necessary for this feature, missing main implem 2023-04-18 09:59:24 +02:00
Denis Merigoux
38b0041bb8
Add common linting passes to Catala (#438) 2023-04-03 14:01:02 +02:00
Denis Merigoux
d147238088
Apply suggestions by @altgr 2023-04-03 13:42:14 +02:00
Denis Merigoux
e80143b3ca
Last linting pass and update tests 2023-03-31 17:56:45 +02:00
Denis Merigoux
3d86a12261
Update error messages 2023-03-31 14:01:04 +02:00
Denis Merigoux
a7ee7074f9
Improve linting 2023-03-31 13:50:02 +02:00
Denis Merigoux
565aa23b8f
Implemented some lints 2023-03-31 11:47:44 +02:00
Louis Gesbert
1208744c6b EmptyError is no longer a literal
it's much simpler to handle it as an AST node, as that makes the literal
identical across all AST passes.
2023-03-30 18:54:50 +02:00
Denis Merigoux
3c364aa1fa
Progress on linting, bugguy unused field detection 2023-03-30 18:52:29 +02:00
Denis Merigoux
9d64150a47
Add linting 2023-03-30 16:09:03 +02:00
Denis Merigoux
aa8ab3be3d
Merge branch 'master' into c_backend 2023-03-21 12:14:10 +01:00
Raphaël Monat
d5cd5b206a Show conflicting date rounding mode declarations when they happen 2023-03-16 18:51:01 +01:00
Raphaël Monat
8981b21edb Add test for date rounding option conflict 2023-03-16 17:20:14 +01:00
Raphaël Monat
51ea9d8cff Format code 2023-03-16 17:20:14 +01:00
Raphaël Monat
d3c27799de Raise exception when more than one rounding mode option has been specified 2023-03-16 17:20:13 +01:00
Raphaël Monat
7021c41f93 Add date rounding option within scopes 2023-03-16 16:55:55 +01:00
Louis Gesbert
6388a4b79f Improved some error messages (cyclic defs, def positions) 2023-03-08 15:27:48 +01:00
Denis Merigoux
1fe3987168
Formatting 2023-03-05 12:10:04 +01:00
Louis Gesbert
5398b1037f Fix ill-funded order function on desugared vars 2023-03-03 19:22:17 +01:00
Louis Gesbert
97e0cfca6f Improvements on function arguments refactoring
- simplify naming in the french law examples
- make messages yet more precise on function arguments mismatch
2023-03-02 19:11:21 +01:00
Louis Gesbert
3766e9db2c Fix function argument naming consistency in the examples 2023-02-28 16:17:19 +01:00
Louis Gesbert
fc5910e093 Fix multi-argument scopedefs, improve error message positions
This adds a few positions to the parser, and tweaks some others, vastly
improving the reporting of some errors (inconsistent functions definitions, but
also exceptions cycles, etc.)
2023-02-28 15:53:50 +01:00
Louis Gesbert
2c97d5de14 Enforce consistency of function arguments naming 2023-02-28 15:53:50 +01:00
Louis Gesbert
8200457e43 Syntax change: require declaration of function argument names 2023-02-28 15:53:50 +01:00
adelaett
4f029db47b explicitly don't accept multiple arguments from surface to desugared 2023-02-22 12:21:55 +01:00
adelaett
9f31715a47 style 2023-02-22 12:11:42 +01:00
adelaett
99d82bc33e Fix toplevel type definition (if arg_types is [], then use a different way) 2023-02-21 14:17:24 +01:00
adelaett
e519b7f146 until desugared 2023-02-20 17:21:44 +01:00
Louis Gesbert
72cf477dd9 Toplevel definitions: fixes following review
Thanks @denismerigoux!
2023-02-15 12:40:15 +01:00
Louis Gesbert
c3af0b4097 Toplevel definitions: branch cleanup
- fix remaining warnings (mostly unused arguments)
- renamings throughout for consistency and clarity
2023-02-13 18:02:09 +01:00
Louis Gesbert
6f1ac5837d Add syntax for calling multi-argument functions
* temporary and undocumented while waiting for discussion an approval
* previous patches already allowed definition (at toplevel) but there was no
syntax for calls
* no syntax for multi-args _local_ functions yet
2023-02-13 11:44:32 +01:00
Louis Gesbert
d66cd1e29c Toplevel defs: tests & fixes 2023-02-13 11:44:32 +01:00
Louis Gesbert
9b0c7583ec Add top-level definitions
Only handled until before scalc at the moment.
2023-02-13 11:43:49 +01:00
Louis Gesbert
3f487a16ed WIP: handle toplevel definitions at the parser level 2023-02-13 10:51:42 +01:00
Denis Merigoux
d7df6b3e80
Typing now takes into account [TAny] in structs/enums 2023-02-08 16:00:53 +01:00
Denis Merigoux
c78a004b53
Leave everything unresolved for now 2023-02-08 16:00:53 +01:00
Louis Gesbert
19033669f5 Add support for paths in the parser
Using them will lead to "not supported yet" errors soon after, but it's a start
to get to handling separate modules.

The idea is that `foo` can now also be `Bar.foo`, `Bar.Baz.foo`, `foo.Struc.fld`
can be `foo.Bar.Baz.Struc.fld`, etc.
The next steps are to enable the lookups to handle this paths, and to provide
ways to load the external modules to feed these lookups.
2023-01-16 12:09:23 +01:00
Louis Gesbert
2003566867 Force parens in compound logic formulas
Closes #373

This forbids expressions such as `a and b or c`, avoiding the need to set an
implicit priority between `and`, `or` and `xor`, which I find error-prone.

Instead, when that appears, a message asking for explicit parentheses will be
shown to the user.

Implementation note: since that would be extremely tedious to do in the parser
directly, the parser is set to allow right-associativity without discrimination
for the logical operators, and the check is done during desugaring. This
required to explicit parentheses in the surface AST to discriminate the case
where the priority was explicit.
2023-01-04 10:46:14 +01:00