Page 2 of 3

Posted: Mon Dec 03, 2007 11:55 am
by AND51
Hello Dare!
Thanks for sharing my idea! :D

> The =<<" (or whatever or no token at all to indicate that line breaks are ignored until the next " [quote] is encountered).
Yes, this is the right description, why they use a << in CGI/Perl or in PHP, as freak said. I didn't find these awesome words... :roll:

> I would suggest (were this a democracy) that leading white space on the following line is collapsed to one space
Personally, I'm against that. Mabey, you want to have some multiple spaces. By the way, perl does not turn multiple spaces into 1 space. I find this ok.

> How would you make the distinction of ending in LF, CR, or CRLF?
The OS decides. The diffirent OS have their own line braks:
Windows => CRLF
Linux => LF
Mac => CR
Furthermore, you can define in the IDE preferences, wether you use Unicode modus or not. If I am not wrong, the Compiler uses the project settings to compile either in Unicode or in ANSII.

> multi-line strings without some sort of symbolic clue, like the = <<" could lead to problems
When I started this thread, I thought << was the best solution. But you all convinced me, that

Code: Select all

string.s="THIS
IS ALSO
A GOOD
POSIBILITY"
:)

> Oopsie = "I forgot to terminate.
I think, we should find compromises, when we want to achieve that this feature will be implemented. Supporting lazyness is like turning PB into Perl :lol:
So in this very special case, it's simply a syntax error. The code should be familiar with coding in a clean way.

Posted: Tue Dec 04, 2007 11:26 pm
by blueznl
Well, here is some code that flattens code (ie. converts multiline to regular stuff).

If FR34K would add a preprocessor option this would be easy to insert, or perhaps AlphaSnd would turn it into part of the language, dunno :-)

It's 3.94, but that's because it's going to be part of CodeCaddy.

Code: Select all

;
; purebasic multiline preprocessor
;
;
; I. each line passed on to the preprocessor can be broken down into:
;
;      [source] [ ; <comments> ]
;      [source] [ _ ] [ ; <comments> ]
;      [ _ ] [source] [ ; <comments> ]
;
;    any line ending on, or starting with an underscore is considered part of a multiline construction
;
; II. the preprocessor ignores all source between pairs of parenthesis or quotes uncluding comments, underscores, etc.
;
;      [source] " <whatever> " [source]
;      [source] ' <whatever> ' [source]
;
; III. there are no comments allowed after any remaining parenthesis, ie. valid constructions are
;
;      ... " <text> "   ; <comment>
;      ... " <text> " _ ; <comment>
;      ... " <text> " _
;
;    an example of an invalid line:
;
;      ... " <text> _ ; <comment>
;
;    however, the following is a special condition (see below) which is valid:
;
;      ... " <text> _
;
; IV. a special condition is an odd number of parenthesis with the line ending on an underscore, in this case
;    it is considered a valid multiline construction but no comments are allowed after the undercore
;
;    this multiline construction is only allowed for text spread over multiple lines; the lines will be trimmed
;    and added together with a single space in between them, ie.:
;
;      ... "<text> _
;      <text>" ...
;
;    will be turned into
;
;      ... "<text> <text>" ...
;
;
; well, thus far theory, now it's time to do the real thing!
; let's start by writing it in pseudosource
;
; 1.  n = n+1
; 2.  line a = line n
; 3.  p = 0
; 4.  line b = line n+p+1
; 5.  strip comments from line a, trim end line a
; 6.  if line a ends on continuation char
; 7.    p = p+1
; 8.    strip continuation char
; 9.    replace with a single space
; 10.   trim line b
; 11.   add line b to line a
; 12 .  go back to step 4
; 13. elseif line b starts with continuation char
; 14.   p = p+1
; 15.   strip continuation char
; 16.   trim line b
; 17.   add line b to line a
; 18.   go back to step 4
; 19. else
; 20.   we now have a complete line to write
; 21.   write line a
; 22.   write 'p' empty lines
; 23.   n = n+p-1
;

Procedure.s strip_comment(x.s)
  Protected c.l, p.l, l.l, parenthesis.l, quote.l, semicolon.l
  ;
  ; this procedure removed a comment section, if existing
  ; a comment section starts at the first semicolon that is not enclosed between parenthesis or quotes
  ;
  parenthesis = 0
  quote = 0
  semicolon = #False
  ;
  l = Len(x)
  ;
  p = 0
  While p < l And comment = #False And semicolon = #False
    p = p+1
    c = Asc(Mid(x,p,1))
    If c = 34
      parenthesis = #True - parenthesis
    ElseIf c = 39
      quote = #True - quote
    ElseIf c = 59 And quote = #False And parenthesis = #False
      semicolon = #True
    EndIf
  Wend
  ;
  If semicolon = #True
    ProcedureReturn RTrim(Left(x,p-1))
  Else
    ProcedureReturn RTrim(x)
  EndIf
  ;
EndProcedure

