FsLexYacc icon indicating copy to clipboard operation
FsLexYacc copied to clipboard

Generating Lexer/Parser file in a specific encoding

Open lkluc opened this issue 8 months ago • 3 comments

I am migrating a project to a CI/CD pipeline for which there is a step which ensures that all .fs files are UTF-8 with BOM.

I have some unit tests which are generated by FsLexYacc and are not adhering to this CI/CD specification.

I would need to have FsLexYacc generate files enforcing a specific encoding, which is, in my case UTF-8 with BOM.

I tried to look in the available command line options of the generators, and it seems the options are regarding the input, not the output.

Could we add an option to specify an output encoding (or code page if we align with the current input options) ?

Thanks !

lkluc avatar May 16 '25 13:05 lkluc

This is a great suggestion - would you be interested in implementing it yourself? It looks like it should be a matter of

  • adding a new CLI option (maybe --output-codepage) similar to the existing one here and here and adding matching mutable defaults for those options
  • adding new configuration to the Writer types for fslex and fsyacc to actually use those passed-in values

baronfel avatar May 16 '25 13:05 baronfel

Hello @baronfel , good news, I followed your advice and made the fix.

I end up implementing it with a --out-bom boolean command line switch available on both programs, fslex and flyacc, because specifying only the codepage (number 65001 for in this case, UTF-8) would not have enable the user to specify with or without BOM, I'm not an I18n expert but it seems the codepage number are being the same in both cases.

So I kept UTF-8 encoding only for now, no other weird ISO-something encoding.

I have created a feature/output-encoding.0 branch on my computer, however when I tried to push it, it seems I'm required to have some permissions granted to me? Nor is it some configuration required on my side?

remote: Permission to fsprojects/FsLexYacc.git denied to lkluc.
fatal: unable to access 'https://github.com/fsprojects/FsLexYacc.git/': The requested URL returned error: 403

Thanks !

lkluc avatar May 23 '25 01:05 lkluc

Good to hear! You'll have to make a fork of this repository, then push your branch to your fork and make a pull request here.

baronfel avatar May 23 '25 01:05 baronfel