Thread overview
betterC CTFE nested switch
Feb 17, 2020
Abby
Feb 17, 2020
Stefan Koch
Feb 17, 2020
Abby
Feb 17, 2020
Stefan Koch
Feb 18, 2020
Abby
Feb 21, 2020
Abby
Feb 21, 2020
Stefan Koch
February 17, 2020
Hi there guys,
I was trying to generated code during compile time. Bassicly I'm creating a tokenizer and I would like to generated nested switch using betterC.

Basically convert something like this:

enum tokens =
[
    ['!', '='],
    ['>', '='],
    ['>'],
];

to:

switch(str[i])
{
    case '!':
        switch(str[i + 1])
        {
            case '=':
                onToken(['!', '=']);
                break;
            default: break;
        }
        break;
    case '>':
        switch(str[i + 1])
        {
            case '=':
                onToken(['>', '=']);
                break;
            default:
                onToken(['>']);
                break;
        }
        break;
    default: break;
}

but right now I'm stuck and I don't know how to achieve this. I was able to find out that:

1) Switches has to be labeled and the only way I know how to do so is to use string code and then mixing it. I was hoping for example to mixing only labels before switch and after continue and break but this does not seem to work :/

2) Format does not work in compile time using betterC (sprintf also does not work


Thank you very much for any kind if help
Kind regards Abby

February 17, 2020
On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote:
> Hi there guys,
> I was trying to generated code during compile time. Bassicly I'm creating a tokenizer and I would like to generated nested switch using betterC.
>
> [...]

I have a ctfe compatible string formatter, you should be to find it here
https://forum.dlang.org/post/hmyxvknbdqtlnxvqqnzq@forum.dlang.org

I hope that helps,

Regards, Stefan
:
February 17, 2020
On Monday, 17 February 2020 at 11:05:46 UTC, Stefan Koch wrote:
> On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote:
>> Hi there guys,
>> I was trying to generated code during compile time. Bassicly I'm creating a tokenizer and I would like to generated nested switch using betterC.
>>
>> [...]
>
> I have a ctfe compatible string formatter, you should be to find it here
> https://forum.dlang.org/post/hmyxvknbdqtlnxvqqnzq@forum.dlang.org
>
> I hope that helps,
>
> Regards, Stefan
> :

Hi Stefan, thank you very much for your reply but I could not find the source code or package name anywhere in that forum thread, I was only able to find this https://github.com/UplinkCoder/ctfeutils on github, but it's empty for me. Can you please help and point me to somewhere so I can try it out?

Thank you very much

Kind regards Abby
February 17, 2020
On Monday, 17 February 2020 at 11:51:03 UTC, Abby wrote:
> On Monday, 17 February 2020 at 11:05:46 UTC, Stefan Koch wrote:
>> On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote:
>>> [...]
>>
>> I have a ctfe compatible string formatter, you should be to find it here
>> https://forum.dlang.org/post/hmyxvknbdqtlnxvqqnzq@forum.dlang.org
>>
>> I hope that helps,
>>
>> Regards, Stefan
>> :
>
> Hi Stefan, thank you very much for your reply but I could not find the source code or package name anywhere in that forum thread, I was only able to find this https://github.com/UplinkCoder/ctfeutils on github, but it's empty for me. Can you please help and point me to somewhere so I can try it out?
>
> Thank you very much
>
> Kind regards Abby

Sorry I just realized I never published the code.
I am going to add it to ctfeutils.
February 18, 2020
On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote:
>
> Sorry I just realized I never published the code.
> I am going to add it to ctfeutils.

Thank you very much
February 21, 2020
On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote:
> Sorry I just realized I never published the code.
> I am going to add it to ctfeutils.

Hi Stefan,
I'm sorry to bother you, I just wanted to kindly ask if you would upload the formatter to ctfeutils on github it would help me alot.

Thank you very much
Kind regards Abby
February 21, 2020
On Friday, 21 February 2020 at 09:03:26 UTC, Abby wrote:
> On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote:
>> Sorry I just realized I never published the code.
>> I am going to add it to ctfeutils.
>
> Hi Stefan,
> I'm sorry to bother you, I just wanted to kindly ask if you would upload the formatter to ctfeutils on github it would help me alot.
>
> Thank you very much
> Kind regards Abby

No problem I am a little busy lately.

In the meantime you can check if std.format : format would do the job.
Even though it will like be much slower than my CTFE optimized version.