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

Operator's rule makes its parsing disjointed with comment #627

Open
trdthg opened this issue Jul 9, 2024 · 1 comment · May be fixed by #628
Open

Operator's rule makes its parsing disjointed with comment #627

trdthg opened this issue Jul 9, 2024 · 1 comment · May be fixed by #628

Comments

@trdthg
Copy link
Contributor

trdthg commented Jul 9, 2024

I find it strange how sail currently handles operator + comment forms like ==/**/ or =/**/.

It seems the issue is caused by the operatorn rule in lexel.mll. To debug this, I added some print statements inside:

  | operator as op { 
      Printf.printf "%s\n" op;
      OpId op }

When I format the following code:

function f () = {
    if a ==/**/ 1 then { 1 };
    
	let b =/**/ 1
}

Here is the output:

$ ./sail -fmt ./test/format/demo.sail 
Syntax error:
./test/format/demo.sail:3.10-10:
3 |    let b =/**/ 1
  |          ^
  | current token: =/**/
==/**/
=/**/

Comments are treated as part of the operator (although they are valid operators in the documentation?).

if this behavior is valid, then we should fix the error?
if not, is there a way to separate the comment?
any advice?

@Alasdair
Copy link
Collaborator

Alasdair commented Jul 9, 2024

Hmm, well spotted! The lexer forbids operators starting with either // or /*, but those characters are generally allowed within operators. It might be better if we were to forbid // and /* anywhere within an operator, assuming there is a nice way to do that in ocamllex

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 a pull request may close this issue.

2 participants