Skip to content

Conversation

@Smaug123
Copy link
Owner

No description provided.

@Smaug123
Copy link
Owner Author

Smaug123 commented Apr 13, 2025

OK. Strategy: an in-progress universe of types. The in-progress of a record type is that same type but where we add options to everything primitive that's not already optional, and replace nonprimitives with their in-progress type. The in-progress of a DU (where every case must contain data) is the list of all DU cases, where all contents are replaced by their in-progress type. To finalise the in-progress DU, we finalise every case and assert that exactly one finalised successfully. To finalise the in-progress record, we finalise its fields. The finalisation of an in-progress primitive is "if it was non-optional, Option.get".

The parser consumes one argument after another in a loop:

  • An in-progress primitive type consumes an argument by parsing it to the primitive type. (If that in-progress primitive type has already consumed an argument and can't accept multiple args, the parse fails due to duplicated args.)
  • An in-progress DU consumes an argument by having every case consume that argument. (This may cause cases to become nonviable if they can't accept the argument.)
  • An in-progress record consumes an argument by presenting it to each of its fields in turn, asserting that exactly one field consumes the argument. (In principle one could imagine a parser where the same arg could be accepted by multiple different fields, but this would lead to some valid DU cases being impossible to access by parsing args - type Foo = | Case1 of --thing | Case2 of --blah and type Args = { Thing : bool ; Whatnot : Foo } has the Case1 case inaccessible - so we ban this.)

Positionals are gathered at the top level, not by an individual parser, and they are injected on finalisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants