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

Unexpected formatting while saving an ocamllex file #1487

Open
francoisthire opened this issue May 30, 2024 · 1 comment
Open

Unexpected formatting while saving an ocamllex file #1487

francoisthire opened this issue May 30, 2024 · 1 comment

Comments

@francoisthire
Copy link

Using extension v1.18.1 with OCaml version 5.2.0 (and 4.14.2), I have an unexpected behaviour when saving an ocamllex file (ending in .mll). The extension formats the file in a way which is no longer valid but also not readable.

My example is the following one:

{
  open Parser

  exception Error of string

  let fail explanation = raise (Error explanation)
}

let space = [' ' '\t' '\r']+

let ident = ['a'-'z''A'-'Z''0'-'9''_']+


rule token =
  parse
  | space        { token lexbuf }
  | '\n'         { Lexing.new_line lexbuf; token lexbuf }
  | "Type"       { TYPE }  
  | ':'          { COLON }
  | '.'          { DOT }
  | eof          { EOF }
  | ident as id  { ID id }  
  | _ as c { fail (Printf.sprintf "Unexpected character: %C (codepoint: %d)" c (Char.code c)) }

and on save, the extension produces this file:

{

open

Parser

exception

Error

of

string

let

fail

explanation

=

raise

(Error explanation)

}

let

space

=

['

'

'\t'

'\r']+

let

ident

=

['a'-'z''A'-'Z''0'-'9''_']+

rule

token

=

parse

|

space

{

token

lexbuf

}

|

'\n'

{

Lexing.new_line

lexbuf

; token lexbuf }

|

"Type"

{

TYPE

}

|

':'

{

COLON

}

|

'.'

{

DOT

}

|

eof

{

EOF

}

|

ident

as

id

{

ID

id

}

|

_

as

c

{

fail

(Printf.sprintf
 "Unexpected character: %C (codepoint: %d)"
 c
 (Char.code c))

}

Deactivating the extension enables to not observe this behaviour.

@Kakadu
Copy link

Kakadu commented Jul 28, 2024

I think that disabling ocamlformat for these kind of files is only approach. Good luck!

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

No branches or pull requests

2 participants