Discussion Different Commander Parser

released:
parser http://www.thehelper.net/forums/showthread.php?t=152352
Cmd http://www.thehelper.net/forums/showthread.php?t=152356

So this is the current one-
http://www.thehelper.net/forums/showthread.php?t=140936

I don't like it... for example, it's many isType and getType methods irritate me and the fact that it couples up the parser and the command manager just seems like an extremely poor design to me >.<..

So, I've been working on a 2 part project-
parser (highly customizable) (done)
command framework (support for different shells and etc)

The parser includes a string stack object that will automatically split a string up into a stack given a delimhttp://www.thehelper.net/forums/forumdisplay.php?f=109iter, a typeof to automatically infer the data type of a given string ('' is treated as ascii and rest are inferred based upon the values). For the most part, types fit into other types. For example, an integer can be treated as a real or a string (follows this hierarchy on data types).

JASS:
struct StringType extends array
        public static constant integer NULL = 0
        public static constant integer BOOLEAN = 1
        public static constant integer ASCII = 2
        public static constant integer INTEGER = 3
        public static constant integer REAL = 4
        public static constant integer STRING = 5


names can also be printed given a type id
JASS:
////
        public static method operator [] takes integer t returns string
            return typeNames[t]
        endmethod


The typeof method automatically infers types (as I said above)
JASS:
/////
        public static method typeof takes string val returns integer
            local integer length
            local string char
            local integer curType = NULL
            local string boolChecker
            local boolean foundDecimal
            
            //make sure not null
            if (val != null) then
                set curType = BOOLEAN
                //check to see if boolean
                set boolChecker = StringCase(val, false)
                if (boolChecker != &quot;true&quot; and boolChecker != &quot;false&quot;) then
                    set length = StringLength(val)
                    set curType = ASCII
                    
                    //check to see if ascii integer
                    if ((length != 3 and length != 6) or (SubString(val, 0, 1) != &quot;'&quot; or SubString(val, length-1, length) != &quot;'&quot;)) then
                        set curType = INTEGER
                        
                        //if curType can't be determined at this point, have to parse it
                        set foundDecimal = false
                        loop
                            exitwhen length == 0
                            set char = SubString(val, length-1, length)
                            if (char != &quot;0&quot; and char != &quot;1&quot; and char != &quot;2&quot; and char != &quot;3&quot; and char != &quot;4&quot; and char != &quot;5&quot; and char != &quot;6&quot; and char != &quot;7&quot; and char != &quot;8&quot; and char != &quot;9&quot;) then
                                if (char == &quot;.&quot; and not foundDecimal) then
                                    set curType = REAL
                                    set foundDecimal = true
                                else
                                    return STRING //no more parsing necessary
                                endif
                            endif
                            set length = length - 1
                        endloop
                    endif
                endif
            endif
            return curType
        endmethod


Obviously I'm still going to be doing some more stuff, but this is how I believe a Parser should be designed ; |. CommandParser is designed in such a way that I refuse to use it, lol.

also, I'm going to do different build strings for the StringStack struct (single argument builds for ripping specific types out of the string and etc).


example of use (with just the parser) (I know I have a ton of extra locals, lol) (uses default delimiter on the StringStack creation)
JASS:
struct tester extends array
    private static trigger t = CreateTrigger()
    private static string array typeName
    
    private static method test takes nothing returns boolean
        //call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, SubString(GetEventPlayerChatString(), 0, 1))
        //call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, SubString(GetEventPlayerChatString(), StringLength(GetEventPlayerChatString())-1, StringLength(GetEventPlayerChatString())))
        local StringStack stringStack = StringStack.create(GetEventPlayerChatString())
        local StringStack node = stringStack
        local integer stringType
        
        local boolean b
        local integer a
        local integer i
        local real r
        local string s
        
        local string bs
        local string as
        local string is
        local string rs
        local string ss
        
        local string value
        loop
            exitwhen node == 0
            set value = node.value
            set stringType = StringType.typeof(value)
            
            if (stringType == StringType.NULL) then
                set s = value
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + s)
            elseif (stringType == StringType.BOOLEAN) then
                set b = StringType.S2B(value)
                set bs = StringType.B2S(b)
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + bs)
            elseif (stringType == StringType.ASCII) then
                set a = StringType.S2A(value)
                set as = StringType.A2S(a)
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + as)
            elseif (stringType == StringType.INTEGER) then
                set i = S2I(value)
                set is = I2S(i)
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + is)
            elseif (stringType == StringType.REAL) then
                set r = S2R(value)
                set rs = R2S(r)
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + rs)
            elseif (stringType == StringType.STRING) then
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, StringType[stringType] + &quot;: &quot; + value)
            endif
            
            //set node = node.next
            set node = node.pop()
        endloop
        
        //call stringStack.destroy()
        return false
    endmethod
    
    private static method onInit takes nothing returns nothing
        call TriggerRegisterPlayerChatEvent(t, Player(0), &quot;&quot;, false)
        call TriggerAddCondition(t, Condition(function thistype.test))
    endmethod
