Erlang Mailing Lists

Author Message

<  Erlang bugs mailing list  ~  erl_scan counts white space badly

uwiger
Posted: Tue Jan 12, 2010 11:06 pm Reply with quote
User Joined: 03 Jul 2006 Posts: 604 Location: Sweden
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I tried the column tracking functionality of erl_scan:

8> {ok,Fd} = file:open("parse_trans.erl",[read]).
{ok,<0.48.0>}
9> {ok,Epp} = epp:open(parse_trans,Fd,{1,1},["."],[]).
{ok,<0.50.0>}
10> epp:parse_erl_form(Epp).
{ok,{attribute,{1,1},file,{"parse_trans",{1,1}}}}
...
18> epp:parse_erl_form(Epp).
{ok,{attribute,{78,2},
record,
{context,[{record_field,{78,19},{atom,{78,19},module}},
{record_field,{79,5},{atom,{79,5},function}},
{record_field,{80,5},{atom,{80,5},arity}},
{record_field,{81,19},{atom,{81,19},file}},
{record_field,{82,19},{atom,{82,19},options}}]}}}


The original source code wasn't misaligned, but the indentation
used a mix of tabs and spaces. erl_scan treats all kinds of
white space as one space.

I think it would be reasonable to at the very least increment by
8 if it's a tab. Supporting a tab length option might also be
possible, but then it would also be nice to have e.g. epp support
passing of this option to the scanner.

Apologies for not just making my own patch and committing, but
I was just playing with this out of curiosity.

BR,
Ulf W
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAktM//gACgkQtqqFieqzed0z8ACgmrRZHiHMh98aK04JbYFcQuT+
6AgAnjeee8wG0wUJTTEHA2hhCdQ6GsAP
=Dhk8
-----END PGP SIGNATURE-----
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com


________________________________________________________________
erlang-bugs mailing list. See http://www.erlang.org/faq.html
erlang-bugs (at) erlang.org

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com

Post received from mailinglist
View user's profile Send private message Visit poster's website
rvirding
Posted: Mon Jan 25, 2010 5:01 pm Reply with quote
User Joined: 30 Aug 2006 Posts: 452 Location: Stockholm, Sweden
2010/1/18 Hans Bolinder <hans.bolinder@ericsson.com>:
> [Ulf Wiger:]
>> I tried the column tracking functionality of erl_scan:
> ...
>> The original source code wasn't misaligned, but the indentation
>> used a mix of tabs and spaces. erl_scan treats all kinds of
>> white space as one space.
>>
>> I think it would be reasonable to at the very least increment by
>> 8 if it's a tab. Supporting a tab length option might also be
>> possible, but then it would also be nice to have e.g. epp support
>> passing of this option to the scanner.
>
> We will consider adding such an option in a future release.

I would argue that it is not really the function of the scanner to do
this type of thing as there are too many different options if it is to
be supported properly. As the option 'return_white_spaces' exists it
can very well be left to the caller of erl_scan.

Robert

________________________________________________________________
erlang-bugs mailing list. See http://www.erlang.org/faq.html
erlang-bugs (at) erlang.org

Post received from mailinglist
View user's profile Send private message Visit poster's website MSN Messenger
Guest
Posted: Mon Jan 25, 2010 7:20 pm Reply with quote
Guest
Robert Virding wrote:
> 2010/1/18 Hans Bolinder <hans.bolinder@ericsson.com>:
>> [Ulf Wiger:]
>>> I tried the column tracking functionality of erl_scan:
>> ...
>>> The original source code wasn't misaligned, but the indentation
>>> used a mix of tabs and spaces. erl_scan treats all kinds of
>>> white space as one space.
>>>
>>> I think it would be reasonable to at the very least increment by
>>> 8 if it's a tab. Supporting a tab length option might also be
>>> possible, but then it would also be nice to have e.g. epp support
>>> passing of this option to the scanner.
>> We will consider adding such an option in a future release.
>
> I would argue that it is not really the function of the scanner to do
> this type of thing as there are too many different options if it is to
> be supported properly. As the option 'return_white_spaces' exists it
> can very well be left to the caller of erl_scan.

Well, as it currently works, it tracks the column number,
so I wasn't asking for that particular feature to be added.
But if it's going to track the column number, it should add
whitespace correctly. It doesn't make sense to count tabs
as one space, and I'd say it violates the Principle of Least
Astonishment. In other words, a bug. Smile

Changing the current behaviour to counting tabs as 8
(hard-coded) would at least be an improvement. Making it
configurable would be the extra feature.

BR,
Ulf W
--
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com


________________________________________________________________
erlang-bugs mailing list. See http://www.erlang.org/faq.html
erlang-bugs (at) erlang.org

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum