Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Klaus via Digitalmars-d-learn
I mean when writing a D lexer, you necessarly reach the moment 
when you think:


Oh no! is this feature just here to suck ?


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via Digitalmars-d-learn wrote:
 I mean when writing a D lexer, you necessarly reach the moment when
 you think:
 
 Oh no! is this feature just here to suck ?

I use heredocs every now and then when I need to embed long strings in
my program. It's one of the things I *like* about D, in fact. Nobody
wants to manually parenthesize every quoted line with '...\n' when the
program need to incorporate several pages of built-in help text, for
example.

Delimited strings are useful when writing code/text generators when you
need to be able to use ' and  as literal characters without crazy
leaning-toothpick syndrome \x\y\z\w\'s sprinkled everywhere.

The crazy variety of ways to write string literals in D, OTOH, *is* a
bit over the top, as I found out myself when I also tried writing a D
lexer.  :-P


T

-- 
LINUX = Lousy Interface for Nefarious Unix Xenophobes.


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Philippe Sigaud via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 10:09 PM, H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:
 On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via Digitalmars-d-learn wrote:
 I mean when writing a D lexer, you necessarly reach the moment when
 you think:

 Oh no! is this feature just here to suck ?


 The crazy variety of ways to write string literals in D, OTOH, *is* a
 bit over the top, as I found out myself when I also tried writing a D
 lexer.  :-P

Out of curiosity, how does a lexer deal with heredocs? It's a sort
of... user-defined token, right?


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 10:50:34PM +0200, Philippe Sigaud via 
Digitalmars-d-learn wrote:
 On Mon, Aug 11, 2014 at 10:09 PM, H. S. Teoh via Digitalmars-d-learn
 digitalmars-d-learn@puremagic.com wrote:
  On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via Digitalmars-d-learn 
  wrote:
  I mean when writing a D lexer, you necessarly reach the moment when
  you think:
 
  Oh no! is this feature just here to suck ?
 
 
  The crazy variety of ways to write string literals in D, OTOH, *is*
  a bit over the top, as I found out myself when I also tried writing
  a D lexer.  :-P
 
 Out of curiosity, how does a lexer deal with heredocs? It's a sort
 of... user-defined token, right?

In Flex, one way you can implement heredocs is to have a separate mode
where the lexer is scanning for the ending string.  So basically you
have a sub-lexer that treats the heredoc as three tokens, one that
defines the ending string for the heredoc (which is never returned to
the caller), one that contains the content of the heredoc, and the
terminating token (also never returned to the caller).

It's not that much different from any other string literal scanning (the
lexer must switch into string literal mode where things like \n and \t
have a different meaning than in the program code proper, and it exits
that mode when it encounters the terminating ''), except that here, the
terminating delimiter is variable.


T

-- 
Real men don't take backups. They put their source on a public FTP-server and 
let the world mirror it. -- Linus Torvalds


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Klaus via Digitalmars-d-learn
On Monday, 11 August 2014 at 20:10:47 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
On Mon, Aug 11, 2014 at 07:47:44PM +, Klaus via 
Digitalmars-d-learn wrote:
I mean when writing a D lexer, you necessarly reach the moment 
when

you think:

Oh no! is this feature just here to suck ?


I use heredocs every now and then when I need to embed long 
strings in
my program. It's one of the things I *like* about D, in fact. 
Nobody
wants to manually parenthesize every quoted line with '...\n' 
when the
program need to incorporate several pages of built-in help 
text, for

example.

Delimited strings are useful when writing code/text generators 
when you
need to be able to use ' and  as literal characters without 
crazy
leaning-toothpick syndrome \x\y\z\w\'s sprinkled 
everywhere.


The crazy variety of ways to write string literals in D, OTOH, 
*is* a
bit over the top, as I found out myself when I also tried 
writing a D

lexer.  :-P


T


Yep I think you get what I mean: clearly over the top, 
particularly when each element of your arm is 50% over the top 
and then when you try to show the top with an over-sized arm then 
it's clearly an over-toped position.




Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Philippe Sigaud via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 10:58 PM, H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 In Flex, one way you can implement heredocs is to have a separate mode
 where the lexer is scanning for the ending string.  So basically you
 have a sub-lexer that treats the heredoc as three tokens, one that
 defines the ending string for the heredoc (which is never returned to
 the caller), one that contains the content of the heredoc, and the
 terminating token (also never returned to the caller).

Ah, a small, specialized sub-lexer. OK, I get it.


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Brian Schott via Digitalmars-d-learn

On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote:
I mean when writing a D lexer, you necessarly reach the moment 
when you think:


Oh no! is this feature just here to suck ?


They are and they do.


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Brian Schott via Digitalmars-d-learn

On Monday, 11 August 2014 at 22:20:54 UTC, Brian Schott wrote:

On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote:
I mean when writing a D lexer, you necessarly reach the moment 
when you think:


Oh no! is this feature just here to suck ?


They are and they do.


Also, use this: https://github.com/Hackerpilot/libdparse


Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Klaus via Digitalmars-d-learn

On Monday, 11 August 2014 at 22:24:28 UTC, Brian Schott wrote:

On Monday, 11 August 2014 at 22:20:54 UTC, Brian Schott wrote:

On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote:
I mean when writing a D lexer, you necessarly reach the 
moment when you think:


Oh no! is this feature just here to suck ?


They are and they do.


Also, use this: https://github.com/Hackerpilot/libdparse


Sorry...I've been stupid...how could I missed that...Sometime I 
hate myself.




Re: Are Delimited strings and HereDoc strings just here to suck ?

2014-08-11 Thread Klaus via Digitalmars-d-learn

On Monday, 11 August 2014 at 22:56:27 UTC, Klaus wrote:

On Monday, 11 August 2014 at 22:24:28 UTC, Brian Schott wrote:

On Monday, 11 August 2014 at 22:20:54 UTC, Brian Schott wrote:

On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote:
I mean when writing a D lexer, you necessarly reach the 
moment when you think:


Oh no! is this feature just here to suck ?


They are and they do.


Also, use this: https://github.com/Hackerpilot/libdparse


Sorry...I've been stupid...how could I missed that...Sometime I 
hate myself.


https://github.com/search?l=Do=descq=stars%3A%3D0ref=advsearchs=updatedtype=Repositories