Commit Graph

6 Commits (master)

Author SHA1 Message Date
Drup 9c8b63f4ce Annotated Asttypes.constant's string with content location. 2019-11-13 16:08:40 +01:00
Gabriel Scherer 8b59222d01 typedtree: make the Tpat_value argument a private synonym
This prevents users from mistakenly constructing a Tpat_value pattern
using the natural implementation

    { pat with pat_desc = Tpat_value pat }

which breaks the attributes-placement invariant (the attributes are
duplicated with this version, instead of being placed only on the
value pattern, with empty attributes on the computation pattern).

(Suggestion from Jacques Garrigue.)
2019-10-31 13:29:28 +01:00
Gabriel Scherer 312253ce82 split patterns into "value patterns" and "computation patterns"
Value patterns match on a value (the result of computation), while
computation patterns handle the effects (hint hint) of
a computation. The only forms of computation patterns in OCaml today
are value patterns and exception patterns (exception p).

The sub-pattern `p` of the `lazy p` construction should be
a computation pattern, rather than a value pattern. This pull-request
does not make this change.

Most of the changes in this PR are boilerplate -- it really is a lot
of work now to add a new syntactic category to the typed-tree
syntax. This boilerplate is fairly automatic and should be easy to
review.

There is a subtle part to the patch, though: the implementation of the
pattern type-checking. It now has to reconstruct the value/computation
distinction (absent from the parse-tree), and return values from two
different types. Instead of splitting the type-checker in several
functions (which risked code duplications), I choose to use a GADT to
have the same [type_pat] function return two different types depending
on the caller. This is the least invasive way to adapt this part of
the codebase, whose inherent complexity is so large (unfortunately)
that adding a GADT to the mix barely makes a difference.
2019-10-31 13:29:16 +01:00
Thomas Refis 369ea5f432 allow exceptions under or-patterns 2018-07-16 10:41:55 +01:00
Thomas Refis 92deef5eba printpat: take formatter 2017-12-04 12:11:21 +00:00
Thomas Refis 60c5f6fe91 parmatch: split pretty printing out into Printpat 2017-12-04 12:11:21 +00:00