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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top