Procedure flatten(unflat.s,flat.s)
  Protected a.s, b.s, aa.s, bb.s, n.l, p.l, nomore.l
  ;
  OpenFile(1,unflat)
  CreateFile(2,flat)
  ;
  n = 0
  UseFile(1)
  a = ReadString()
  While Eof(1) = #False
    n = n+1
    p = 0
    nomore = #False
    While nomore = #False
      aa = a
      a = strip_comment(a)
      UseFile(1)
      bb = ReadString()
      b = Trim(bb)
      If Right(a,1) = "_"
        p = p+1
        a = RTrim(Left(a,Len(a)-1))+" "+b
      ElseIf Left(b,1)="_"
        p = p+1
        a = a+" "+Trim(Mid(b,2,Len(b)))
      Else
        UseFile(2)
        WriteString(aa+#CRLF$)
        While p > 0
          p = p-1
          WriteString(#CRLF$)
        Wend
        a = bb
        nomore = #True
      EndIf
    Wend
  Wend
  CloseFile(1)
  CloseFile(2)
  ;
EndProcedure

flatten("unflat.pb","flat.pb")

No, I haven't tried to make it as fast as possble.

And, if you wonder what it does, it turns this...

Code: Select all

a = a+ _
    22+ _
    7

b.s = "this is a _
      test"

b.s = "this is a
    _ test
    _ and another one"

b.s = "you can even" + _                      ; fool around with comments
      "and they will be properly stripped"    ; see?

b.s = "although in this case _                ; we obviously will
       see some problems"                     ; as we can't know it's a comment up there

b.s = "abc" + _                               ; no problem including " here
      "def"

a = '_' + 'a' _                               ; and this shoudl work as well...
    + '_'                                     ; i hope...
    
a.s = "123 _ 123"                             ; of course all possible comments should stay
       
b.s = "although in this case _                ; we obviously will
       see some problems"                     ; as we can't know it's a comment up there

b.s = "hmm"                                   ; no problems so far _
a = 1+2
into this

Code: Select all

a = a+ 22+ 7



b.s = "this is a test"


b.s = "this is a test and another one"



b.s = "you can even" + "and they will be properly stripped"    ; see?


b.s = "although in this case _                ; we obviously will
       see some problems"                     ; as we can't know it's a comment up there

b.s = "abc" + "def"


a = '_' + 'a' + '_'                                     ; i hope...

    
a.s = "123 _ 123"                             ; of course all possible comments should stay
       
b.s = "although in this case _                ; we obviously will
       see some problems"                     ; as we can't know it's a comment up there

b.s = "hmm"                                   ; no problems so far _
a = 1+2

Posted: Sat Dec 08, 2007 10:10 am
by Mistrel
What about trying to escape a multi-line string that contains double-quotes?

Posted: Sat Dec 08, 2007 12:12 pm
by blueznl
You lost me :-) Oh wait, I see. You CANNOT have double quote characters in a multiline string. Sorry :-)

Try CodeCaddy and see what it does to multilines.

There are some limits in it, but it goes quite far. In my solution you have to be careful with doublequotes, singlequotes and underscores. Here's what works:

Code: Select all

Debug "0101" + "0102"
Debug "0201" + "0202"   ; comments can include ; ' " or end on _
Debug "0301" _          ; a multiline example allowing a comment
  + "0302"              ; the comment above will be stripped, only this one will stay
Debug "0401" +          ; a similar construction, not with the multine character
_ "0402"                ; as the first character on the succeding line
Debug "0501 _
0502"                   ; i can add some comments here, but not on the line above
Debug "0601
_ 0602"                 ; you may also note that this construction puts a space in the output
Debug '"'               ; this actually works because '"' IS A NUMBER :-)
... and here's what doesn't work:

Code: Select all

Debug "a _            ; no comments allowed here
  b"
