• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[System] String Parser

Level 31
Joined
Jul 10, 2007
Messages
6,306
Okay, it looks decent. It has its uses, I guess. Not as many as Romek's string separator, but still.

I'll give it an approval. But don't take that too serious.

Well, what I want to eventually be able to do is have inferred typing while being able to merge characters into a single string =\.

I'm starting to think that " " for multi word types is a good thing. With this, I can add type aliases as well as new type creation.

For single word types, " " is unneeded, but the things will be inferred.

I just am reluctant to do that because that's not how text parsing normally operates when a player types a string or w/e. They aren't normally required to do " ".

What I'd also like to do is automatically do is dynamically split up by a queue of types. For example, if the string should be made up of a string, an integer, a string, and a boolean, it'll group up a string until it infers an integer and etc.

There is a lot I want to do, I've just yet to come up with good designs ; ).

Also Azlier, keep in mind that this is really a parser, not an exploder ; P. This means that it is supposed to act a little bit different and it's used for different things.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Added support for creating and destroying string values as well as manipulation of the values of those values o-o. Essentially, added support for variables, lol.

Will work on the stack in a bit.

I also got rid of a few totally useless loops in parse and Typeof... just changed it to a hashtable read >.<.


btw, would anyone seriously want to do something like this?
-e 1+1

output: 2

I can do super types, but it would add some overhead : |. I just don't see a real use for it...
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Ok, updated this to 2.2. The parse method is now officially 255 lines long!! O_O.

This now supports stacks of stacks in stacks with stacks on stacks /etc
Code:
"1"("2.1"("3.1")("3.1")"2.2")"1.2"

outputs (where the number in () is a label for (), like (1) is label of 1)
Code:
1, (1), 1.2

(1): (inside of 1)
    2.1, (2), (3), 2.2
    (2): (inside of 2)
        3.1
    (3): (inside of 3)
        3.1

All bugs I know of are fixed, lol...

The loop for iterating through your values is now really insane if you want to do stacks of stacks...

Stack characters are [ ], ( ), { }

