Page 1 of 3

StringSection / EndStringSection

Posted: Mon Jan 11, 2010 11:59 am
by Seymour Clufley
As a refinement on this idea, I propose something like this:

Code: Select all

StringSection description
  PureBasic is a native 32 bit and 64 bit programming language based on established BASIC rules.
  The key features of PureBasic are portability (Windows, Linux, MacOS X and AmigaOS are currently supported), the production of very fast and highly optimized executables and, of course, the very simple BASIC syntax.
  PureBasic has been created for the beginner and expert alike. We have put a lot of effort into its realization to produce a fast, reliable system friendly language. 
EndStringSection

t.s = ReadStringSection(@description)
MessageRequester("About PureBasic",t)
I think this would be very useful as it would enable easy inclusion of long strings in a program, with no file dependencies and no string operations (eg. replacing Chr(34) all the time etc.).

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 2:14 pm
by ts-soft
IncludeBinary with a Textfile do the same.

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 4:12 pm
by Seymour Clufley
But then the other file has to be copied/transported along with the source code, because it isn't inside the source code.

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 4:38 pm
by Kaeru Gaman
I had to think about it a little, but it sounds like an interesting idea.
the advantage of including DQuotes without escaping maybe a good thing...

BUT the IDE needs to handle this properly.
no sytax highlighting for a whole block, no keyword case correction, etc., etcpp...

the question is ... is it really worth the effort?

when you want to spread your sourcecode, why not shipping a textfile with it?

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 5:29 pm
by Foz
As text files can be added as part of a project, I don't see the problem with that any more.

I now have a "scratchpad" file in my projects as a reminder and todo list.

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 6:05 pm
by Seymour Clufley
Kaeru Gaman wrote:the advantage of including DQuotes without escaping maybe a good thing...
I think it would be very, very useful!
BUT the IDE needs to handle this properly. no sytax highlighting for a whole block, no keyword case correction, etc., etcpp...
Absolutely.
the question is ... is it really worth the effort?
I think so.
when you want to spread your sourcecode, why not shipping a textfile with it?
Because it would be so much simpler just to have the necessary text inside the source code.

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 8:50 pm
by Kaeru Gaman
but even "plain" text can contain control codes.

DQuote is the most simple, what about Newline?
should it be put after every line in the Stringsection?
then long paragraphs could be annoying.

Tab isn't part of the Input in the IDE, how to manage this?
not even the two spaces at the beginning like in your example would be possible.

and Strings can also be used to build text output functionalities.
up, down, left, right, backspace and delete are legal controlcodes within a string,
not to forget ESC what you need to start escape sequences on the printer...

so, the ONLY real advantage would be sparing DQuote,
the rest already is possible with Data.s

so, I have to repeat: would this really be worth the effort?

Re: StringSection / EndStringSection

Posted: Mon Jan 11, 2010 10:57 pm
by bembulak
would this really be worth the effort?
Why not? Lots of languages support such behavior. Python for example supports 'triple-quoted' strings.
Python even supports it for documentation purposes (so called docstrings).

I really can understand that request. Since we do not have the possibility now to split long lines, this is a good idea.
(In fact long line splitting has nothing to do with this request, but I would use both requests to serve the same purpose)

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 12:52 am
by Joakim Christiansen
Kaeru Gaman wrote:the question is ... is it really worth the effort?
I think it is an excellent idea!

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 10:41 am
by Trond
This doesn't solve the problem. The problem is that the string end character can't be used in the string. With a StringSection, the string end character is now "EndStringSection" instead of a double quote. But it still can't be used in the string, so if you want to have a string like this:

Code: Select all

StringSection
  PB's string sections are perfect for any situation.
  There is only two exceptions - when you indent your code the string gets messed up
  And if you want to explain that string sections are ended with "EndStringSection" then
  you will get a syntax error.
EndStringSection
it won't work, because EndStringSection is in there.

What a StringSection does is to take away the possibility of working around this limitation. Because with double quotes you can add them with Chr(). But string sections can't be added together, so you're stuck in a much worse way than with ordinary strings.

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 10:51 am
by helpy
You could use:

Code: Select all

StringSection EndStringMarker
Put some text here ...
EndStringSection EndStringMarker
So you can use an EndStringMarker, which does not occur in the string!

Code: Select all

StringSection AnotherEndStringMarker
Put some text here ...
EndStringSection AnotherEndStringMarker
cu, helpy

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 11:22 am
by Seymour Clufley
Or it could simply be illegal to have EndStringSection inside a stringsection.

In Trond's example, the IDE could alert you that the StringSection is prematurely terminated by an EndStringSection.

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 11:46 am
by gnozal
ts-soft wrote:IncludeBinary with a Textfile do the same.
Seymour Clufley wrote:But then the other file has to be copied/transported along with the source code, because it isn't inside the source code.
I am probably stating the obvious, but you could include the text (or any other data) as (compressed) hexadecimal data.
That's what I do instead of IncludeBinary, because I like to have all the data in the source code too.
Example :

Code: Select all

DataSection
  ToolbarImage_Window_0_CharMap_2:
  Data.l $0000013E
  Data.l $013E434A,$E24C0000,$2301AD18,$80022091,$108C0098,$08C500CC,$0800A005,$94818030,$601D4620,$04682062,$AFA0492A,$811F0811
  Data.l $911E46C0,$80267CC0,$7404F810,$08470010,$60477040,$1E78204B,$E2807681,$00211211,$04512048,$C1811FFA,$E640E814,$3399CD5E
  Data.l $F2B88DBB,$494B3496,$79660400,$7246E36D,$50606886,$02027795,$3334CA1A,$BDB5F5C4,$D9331330,$C10F6F7B,$C4B722C8,$D0FFEFBD
  Data.l $0E084685,$BE9EB466,$B6244D38,$C62FF453,$C048B4BD,$A6507428,$9A0DC0E0,$F43F19D7,$3C103FD7,$A02D11F4,$008B76B2,$0012B9E6
  Data.l $F0090A1C,$7D8D81A1,$22441FE4,$000000F0
  Data.b $00,$00
EndDataSection
Some IDE / jaPBe plugins will even generate the data section code for you.

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 2:00 pm
by Seymour Clufley
gnozal wrote:you could include the text (or any other data) as (compressed) hexadecimal data.
Yes, but then you can't edit it in the IDE as you would edit any other string.

Re: StringSection / EndStringSection

Posted: Tue Jan 12, 2010 2:08 pm
by Kaeru Gaman
what about some EXTRA type for the DataSection?

e.g. name it type .ss

this would lead to
Data.ss
Read.ss
MyString.s
the .ss type Dataline could carry
- literal strings in DQuotes, wich will NOT be terminated with delimiters
- numbers that will directly be inserted, to be able to carry controlcodes

then datalines could look this way:

Code: Select all

Data.ss "this is the first line", #CRLF, "this is the second line", #CRLF
Data.ss "this is some text in quotes:", #DQUOTE, "quote me", #DQUOTE, #CRLF
Data.ss "and all the text belong to the same string!", #StringTerminate
maybe that would solve almost the same
and be far easier to implement to IDE and Compiler...