aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.25k stars 119 forks source link

Bugs in tokenize() #185

Closed AntonBogun closed 2 years ago

AntonBogun commented 2 years ago

print(tokenize(";a;;", ";", "")) outputs ["","a"] instead of expected ["","a","",""]

AntonBogun commented 2 years ago

Furthermore, the whitespace argument does not work as intended:

let str="Hello,\r\nWorld" print(tokenize(str,"\n","")) print(tokenize(str,"\n","\r"))

prints ["Hello,\r", "World"] ["Hello,\r", "World"] while the second print is expected to be ["Hello,", "World"]

aardappel commented 2 years ago

That is intentional, it says by splitting into segments upon each dividing or terminating delimiter, i.e. the last 2 , are terminating.

The intention was to make the function useful for situations where the delimiter is dividing (such as typically intended with ,) or terminating (as typically intended with ; ).

I suppose I could have added a bool indicating whichever strategy, or two separate functions.

Agree the whitespace case is a bug.

aardappel commented 2 years ago

Ok, improved things in https://github.com/aardappel/lobster/commit/fd1f0c1b3617f5b2aba53ddb30b5e7cf70f525e8