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

Cannot use a | at the beginning of an or-pattern #7296

Closed
vicuna opened this issue Jul 20, 2016 · 5 comments
Closed

Cannot use a | at the beginning of an or-pattern #7296

vicuna opened this issue Jul 20, 2016 · 5 comments

Comments

@vicuna
Copy link

vicuna commented Jul 20, 2016

Original bug ID: 7296
Reporter: @johnwhitington
Status: acknowledged (set by @gasche on 2016-07-20T14:50:59Z)
Resolution: open
Priority: low
Severity: feature
Version: 4.03.0
Target version: later
Category: lexing and parsing
Related to: #7267
Monitored by: @gasche

Bug description

The OCaml style guide prefers

match x with
| 1 ->
| 2 ->

However, one cannot use the initial | in an or-pattern:

# match 1 with (| 1 | 2 | 3) as y -> y;;
Error: Syntax error: operator expected.

I've never needed this before, but I tried to use it in real code today, to line up columns:

| Pdfgenlex.LexName
    (| "PW" | "PH" | "CW" | "CH" | "PMINX" | "PMINY" | "PMAXX" | "PMAXY"
     | "CMINX" | "CMINY" | "CMAXX" | "CMAXY") as page_characteristic ->
       parse_units pdf page page_characteristic
@vicuna
Copy link
Author

vicuna commented Jul 20, 2016

Comment author: @alainfrisch

Being able to use for the first clause of a match/function is nice, but the equivalent for or-pattern seems much less useful. I don't think this deserves reserving the banana tokens (|...|) that will certainly find some use in OCaml at some point.

@vicuna
Copy link
Author

vicuna commented Jul 27, 2016

Comment author: @johnwhitington

Then perhaps require a space before the |. This sort of disambiguation already occurs with polymorphic variant type declarations:

# type 'a vlist = [`Nil | `Cons of 'a * 'a vlist];;
type 'a vlist = [ `Cons of 'a * 'a vlist | `Nil ]

# type 'a vlist = [|`Nil | `Cons of 'a * 'a vlist];;
Error: Syntax error

# type 'a vlist = [ | `Nil | `Cons of 'a * 'a vlist];;
type 'a vlist = [ `Cons of 'a * 'a vlist | `Nil ]

@vicuna
Copy link
Author

vicuna commented Jul 27, 2016

Comment author: @gasche

I agree with the proposed change but I would like to get my work on a Menhir parser

#292

done before playing with changes to the grammar, as Menhir is a much more convenient tool to factorize a grammar, explain conflicts, etc.

@vicuna
Copy link
Author

vicuna commented Feb 18, 2017

Comment author: @xavierleroy

Indeed, #7267 wants to use (| for another purpose...

I'm not a big fan of the proposed extension.

@github-actions
Copy link

github-actions bot commented May 9, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

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

1 participant