Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of enums when parsing #7

Open
mor1 opened this issue Sep 15, 2013 · 6 comments
Open

use of enums when parsing #7

mor1 opened this issue Sep 15, 2013 · 6 comments

Comments

@mor1
Copy link

mor1 commented Sep 15, 2013

it would be nice if, given an enum of the form

cenum foo {
  bar1 = v1;
  bar2 = v2
} as enumtype

...rather than foo option the parser return something like foo orError where orError would be defined something like

type 'a orError = 
  | Ok of 'a
  | Err of enumtype

the use case is when parsing data -- it's nice to lift to a proper type as early as possible but retain the ability to output some sensible debug info when there's a parse error.

@avsm
Copy link
Member

avsm commented Sep 15, 2013

Agreed...option returns on error should basically be considered harmful. Also Or_error.t in Core is a good example of what we should aim for.

On 15 Sep 2013, at 15:12, Richard Mortier [email protected] wrote:

it would be nice if, given an enum of the form

cenum foo {
bar1 = v1;
bar2 = v2
} as enumtype
...rather than foo option the parser return something like foo orError where orError would be defined something like

type 'a orError =
| Ok of 'a
| Err of enumtype
the use case is when parsing data -- it's nice to lift to a proper type as early as possible but retain the ability to output some sensible debug info when there's a parse error.


Reply to this email directly or view it on GitHub.

@avsm
Copy link
Member

avsm commented Oct 12, 2013

I guess it's ok to break compatibility here, since we're still < 1.0.0.

@avsm
Copy link
Member

avsm commented Oct 13, 2013

I took a look at this, but it's not clear to me what enumType is here. Are you saying that you want to gather all the possible enumerations that have been defined, and to say which one raised an error? That should happen in the parser.

@mor1
Copy link
Author

mor1 commented Oct 13, 2013

no, i'm saying that (following the example above) if you define an enum foo of type enumtype (uint8_t or whatever), then when the int_to_foo function would more usefully return foo orError rather than foo option where 'a orError is defined as above. ie., when the autogenerated function that converts from the raw input to the typed value is presented with a value outside the range of the enumeration, it's useful to know what that value is, not just that it was outside the range.

(and not force the error to be handled at that point but permit it to bubble up.)

@mor1
Copy link
Author

mor1 commented Oct 13, 2013

ps. i can try to have a go at this this afternoon perhaps. i'm bored of proposalising at the moment. and it'll be an excuse to fail to understand camlp4 too.

@avsm
Copy link
Member

avsm commented Dec 5, 2013

Not going to do this for 1.0 since we have existing users. We can create a 1.2.x with interface-breaking changes.

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

No branches or pull requests

2 participants