Discussion Different Commander Parser

Nestharus

o-o
Reaction score
84
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;&#039;&quot; or SubString(val, length-1, length) != &quot;&#039;&quot;)) then
                        set curType = INTEGER
                        
                        //if curType can&#039;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 &#039; ?
                    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;&#039;&quot;) then
                            set arg = arg + &quot;&#039;&quot;
                        elseif (argLength &gt; 0 and argLength &lt; 5) then
                            if (argLength == 2 and char == &quot;&#039;&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;&#039;&quot;, check for previous one
                    if (argLength == 5 and foundDecimal) then
                        set arg = SubString(arg, 0, 2) + &quot;&#039;&quot;
                    elseif (argLength != 6 or (argLength != 3 and SubString(arg, argLength-1, argLength) != &quot;&#039;&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™
Reaction score
397
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. :)
 

Nestharus

o-o
Reaction score
84
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top