How to add new features? (syntax, user API)

For other topics related to the FreeBASIC project or its community.
paul doe
Posts: 1255
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: How to add new features? (syntax, user API)

Postby paul doe » Nov 11, 2019 21:13

Juergen Kuehlwein wrote:@paul doe,

thanks for your interest! I will post a link to the executables and how to use them - maybe tomorrow.

You're welcome. I'll give them a whirl as soon as I can, I promise.

Juergen Kuehlwein wrote:
stringizing that takes spaces into account

doable, but what for?
...
May I suggest a 'destringize' also?

could you expand on this too. I don´t understand, what exactly you want: "(a string to a valid symbol)" to my understanding this is what "#" already does. Return a literal string from a macro parameter (which can be a symbol).

Check out how the templating framework is laid out in the project I linked before to see a concrete example. But, for quick reference:

Code: Select all


#macro foo( bar )
  #print #bar
#endmacro

foo( integer ptr )

That macro indeed expands to integer ptr, which is not a valid symbol. A valid symbol could be, in this case, integer_ptr, _integerptr, _integer_ptr_ or anything like that. That is, it somehows mangles the valid data type into a valid symbol. And before you answer: yes, this can be done with variadic macros and no, I don't want to do it that way (it forces you to syntax like, for example, dim l as LinkedList( of( integer, ptr ) ) which looks awful).
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Postby Juergen Kuehlwein » Nov 12, 2019 17:33

I see! Yes, i can do that.
paul doe
Posts: 1255
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: How to add new features? (syntax, user API)

Postby paul doe » Nov 12, 2019 21:11

Juergen Kuehlwein wrote:I see! Yes, i can do that.

Thanks, Juergen. Much appreciated.

Say, some of the new macros you added are pretty cool, and have a lot of potential. I'll code some use cases and post them here (or, if you prefer, we can open a new thread specifically for your fork), so we can discuss them and their potential applications.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Postby Juergen Kuehlwein » Nov 12, 2019 21:59

The new feature ("#%" remove spaces in an argument, i.e. concatenate space separated parts) is in my Google drive: https://drive.google.com/open?id=1e7oP1 ... RHp0G_HQQm. The folder "Macro" contains executables for win32/64, i removed the macro without brackets feature temporarily, because it´s still buggy.

I'll code some use cases and post them here (or, if you prefer, we can open a new thread specifically for your fork), so we can discuss them and their potential applications.

Yes please do, but start a new thread.

Added:
maybe i should rename the new operators: "###" for the new concatenation operator (#=stringize, ##=concatenate, ###=concatenate - remove spaces), "#'%" for counting commas, "#?" for quirk words, and maybe something more obvious for "#&#" (currently "stringize uppercase").

Or "#&" for the new concatenation (& stands for concatenation in FB otherwise too) and "###" for stringize uppercase ('#" regular stringize).
paul doe
Posts: 1255
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: How to add new features? (syntax, user API)

Postby paul doe » Nov 13, 2019 20:43

Juergen Kuehlwein wrote:The new feature ("#%" remove spaces in an argument, i.e. concatenate space separated parts) is in my Google drive: https://drive.google.com/open?id=1e7oP1 ... RHp0G_HQQm. The folder "Macro" contains executables for win32/64, i removed the macro without brackets feature temporarily, because it´s still buggy.
...

Terrific. Downloading it now, thanks.

...
Yes please do, but start a new thread.
...

Duly noted.

...
Added:
maybe i should rename the new operators: "###" for the new concatenation operator (#=stringize, ##=concatenate, ###=concatenate - remove spaces), "#'%" for counting commas, "#?" for quirk words, and maybe something more obvious for "#&#" (currently "stringize uppercase").

Or "#&" for the new concatenation (& stands for concatenation in FB otherwise too) and "###" for stringize uppercase ('#" regular stringize).

The first option sounds fine with me (re-reading the posts above, I should have used 'identifier' instead of 'symbol' -duh). The second option is also acceptable, naturally.
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Postby Juergen Kuehlwein » Nov 14, 2019 22:27

Restored the macro without brackets feature - should work now. There is a new upload in my Google drive: https://drive.google.com/open?id=1e7oP1 ... RHp0G_HQQm.
dodicat
Posts: 6643
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How to add new features? (syntax, user API)

Postby dodicat » Nov 15, 2019 12:13

For fun.
macro mess around

Code: Select all



#macro Remove(Text,Chars)
scope
#macro _For(a,b,c,instruction)
scope
a
#define labl  label:
labl
instruction
c
if b then goto labl
#undef label
end scope
#endmacro
#define unfinished  m<len((Chars))
#define RangeText(g)  If (Text)[n]<> Asc(g) Then (Text)[i]= (Text)[n]:i+=1
#define RangeChars(h)  _For(dim as long n=0,n<len((Text)),n+=1,RangeText(h))
    Dim As Long i, m
    #define go label2:
    go
       i=0
    RangeChars(chr((Chars)[m]))
    (Text)=left((Text),i)
    m+=1
    if unfinished then goto go
end scope
#undef label2
    #endmacro
   
    dim as string s="free"+string(1000000,"a")+"basic"+string(100000,"b")
    remove(s,"freeba")
    print s
 
   s="hHIJK2LMNOo"
    remove(s,"HIJKLMNO)")
    print s
    s="Pardon me"
    remove(s,"Pram ")
    print s
    sleep
     
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Postby Juergen Kuehlwein » Nov 15, 2019 14:27

It´s amazing, what you can do with macros, isn´t it!

Thanks for this test piece, runs without problems - the added features don´t interfere with the existing ones. I know, you have done a lot with macros. Feel free to test your macros with the new compiler version (nothing official, just for testing and finding bugs). It would be of great help to have someone experienced like you on board!
Juergen Kuehlwein
Posts: 284
Joined: Mar 07, 2018 13:59
Location: Germany

Re: How to add new features? (syntax, user API)

Postby Juergen Kuehlwein » Nov 16, 2019 12:48

I changed operator actions as follows for a more consistent syntax:

these are the already availble operators:
# = stringize
## = concatenate

these are new:
### = stringize (uppercase)
#&# = stringize + concatenate (remove spaces in a space separated argument). "&" stands for concatenate
#% = count arguments contained in a variadic parameter (= count of commas + 1). % implies "number", so counting seems obvious
#? = check for preceding quirk word. ? for checking something seems obvious too

uploaded to my Google drive: https://drive.google.com/open?id=1e7oP1 ... RHp0G_HQQm

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests