haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
298 stars 82 forks source link

Alex assumes tab to be size 8 #57

Closed chamini2 closed 9 years ago

chamini2 commented 9 years ago

Alex assumes that tab size is 8, as an example, gcc takes tabs as 1 in character size.

Using tab size 8 also makes the errors like:

program:2:9

To give addresses that are not real.

I propose we make the size of a tab to be 1, it's just changing this line.

simonmar commented 9 years ago

Tabs are size 8 in Haskell, see the Haskell report.

osa1 commented 9 years ago

How is this related with tab sizes in Haskell report? \t is one character but Alex behaves as if it's 8 characters.

chamini2 commented 9 years ago

Maybe a flag for --tab-size=NUMBER that defaults to 8 can be added. I guess that would be done by adding a State Monad in the ParseMonad module.

simonmar commented 9 years ago

Alex adopts the same convention for .x files as for Haskell, which is that tab stops are 8 columns apart. If you don't like this, you don't have to use tabs (in fact, it's better just not to use tabs anyway).

Now, in the generated lexer (rather than Alex itself) it is arguably wrong to fix the same convention: https://github.com/simonmar/alex/blob/master/templates/wrappers.hs#L151

By all means submit a pull request to change this, I suppose we could have a command line flag, and plumb the tab width through to wrappers.hs using CPP.

chamini2 commented 9 years ago

Oh... I see my mistake. I thought the line in the ParseMonad module was for the generated lexer. That is what I meant to link. Thank you for clearing that up!

Now, in the line in the wrapper file that you linked, that one should follow the flag's instruction. I'll see to make a pull request with that change!