StringSection / EndStringSection

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

StringSection / EndStringSection

Post 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.).
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: StringSection / EndStringSection

Post by ts-soft »

IncludeBinary with a Textfile do the same.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: StringSection / EndStringSection

Post 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?
oh... and have a nice day.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: StringSection / EndStringSection

Post 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.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: StringSection / EndStringSection

Post 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?
oh... and have a nice day.
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: StringSection / EndStringSection

Post 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)
cheers,

bembulak
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: StringSection / EndStringSection

Post by Joakim Christiansen »

Kaeru Gaman wrote:the question is ... is it really worth the effort?
I think it is an excellent idea!
I like logic, hence I dislike humans but love computers.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: StringSection / EndStringSection

Post 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.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: StringSection / EndStringSection

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: StringSection / EndStringSection

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: StringSection / EndStringSection

Post 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...
oh... and have a nice day.
Post Reply