Debug """             ; the doublequote is a reserved character, so no luck here

Posted: Sat Dec 08, 2007 3:49 pm
by AND51
blueznl, thanks for your work, but I don't want to code a preprocessor. I'd like to have this natively.

The sense of this feature should be to avoid any garbage at the end of the line that should indictae to the preprocessor/compiler that a line break follows.

No #CRLF$, no _undersocre_, simply nothing! The string must be read until it's correctly terminated as usual.
That's why

Code: Select all

b.s = "this is a _ 
      test" 
is not valid. There could be situations in which I need a underscore in a string followed by a line break. Your preprocessor would limit my possibilities.

Posted: Sat Dec 08, 2007 7:16 pm
by blueznl
If you want to put doublequotes in there, it won't work either.

Besides, if you need to include larger amounts of data, then you should use datafile's.

Pffffrt.

Frankly, I wouldn't give a damn. It suits me, and as I am my primary customer that's how CodeCaddy is going to stay. May I suggest you take a long walk then write your own pre-processor?

Pffffrt.

:roll:

Posted: Sun Dec 09, 2007 12:43 pm
by AND51
Hello!

Sorry, if you feel attackted, this was not my intention. The reason might be a misunderstanding.

However, I donÄt want to use datafiles for a larger amount of data. I just want a quick feature to include multi-line strings into my program, e. g. for a default-XML-settings file.

There's no reason to be huffy.

@ CodeCaddy:
It doesn't matter to me how your project stays, this is a feature request regarded to Fred and PB, not at your project. So, your second sentence does not fit into this thread. But it's nice to hear that your CodeCaddy supports this feature. And as I already said, there's no reason for rolling your eyes.

Posted: Sun Dec 09, 2007 12:53 pm
by blueznl
Well, the data must come from somewhere. So let's assume you copy it from somewhere, all you would need to do is write a little program that takes the clipboard data, and turns it into a bunch of data.s / data.b statements.

Of course that's just a plugin, and not an integral part of PureBasic, but it may just work...

Posted: Sun Dec 09, 2007 1:43 pm
by AND51
Well, this is an idea...
OK, yes, this is a good workaround...
It's a pity, that PB doesn't suppoert this natively.
Hm... Is it possible to hear the PB team again? What do you say to this thread?
:D

Posted: Sun Dec 09, 2007 2:42 pm
by blueznl
I seem to recall that one could send commands to a scintilla gadget, thus it should be possible to do an externally generated 'paste'.

Posted: Sun Dec 09, 2007 5:30 pm
by freak
> Hm... Is it possible to hear the PB team again? What do you say to this thread?

I told you my opinion.
You don't need to ask over and over for our opinion, just be cause you do not like what we already told you...

Posted: Sun Dec 09, 2007 9:39 pm
by AND51
freak wrote:I told you my opinion.
You don't need to ask over and over for our opinion, just be cause you do not like what we already told you...
Thank you very much for this overall nice answer. :roll:
I'm so sorry for trying to convince you. I didn't know that you're too lazy to join a discussion, where you must be able to bring forward arguments.
I know that it's not me who has the right to determine PB's developement (this is not my intention!), but I can only make suggestions and I can only support this suggestions with arguments and examples. All I want is a discussion why/why not you're going to implement this. I don't know your definition of the word 'discussion', but it must be clear even to you that a discussion consists of more than just 1½ sentence.

If this enthusiasm is too much for you, I feel sorry for stealing your precious time. :roll:

Posted: Mon Dec 10, 2007 12:39 am
by Dare
Steady on there, AND51.

Lazy is NOT a word that you can associate with Freak and his time IS actually very precious.

Posted: Mon Dec 10, 2007 12:30 pm
by AND51
I know that 'lazy' is not appropriate.
But freaks statement "you do not like what we told you" IS also not appropriate, as it's not true. :?

My time is also very precious and your time is also precious, Dare; if there was no community, freak and his friends could detect bugs on his own. So freak, please appreciate my (and Dare's, Mistrel's, blueznl's and the communities) effort, then everything is fine. Do not forget that the community is helping to develope PB for free (finding Bugs, making suggestions, creating add-ons, ...)! That's why I call our all's time 'precious'.

A simply "Yes, I'll put it on my list" or "No, because" would have been enough! The 'because' is missing. Do you call "uh, it's ugly" an appropiate argument?
It's very annoying that you act so condescending. :(

...

I'll calm down and I'd like to go back to topic, because I'm interested in this. But I only want to go on with this, if freak (and the rest of the team) is interested in this at least a bit.

Posted: Mon Dec 10, 2007 3:30 pm
by freak
We had this discussion before...
http://www.purebasic.fr/english/viewtopic.php?t=26869

This is not the "I request something and you HAVE to answer me"-Forum.

Feel free to post your feature requests here, and feel free to discuss the pro's and con's
with the other forum users as well. We do take notice of what is posted here
and follow the discussions, and sometimes also join in and state our opinion on things.
But you simply cannot expect me to jump into every lengthy discussion
about feature X or Y and discuss it to death. I simply don't have time for that.

The past few weeks i had almost 0 time to do any coding. Now i can spend this time
to continue arguing about why i don't like some of your requests and get nothing done, or i can spend
it on actually implementing some things you requested. I think the choise is obvious...

In the above linked thread you said:

> I don't expect a long description, one or two sentences would be enough.

Now, i did tell you my opinion on this. Which just happens to be that this kind of
notation (can) create a messy code, which is hard to read.
I summed this up as being "ugly", which wiktionary defines as "not aesthetically pleasing."
which describes pretty well how i feel about this feature :)

This is my opinion. You wanted to know it, i told it to you. Plain and simple.
I wasn't looking for a lengthy discussion.

Its not like this thing has a ton of pro's and con's that you can debate
about forever. (well maybe you can, but where is the sense of it ?)
You may recall that i did spend quite some time to explain in detail our position
on things like the OOP discussion, but these are really things where there
is a lot to discuss about. I can't and won't do this for every one of the topics in
the feature requests forum...

Now, if i cannot even state my opinion on the simplest things without
getting "tell me more / i expect more arguments / tell me again / ..." responses
over and over, maybe next time i will not say anything at all...


(sometimes i really miss the times when i was just a regular user, where i could rant
about things and nobody would care.)