Paste #10028: Edit of P#10027 - mcmonkeys tag challenge

Date: 2014/09/23 22:51:27 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# Script that replaces predefined characters for their ASCII equivalents
# Utilizes a database to read from.

"Determine Word Replacement":
    #############################################################################################################################
    #                                                                                                                           #
    # Specific to the word replacement typing as it checks the sai database script for its values                               #
    #                                                                                                                           #
    #############################################################################################################################
    type: procedure
    definitions: word
    script:
    #Selective escaping
    - define replacement <def[word].replace[<&dot>].with[$dot$]>

    # made by reason of the root node
    # This script fails here as its got issues parsing tags within the wrong place (prob right after the 2nd '[')
    - define replacement <yaml[word_replacement].read[Replace.<def[replacement]>]>
    - define replacement <def[replacement].replace[$dot$].with[<&dot>]>
    - if <def[replacement]> != null {
        - define word <def[replacement]>
        }
    - determine <def[word]>



# The issue is where you start to add the arguments to this script as the <def[new_list]||li@>. The fallback fails or gets parsed
# diferently... but Ive checked. 
# edit: fixed the line -define bad_list... the first arg to list append right was the incorrect list reference.
List Append Right:
    #############################################################################################################################
    #                                                                                                                           #
    # Takes an escaped <escape:iterable>                                                                                        #
    # Takes a value to append to that iterable (can be another list :)   )                                                      #
    # Returns a list                                                                                                            #
    # notice: This escapes the return value. Youll NEED TO <unescape:> or <element.unescaped>IT FIRST!                          #
    #                                                                                                                           #
    # ex:                                                                                                                       #
    #   - define griefer_list <p@chemical_Datas>|<p@calico-kid>|<p@ghost_bawb>|<p@noobzilla>                                    #
    #   - foreach <def[griefer_list].as_list> {                                                                                 #
    #       - if !<def[value].is_op> {                                                                                          #
    #          - define bad_list "<proc[List Append Right].context[<def[bad_list]||li@>|<def[value]>]>"                         #
    #          }                                                                                                                #
    #       }                                                                                                                   #
    #  #in some other script that recieved a list from this.....                                                                #
    #   - foreach <def[bad_list].unescaped> {                                                                                   #
    #        - execute as_server "ban <def[value].name>"                                                                        #
    #        }                                                                                                                  #
    #                                                                                                                           #
    #############################################################################################################################
    debug: false
    type: procedure
    definitions: iterable|value
    script:
    - announce "iterable<&co> <blue><def[iterable]>"
    - define iterable <def[iterable].unescaped||none>
    - announce "iterable<&co> <blue><def[iterable]>"
    - if <def[iterable]> == none {
        - determine <def[value].unescaped.as_list.escaped||<li@.escaped>>
        } else {
        - determine <def[iterable].as_list.include[<def[value].unescaped.as_list||li@>].escaped>
        }


#edit: example: the 2nd time - define op_locations comes up, the procedure should be 'list append right' as that matches the way the args are passed to it.
#edit: example: the other fix is the first argument to the example definition op_locations. Changed from <escape:list> to <def[op_locations]||li@>
#edit: example: the list fix is the second argument to the example define op_locations. Changed <el@%value%.length> to <def[value].length> 
Transform List:
    #############################################################################################################################
    #                                                                                                                           #
    # The idea is that it takes a list then a string to apply to each element in that list                                      #
    #                                                                                                                           #
    #                                                                                                                           #
    # ex:                                                                                                                       #
    #  <server.list_online_ops>  | name                                                                                         #
    # turns it into a list of player names                                                                                      #
    # ex:                                                                                                                       #
    #  define op_locations "<proc[Transform List].context[''|<escape:<server.list_online_ops>>|location]>"                      #
    # instead of:                                                                                                               #
    #  - foreach <server.list_online_ops> {                                                                                     #
    #        - define op_locations "<proc[List Append Left].context[<escape:list>|<%value%.location>]>"                         #
    #        }                                                                                                                  #
    #                                                                                                                           #
    # - define name_length "<proc[Transform List].context[<escape:el@>|<escape:<server.list_online_players>>|length]>"          #
    # instead of:                                                                                                               #
    #  - foreach <server.list_online_players> {                                                                                 #
    #        - define op_locations "<proc[List Append Right].context[<def[op_locations]||li@>|<def[value].length>]>"            #
    #        }                                                                                                                  #
    #                                                                                                                           #
    #############################################################################################################################
    type: procedure
    definitions: precursor|list|transformer
    script:
    - define precursor "<def[precursor].unescaped||>"
    - foreach <def[list].unescaped.as_list> {
        - announce "before transformer <def[value]>"
        - define new_value <%precursor%%value%.%transformer%>
        - announce "after transformer <def[new_value]>"
        - define return "<proc[List Append Right].context[<def[return]||li@>|%new_value%]>"
        - announce "after list append <def[return].unescaped>"
        }
    - determine <def[return].unescaped>

tlist:
    type: procedure
    script:
    - determine "<proc[Transform List].context[|<server.list_online_players.escaped>|location|]>"