endstruct


ripper code
for single argument commands (provides more flexibility)
JASS:
////
        //rips out a single argument given a type
        //slow but extremely flexible
        public static method rip takes string val, integer typeToRip returns string
            local string arg = &quot;&quot;
            local integer length
            local integer count
            local string char
            local integer argLength
            local integer boolCount
            local boolean foundDecimal
            
            if (val != null) then
                set length = StringLength(val)
                set count = 0
                
                //rip null, which is easy, lol
                if (typeToRip == StringType.NULL) then
                    set arg = null
                //rip boolean, which tries to piece together straight** chars that could build boolean
                elseif (typeToRip == StringType.BOOLEAN) then
                    set boolCount = 0
                    loop
                        exitwhen count == length
                        set char = SubString(val, count, count+1)
                        if (boolCount == 0) then
                            if (char == boolChars[trueChar]) then
                                set boolCount = trueChar+1
                                set arg = char
                            elseif (char == boolChars[falseChar]) then
                                set boolCount = falseChar+1
                                set arg = char
                            endif
                        elseif (char == boolChars[boolCount]) then
                            set arg = arg + char
                            set boolCount = boolCount + 1
                            exitwhen arg == &quot;true&quot; or arg == &quot;false&quot;
                        else
                            set boolCount = 0
                            set arg = &quot;&quot;
                        endif
                        set count = count + 1
                    endloop
                    if (arg != &quot;true&quot; and arg != &quot;false&quot;) then
                        set arg = null
                    endif
                //rip out an ascii value, which rips out the first 3 to 6 possible chars it comes across
                elseif (typeToRip == StringType.ASCII) then
                    set foundDecimal = false //found ' ?
                    set argLength = 0
                    loop
                        exitwhen count == length or argLength == 6
                        set char = SubString(val, count, count+1)
                        set argLength = StringLength(arg)
                        //find start
                        if (argLength == 0 or argLength == 5 and char == &quot;'&quot;) then
                            set arg = arg + &quot;'&quot;
                        elseif (argLength &gt; 0 and argLength &lt; 5) then
                            if (argLength == 2 and char == &quot;'&quot;) then
                                set foundDecimal = true
                            endif
                            set arg = arg + char
                        endif
                        set count = count + 1
                    endloop
                    set argLength = StringLength(arg)
                    //if maxed ascii and no final &quot;'&quot;, check for previous one
                    if (argLength == 5 and foundDecimal) then
                        set arg = SubString(arg, 0, 2) + &quot;'&quot;
                    elseif (argLength != 6 or (argLength != 3 and SubString(arg, argLength-1, argLength) != &quot;'&quot;)) then
                        set arg = null
                    endif
                //rips out a plain old integer
                elseif (typeToRip == StringType.INTEGER) then
                    loop
                        exitwhen count == length
                        set char = SubString(val, count, count+1)
                        if (char == &quot;0&quot; or char == &quot;1&quot; or char == &quot;2&quot; or char == &quot;3&quot; or char == &quot;4&quot; or char == &quot;5&quot; or char == &quot;6&quot; or char == &quot;7&quot; or char == &quot;8&quot; or char == &quot;9&quot;) then
                            set arg = arg + char
                        endif
                        set count = count + 1
                    endloop
                    if (arg == &quot;&quot;) then
                        set arg = null
                    endif
                //rips out a real
                elseif (typeToRip == StringType.REAL) then
                    set foundDecimal = false
                    loop
                        exitwhen count == length
                        set char = SubString(val, count, count+1)
                        if (char == &quot;.&quot; and not foundDecimal) then
                            set foundDecimal = true
                            set arg = arg + char
                        elseif (char == &quot;0&quot; or char == &quot;1&quot; or char == &quot;2&quot; or char == &quot;3&quot; or char == &quot;4&quot; or char == &quot;5&quot; or char == &quot;6&quot; or char == &quot;7&quot; or char == &quot;8&quot; or char == &quot;9&quot;) then
                            set arg = arg + char
                        endif
                        set count = count + 1
                    endloop
                    if (arg == &quot;&quot;) then
                        set arg = null
                    endif
                else
                    set arg = val
                endif
            endif
            
            return arg
        endmethod


and how you might use the above
[ljass]local string arg = StringType.rip(GetEventPlayerChatString(), StringType.ASCII)[/ljass]
 

Jesus4Lyf

Good Idea™
Well done? Another failure interface? :(
I don't like it...
...
So, I've been working on a 2 part project
If you're looking to submit something and get approved, that's really not how things are done around here... you post in the thread when you don't like it, instead of jumping to remake it. :)
 
If you're looking to submit something and get approved, that's really not how things are done around here... you post in the thread when you don't like it, instead of jumping to remake it.
I'm very impatient. I'd rather rewrite it than wait for an unknown period of time for a response =P. Even 1 day on a response is too long for me = ).

oh, and how does the API fail? : o.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    Also fixed a bug, where I prevented the CPU fans from spinning wildly if I reverse the order of rendering and updating function calls in Pokemon Walking
  • The Helper The Helper:
    Is that going to be a full game now tom?
  • The Helper The Helper:
    what is this Ghan? https://enterprise.ghannet.com/ you are totally holding out on us my friend
  • Ghan Ghan:
    Not mine, I just ran the server. They let the domain expire but it was a cool project so I kept it alive there.
  • Ghan Ghan:
    Used to be enterpriserpg.com I think.
  • The Helper The Helper:
    If you go to the world editor tutorials site and click the starcraft link it takes you there :)
  • Ghan Ghan:
    lol
  • Ghan Ghan:
    I forgot about that alias name. (The full URL still went to the correct site.) That should be fixed.
  • Ghan Ghan:
    Silkroad Forums site really needs help.
  • Ghan Ghan:
    Its software has been out of support since 2017.
  • Ghan Ghan:
    The woes of using custom styles....
  • The Helper The Helper:
    does anyone still use silk road forums?
  • Ghan Ghan:
    It's about as active as here I'd say. Not much going on.
  • Wizard Wizard:
    I think it doesn't help that the silk road game isn't as popular any more I think. The only MMO I play these days is FFXIV like most other people I know.
  • The Helper The Helper:
    I checked a status page for players and it says the game has 500 daily players.
  • The Helper The Helper:
    I cannot believe that site is still going I wonder if Ryoko is involved with it at all would love to talk to him again and see what he is up to
  • The Helper The Helper:
    my oldest daughter failed her driving test today for her license she is 22 and yes I have been driving her everywhere her whole life
  • The Helper The Helper:
    Now they are blaming me on Facebook for her failure LOL I am accepting it because it is my failure I am her driving teacher even though she had certified driving instruction from the best place in town I for some reason cannot teach her how to drive this is frustrating
  • jonas jonas:
    I didn't get my license until I was 25
    +1
  • The Helper The Helper:
    Back in the old days when I was getting a license people were getting them at 16 yrs old and many were getting hardships so they could get them earlier. Almost nobody did not drive when they were able. Nowadays though....
  • Ghan Ghan:
    Why drive when there's Uber Eats?
    +2
  • The Helper The Helper:
    I hope Varine is OK have not heard from him in a while.
    +1
  • Ghan Ghan:
    Diablo 2 Resurrected launching in 9 days.
  • The Helper The Helper:
    Just got a new to me computer hope it will run it

    Members online

    Affiliates

    Hive Workshop NUON Dome
    Top