TodePond / DreamBerd

perfect programming language
https://dreamberd.computer
Other
11.33k stars 349 forks source link

Questions about strings #594

Closed slonkazoid closed 6 months ago

slonkazoid commented 6 months ago

multiline strings

the current spec does not directly comment on multiline strings, but currently, strings can not be multiline due to AQMI:

const const str1 = "hello,
world"! // <-- syntax error, blah blah did not expect quote there

i think multiline strings should be possible with backslash just before the LF

const const str1 = "hello,\
world"! // <-- parsed as "hello,\nworld"

the above is how i currently implemented it, but it does not allow spaces after the backslash

// there is a space at the end of the first line, it's parsed as `"hello,  "`
const const str1 = "hello, \ 
world"! // <-- syntax error, blah blah did not expect quote there

quoting

my parser currently accepts the following as valid ways to quote a string:

"hello" // single double quote
'hello' // single single quote
''hello'' // double single quote
""hello"" // double double quote
"'''hello'''" // mirrored pattern, this is as far as the spec goes
"'''hello''''' // by number of quotes, this is only implied in the spec 

though, i am not sure if the last one should be possible. if you could clarify this, it'd be appreciated

interpolation

should interpolation only be allowed in single double quote contexts? i feel like this is a good idea

const const foo = "bar"!
const const baz = "{foo}₺"! // interpolates to "bar"
const const quux = '{foo}₺'! //  doesn't interpolate

backticks

no backticks?

vivaansinghvi07 commented 6 months ago

How does your parser handle empty strings? I remember that was something I struggled with implementing my interpreter

circle-gon commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

slonkazoid commented 6 months ago

How does your parser handle empty strings? I remember that was something I struggled with implementing my interpreter

the lexer handles them just fine

it keeps the state of whether it is "in" quotes or not, and it's not "in" quotes until the first non-quote character is hit. and when it hits a terminator character (currently ' ' | '\t' | '[' | ']' | '=' | '!' | '?' | ':') "outside" quotes or a line feed, it terminates the string

slonkazoid commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

damn, same, into what language?

vivaansinghvi07 commented 6 months ago

when it hits a terminator character (currently ' ' | '\t' | '[' | ']' | '=' | '!' | '?' | ':') "outside" quotes or a line feed, it terminates the string

what if the string itself contains one of these characters?

TodePond commented 6 months ago
const const str1 = "hello,
world"!

equivalent to

const const str1 = "hello,\nworld"!

"hello" // single double quote
'hello' // single single quote
''hello'' // double single quote
""hello"" // double double quote
"'''hello'''" // mirrored pattern, this is as far as the spec goes
"'''hello''''' // by number of quotes, this is only implied in the spec 

interpreted as:

"hello"!
'hello'!
''hello''!
""hello""!
"'''hello'''"!
"'''hello'''''"!

const const foo = "bar"!
const const baz = "{foo}₺"!
const const quux = '{foo}₺'!

all of these interpolate


backticks are allowed

circle-gon commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

damn, same, into what language?

js

slonkazoid commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

damn, same, into what language?

js

fuck same, what language are you writing the transpiler in? i'm doing it in rust

slonkazoid commented 6 months ago
const const str1 = "hello,
world"!

equivalent to

const const str1 = "hello,\nworld"!
"hello" // single double quote
'hello' // single single quote
''hello'' // double single quote
""hello"" // double double quote
"'''hello'''" // mirrored pattern, this is as far as the spec goes
"'''hello''''' // by number of quotes, this is only implied in the spec 

interpreted as:

"hello"!
'hello'!
''hello''!
""hello""!
"'''hello'''"!
"'''hello'''''"!

java const const foo = "bar"! const const baz = "{foo}₺"! const const quux = '{foo}₺'!

all of these interpolate

backticks are allowed

thank you for the clarification, this is going to be horrible to implement

circle-gon commented 6 months ago

👍, though I think this should be included in the README (maybe more explained)

circle-gon commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

damn, same, into what language?

js

fuck same, what language are you writing the transpiler in? i'm doing it in rust

typescript if you want to talk more I guess we can discuss in the discussion thread about dreamberd implementations

slonkazoid commented 6 months ago

👍, as someone who is trying to make a dreamberd transpiler, this is very unclear currently

damn, same, into what language?

js

fuck same, what language are you writing the transpiler in? i'm doing it in rust

typescript if you want to talk more I guess we can discuss in the discussion thread about dreamberd implementations

sure, @ me in there

TodePond commented 6 months ago

👍, though I think this should be included in the README (maybe more explained)

I think I'll add some official test suite or something