Underscore rules

Forum for discussion about the documentation project.
Post Reply
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Underscore rules

Post by Richard »

Use of underscore character to use multiple text lines for one line of source code seems to allow comments on all text lines. This is great for documenting lists.

Code: Select all

dim as _
integer i
for _       ' comments
    i _     ' are 
    = 1_    ' ok
    to 10   ' within
    print _ ' extended
    i       ' lines
next i
sleep
Now the only problem is finding the rules for using the line extensions, keywords and variables need a SpaceUnderscore while numbers need only an Underscore. How much of this is a supported feature?
Are the definitive rules hidden in the wiki documentation, or does everyone know them? Are they the same as C++ which I don't use?
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Post by Deleter »

Well it makes sense since an underscore can be part of a legal variable, but not a number. Just put a space no matter what and you can't go wrong.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Yes, it does make sense which is why I tried it. The parser needs to know what to look for next.
The Help on REM gives a new way of having comments that straddle multiple lines by using /' and '/ but this is a different situation since my example actually places the comments within the line of source code.
I can still go wrong if this is a development artifact that disappears later rather than an undocumented feature that becomes documented. It does seem to be a deliberate feature.
Multi-line DIM and parameter passing are quite neat with comments.

Code: Select all

dim fred as integer, _ ' a very special number 
    rope as string     ' lots of characters

Sub Observer ( _
    LatObs As Double, _   ' Latitude of observer
    LngObs As Double)     ' Longitude of observer
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

I would say that placing comments ( with ' ) after the line continution character ( _ ) should be possible in all future versions of FreeBASIC. When the information does get added to the docs it would likely go under "Lexical Conventions" on this page: Programmer's Guide (link)

A brief description of identifier rules is described here: Identifier Rules (link)

In spite of the progress we have made with the documentation, this reminds me of how far we still have to go. :)
Post Reply