If you have something like ((), string stack will be invalid and it will return 0. If you have ()), it will still be invalid and return 0. If you have (], still returns 0, lol. With """ 123, it'll end up returning "" and " 123. With ''' 123, it'll end up returning ''' and 123. With ()()((())), it'll return a bunch of empty stacks o-o.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
2.2.1.0 is out : |.

The extensions on types was hella weird... made it normal >.<.

It was originally:
real extends integer (all integers are now reals but not all reals are integers)
Now it is integer extends real (all integers are now reals, but not all reals are integers)

The latter just makes a whole lot more sense and is much easier to work with. While working on an example for Chapter 6, I was using color and playercolor. With the first example, color would have to extend playercolor.... That just looked so very wrong to me, so I reversed it =). Now playercolor extends color.


And chapters 1 through 6 are now written in the Tutorial, so if you have no clue what I'm talking about, read the tutorial : D. I'd also love feedback on it. Anyone who gives feedback on it will get +rep.

Last chapter to be written (getting rid of Advanced Techniques Chapter as that's really a bonus to Stack) is the Stacks chapter.

If you go through the chapters, you'll notice the examples in them get harder, bigger, and more complicated as you progress. Just take a look at the StringType example in Chapter 6.

If you want to get a feel for some of the Stack examples for Chapter 7, look at the Advanced Use code at the bottom of the first post. That is actually a simple Stack example.

The Stacks chapter might actually be split up into multiple chapters = |.

edit
Chapters all done. Chapter 8 changed into Looping chapter because stack loops are crazy as hell, lol.

Fixed one last bug that I encountered while writing an example. The stack sizes/counts were wrong on multiple stacks/nested stacks o-o.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
After reading the tutorial a bit I think this is the best documentated code ever :O The coding is nice too and it will be very useful for some people.

Thank you for the feedback : D. I'd +rep you if I could, but I must spread some reputation ;o.

I'm very glad you understood it. I was quite worried about Chapter 7: the nightmare chapter ; ).
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Soo... I was just wondering how many people have actually tried StringParser or currently use it? : D

Share with us your stories =D

Any StringParser masters out there who work with material covered in Chapter 7? ^_-.


Also, are there any changes that should be made to String Parser, or does it support enough? : o


What kind of commands has everyone made using this? ; D

I really did spend a very long time on the tutorial and code, so I'd love to hear about any stories/projects/ w/e ^_-.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Made a small update to the pop command to destroy internal stacks when popping off a stack.

From
JASS:
        public method pop takes nothing returns thistype
            //recycle node
            set stackRecycle[stackRecycleCount] = this
            set stackRecycleCount = stackRecycleCount + 1
            return next
        endmethod

To
JASS:
        public method pop takes nothing returns thistype
            //recycle node
            set stackRecycle[stackRecycleCount] = this
            set stackRecycleCount = stackRecycleCount + 1

            //if node is a pointer to a stack, destroy the stack it points to
            if (type == StringType.STACK) then
                call stack.destroy()
            endif
            return next
        endmethod

The learning map has v2.2.2.1 as this bug does not disable the learning map from working.
 
Level 7
Joined
Dec 3, 2006
Messages
339
I think I could use this to save several data type reals in shorter space but i'd like some help. For example if i wanted to save 4 reals for damage to every certain race; orc,human, nightelf, and undead. Is it possible to save it like "O1.00H2.00N1.00U1.00" and then have functions that also set say the "1.00" after "O".
I could also settle for help just setting the 4 reals in a string without the letters like "O" or "N", etc.

Or should I just make my own if then checks and whatnot for this stuff?

Edit: I have read some of the tutorial but i think it's still quite a bit over my head especially since it's focusing on certain things that are common commands like -give 100 , -color green,(which of some i did understand) and it is not what i am trying to do.

Edit2:I mean i think i need to use a Stack, but i get lost half way through chapter 7 around where it says: "Really, there are many many ways to handle stacks within stacks" I think that should split into another chapter sorta, and in chapter 7 there should have been more explanation on how to use single stacks. Any help would be much appreciated thanks.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Er, the -give and -color are just very basic commands. If you go down to the last chapter, you'll see how advanced some of this stuff gets.

And yes, your command can be easily done with String Parser, although you'll have to put in spaces.

->O 1.00 H 2.00 N 1.00 U 1.00

O, H, N, and U would be treated as variables of data type race if I'm not mistaken? : )

You could also easily pass in
->O 1 H 2 N 1 U 1

And the values would still be interpreted as reals.

If you want the O, H, N, and U vars, you'll have to go down until you learn how to create data types and data values.

Happily, your command doesn't require the last chapter, which is insaneness o-o.

So yes, work your way down through chapter 6. If you really want to, you can do chapter 7 as well, but you don't need it for what you are trying to do :).


Chapter 6 teaches you do stuff like this
Code:
type color extends string
type playercolor extends color

And chapter 5 teaches you how to do this
Code:
playercolor red
playercolor blue
color black

So if I were to type in black, it'd be interpreted as a color and it'd have a value stored inside of it.

You'd probably do
Code:
type race extends string

race O
race U
race H
race N

Then you could do like
local StringStack stack = String.Parse("O 1 U 2.53 H 1.2424 N 16")

or

local StringStack stack = String.Parse("O,1 U,2.53 H,1.2424 N,16")

or w/e ; P, the comma is treated the same way as a space :)

edit
Work the chapters in order**

edit 2
You should probably start the command with a dash : )
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Read the tutorial, that's what it was written for. Chapter 7 goes into how that stuff works.

If you read it, you'll realize you can do stuff like this too ((()()(()()))()()(()())))

Chapter 7 primarily goes over how to loop over infinite items with infinite depth.

Just learn String Parser >: P; there's a huge in-depth tutorial on the first post ;).
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Yeah I don't see this happening without vJass on my PC. Currently running blank WC3 editor... can't download from wc3c.net because the file is corrupted and Anachron's download didn't contain the full version for me. Any chance I can get you to pastebin the jasshelper + JNGP files to me?

Also, String.filter's boolean, shouldn't it be both for leading as well as trailing characters?
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Level 31
Joined
Jul 10, 2007
Messages
6,306
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
 
Last edited:
Level 10
Joined
May 27, 2009
Messages
494
currently reading the documentation/tutorial and currently my mind is in circles :D

uhm, is it possible to get something from a list of string, like for example, if a user type asdf, the code will look for a pre-specified string and if for example, as is in the pre-specified string, then return true?? just like a game mode
specified string could be "as df" separated by spaces,
yeah it should work like a game mode parser, wherein entering like -apnp, the "-" will be removed (as seen from the 1st post) then parse "apnp" and check those if it matches a string from a pre-specified string list :D
can you make 1??
(sorry if this looks kinda a necropost)
haven't really gone through the code though... and its APIs, i'm not good at understanding too much weird codes atm :D
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Not at all a necro post. No such thing as necro posts for resources ;p.

For the apnp, you'd need spaces in there (ap np). W/o the spaces, it can't tell. If I added super types, it would be able to tell, but I haven't really wanted to add them ;o, lol. If you look above, some people wanted to make a calculator with this, meaning I'd have to add super types so that it could parse 1+2 instead of forcing 1 + 2.

So for your list, it'd be -ap np unless you really want me to add super types ;p.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
the super types would be quite a bit of extra overhead =).

Super types are like types of types. For example, one super type might be operators and another one might be labels. Operators can go next to labels, but labels can't be next to labels. You can sort of hackishly pull off what you want by making each mode a dif super type (super type mode 1, type mode 1, value ar) for example. It's a bit overkill, but using the current system, that's how it'd be done.

So anyways, notice these 2 super types (value and operator)
1+1

If the 1 and 1 were next to each other, it'd be the value 11 (why things of the same super type can't be together), but with the operator in between, it is known.

You could also have value, label, and operator super types
1add3

for example =D.
 
Level 10
Joined
May 27, 2009
Messages
494
well they are just string types, i don't care integers/reals wutever but it would work like php script if its possible, getting a string for a list of string arrays (e.g. "1 2" delimiter of a " ") or maybe you could provide a little snippet to it out of the main script :D

edit

well, hmm, can filter can be used?? so for example, for each 2 chars, add space?? so it can be parsed properly?
 
Level 10
Joined
May 27, 2009
Messages
494
oh yeah, but maybe maskedpoptart's string library can do the job?? my problem is, i'm having a hard time in the implementation / calling function state wherein this library can do that but the problem is you need spaces D:

hope you can add super types even its pain in your brain :D

anyways thanks!
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Well, you shouldn't use this library unless you really need the features. It's really overkill for what you want ;p.

For example, I created this more for type checking with commands, like giving a player gold =). Sure, you could use it for type checking on modes, but the modes are pretty simple in the first place if you write code that is optimal for it. For example, let's say that all modes are exactly two characters long, then you don't need spaces in the slightest because you know exactly what to look for. If they are between 2 and 3, same deal. This is more if something is of a variable length, entirely unknown. For example, look at that insane stack thing in chapter 7 =p, or the player colors.
 
Top