StringSection / EndStringSection

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: StringSection / EndStringSection

Post by Trond »

Kaeru Gaman wrote: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...
You can't expect people to manually null-terminate their strings in a BASIC language, it's just not right™.

If people want to do that then they can use inline asm, which looks really clean in my opinion:

Code: Select all

Readme.s = PeekS(?MyString)
DataSection
  MyString:
  !CRLF equ 13, 10
  !db "this is the first line", CRLF, "this is the second line", CRLF
  !db 'this is some text in quotes:"quote me"', CRLF
  !db "and all the text belong to the same string!", 0
EndDataSection
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 »

okay... I think I got to take a look at the db command ...
you use " and ' mixed?
fist line: " encloses the string
second line ' encloses the string wich contains "
oh... and have a nice day.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Re: StringSection / EndStringSection

Post by Marco2007 »

Trond wrote:

Code: Select all

Readme.s = PeekS(?MyString)
DataSection
  MyString:
  !CRLF equ 13, 10
  !db "this is the first line", CRLF, "this is the second line", CRLF
  !db 'this is some text in quotes:"quote me"', CRLF
  !db "and all the text belong to the same string!", 0
EndDataSection
:shock: Holy Shit, this is great! thx! :D
Last edited by Marco2007 on Tue Jan 12, 2010 7:50 pm, edited 1 time in total.
PureBasic for Windows
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: StringSection / EndStringSection

Post by Foz »

What about a tool for generating and editing hex data lines?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: StringSection / EndStringSection

Post by Trond »

Kaeru Gaman wrote:okay... I think I got to take a look at the db command ...
you use " and ' mixed?
fist line: " encloses the string
second line ' encloses the string wich contains "
Both " and ' can be used to define strings, the strings can contain the other type of quote.

Note: use of !db works in ascii mode only. For unicode, use !dw instead.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post by Seymour Clufley »

That's much more complicated than a StringSection like I propose. I really do think there's a place for this. Of course it's not essential and it wouldn't improve our programming, but it would be very useful.
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
greyhoundcode
Enthusiast
Enthusiast
Posts: 112
Joined: Sun Dec 30, 2007 7:24 pm

Heredoc style syntax

Post by greyhoundcode »

Similarly, something like:

Code: Select all

Print <<<TEXT
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. 

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
TEXT;
Would make it nice and easy to work with multi-line strings. Could this, or Seymour's StringSection, be implemented by some sort of pre-processor arrangement if not as a de facto part of the language?
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Heredoc style syntax

Post by Seymour Clufley »

greyhoundcode wrote:Could this, or Seymour's StringSection, be implemented by some sort of pre-processor arrangement if not as a de facto part of the language?
But that would not affect the IDE, which would "syntaxify" everything inside the StringSection - so the text couldn't contain words like "with", "and", "not", "or" etc.

I still think this would be a good addition to PB, and surely not that difficult to implement.
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
greyhoundcode
Enthusiast
Enthusiast
Posts: 112
Joined: Sun Dec 30, 2007 7:24 pm

Re: Heredoc style syntax

Post by greyhoundcode »

Seymour Clufley wrote:I still think this would be a good addition to PB, and surely not that difficult to implement.
+1 :D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: StringSection / EndStringSection

Post by blueznl »

Dunno, wouldn't a multiline option fix the same problem?

In CodeCaddy I supported 'terminating' line continuation characters, as well as 'leading' ones, so I could do this:

Code: Select all

Data.s 
  _ Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet
  _ dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
  _ lobortis nisl ut aliquip ex ea commodo consequat.
  _ Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat
  _ nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue
  _ duis dolore te feugait nulla facilisi.
Isn't that pretty much the same thing?

The rules I used were:

1. when appending lines strip out comments from the lines code is appended to
2. if a line STARTS with an underscore followed by a space it will be appended to the previous line
3. if a line ENDS with an underscore preceded by a space and followed by a CR or space the next line will be added to it

It takes a little code to parse the line to fix things like " _ " but it seems to work fine. By putting the line continuation character AT THE START of the next line, processing those lines becomes very fast, and code stays quite readable.

This is NOT to open a discussion on multi line support in PB! :-) I just wanted to see if, when requesting a 'text section' feature, things could be made as simple as possible. My solution does not support additional CR's though... Hmm...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: StringSection / EndStringSection

Post by chris319 »

t.s = ReadStringSection(@description)
This should not be necessary. It should be:

Code: Select all

StringSection description.s =
PureBasic is a native 32 bit and 64 bit programming language based on established BASIC rules.
EndStringSection
or StringSection description$ =

For your control characters:
/n = newline
/t = tab

BTW, this is a quotation mark "
This is a double quotation mark ""
This is an apostrophe '

http://en.wikipedia.org/wiki/Punctuation
http://en.wikipedia.org/wiki/Quotation_mark
http://en.wikipedia.org/wiki/Apostrophe
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: StringSection / EndStringSection

Post by Seymour Clufley »

chris319 wrote:
t.s = ReadStringSection(@description)
This should not be necessary. It should be:

Code: Select all

StringSection description.s =
PureBasic is a native 32 bit and 64 bit programming language based on established BASIC rules.
EndStringSection
or StringSection description$ =
Possibly, although you'd have to stipulate beforehand whether the resulting string was global, local etc. Maybe not a bad thing.

But why the = sign? We don't need that when specifying structures, for example.
For your control characters:
/n = newline
/t = tab
Why these control characters instead of the real thing(s)?
BTW, this is a quotation mark "
This is a double quotation mark ""
This is an apostrophe '
I don't know if I used those names wrongly somewhere, but I am very well-acquainted with those symbols. ;)
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 »

Seymour Clufley wrote:
chris319 wrote:BTW, this is a quotation mark "
This is a double quotation mark ""
This is an apostrophe '
I don't know if I used those names wrongly somewhere, but I am very well-acquainted with those symbols. ;)
in modern english terms, ' is a quote and " is a doublequote.
http://en.wikipedia.org/wiki/Quotation_mark wrote:Quotation marks or inverted commas (informally referred to as quotes[1] and speech marks) are punctuation marks used in pairs to set off speech, a quotation, a phrase, or a word. They come as a pair of opening and closing marks in either of two styles: single ('. . .') or double (". . .").
again showing the same korinthenkacker attitude like with the definition of "character", and even failing.

epic fail, dude!

Image
oh... and have a nice day.
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 »

the reason is the limited keyboard of classic typewriters, thus they made only a single DQ for both, opening and closing,
and an apostrophe for use as apostrophe and opening and closing SQ.

you would need four additional keys to add the chars $201c, $201d, $2018 and $2019 to the standard keyboard.


... and the reson for being so unkind is that
chris319 wrote:Thanks for sharing your vast wisdom.
really means
hit me harder next time
... think about that before you get cynical on people again.
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: StringSection / EndStringSection

Post by blueznl »

Stop it people. Flamewars don't belong here.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply