I just fail to see why the tail would ever need to be filtered. The filter function is a rather extraneous function to begin with =P. For commands, it could be useful at head (if you weren't using String.parse).
edit
String Parser doesn't support super types, so doing 1+1 is impossible (1 + 1 would work, but it would be dumb, lol). I thought about adding it in, but I realized that something like a math string thing would be stupid ; P.
I do know how to change this around so it supports supertypes and subtypes, but I likely won't do it as its an overhead that's not worth it :\.
edit
If you guys want supertypes, let me know... supertypes would let you do stuff like: 1+1&2+2 or w/e.
So far, the hard coded supertypes in StringParser are ascii numbers, strings, variables, numbers, and stacks (to give you an idea of what they are).
If I were to do supertypes, then this would pretty much be a full blown language parser as this already handles everything else >.<.
Just keep in mind that this would be like a cmd in wc3... the practical use of a cmd in wc3 is pretty much bleh, lol. Also think of the extra overhead that would be incurred for the nearly useless feature of supertypes ; P. This is the reason I did not implement supertypes.
Now, if you wanted to do math with StringParser right now, all that it would be useful for is the grouping symbols (trust me, grouping is a pain to deal with).
Here would be the current steps to do the math stuff-
JASS:
String.parse(string)
loop
//whenever encountering a math symbol, join left and right
//if left is stack, get result of stack using a nifty loop
//if right is stack, get result of stack using a nifty loop
endloop
You could also do it this way
JASS:
loop
//whenever encountering a math symbol, add space to left and right of it
endloop
call String.parse(str)
loop
//do maths
endloop
lol...
Why don't I just add special support for special characters? Because there are also well known special strings like && and ||.
supertypes would be implemented in this fashion-
JASS:
local integer i = SuperTypes.maxsize
local string v
local SuperType superType = 0
loop
exitwhen i == 0 or superType != 0
set v = SubString(str, pos, pos+i)
set superType = LoadInteger(SuperTypes.table, StringHash(v), 0)
set i = i - 1
endloop
if (superType != 0)
//allocate new node and finish off last
set pos = pos+i+1
endif
So really, the overhead isn't that insane I guess... especially if the biggest supertype you have is only 2 characters (maxSize is how many characters the biggest supertype is).
Perhaps I will implement it...
Only thing is multi position super types that can also have depth, like stacks... I guess that's when it starts getting semi hardcore ;P.
This would mean that each supertype would have a collection of tags associated with it that must occur in a specific order >: O.
Furthermore, supertypes that aren't the same can be next to each other, and some supertypes can be next to each other regardless.
For example, 1+++ wouldn't work so well, but 1+1 would. 111++ wouldn't do so well, but 1+1+1 would : ).
Shall I implement this insanity?
local StringStack gg = String.parse("x=1+5*16(18+14)-12 loop(CreateUnit(player1|player2|player3||player4&&player5|player6(bonus*3)) x-- until x==0))")
would be around
Code:
set x = 1+5*16*(18+14)-12
loop
CreateUnit(player1)
CreateUnit(player2)
if (player3.inGame) then
CreateUnit(player3)
else
CreateUnit(player4)
CreateUnit(Player5)
endif
local integer i = bonus*3
loop
exitwhen i == 0
CreateUnit(Player6)
set i = i - 1
endloop
set x = x - 1
exitwhen x == 0
endloop
Yes, with supertypes you can easily make an entire programming language using StringParser since it already has everything else it needs ;o...
There's also the delimiter supertype (spaces and commas). You could just do this and eliminate the extra overhead and work-
1 + 1 * 3(5 + 5) etc