Exemplo n.º 1
0
def value_to_carry(score):
    '''Replaces subsequent repeated values with a carry (.)
    
    Identical expressions do no carry, as a carry only copies the first
    value output from an expression.  This breaks the form when multiple
    random evaluations are part of the score.
    
    Macros do no carry as they may contain expressions.
    
    No-carries are not carried.
    '''

    event_list = score.splitlines(True)
    last_identifier = None
    last_values = []
    output = []

    # Explicitly state pfield 3 instead a magic number.  Carry
    # statements only substitute for pfields 3 or higher.
    PFIELD_3 = 3

    # Excluded element token types
    elements = [element.EXPRESSION, element.MACRO, element.NO_CARRY]

    for e in event_list:
        if event.match(e, {0: 'i', 1: last_identifier}):
            lolv = len(last_values)

            for i in range(PFIELD_3, max(event.number_of_pfields(e), lolv)):
                this_pfield = event.get(e, i)

                # Detect NO_CARRY
                if element.token_type(this_pfield) == element.NO_CARRY:
                    last_values[i] = this_pfield
                    break

                elif element.token_type(last_values[i]) == element.NO_CARRY:
                    break

                # Replace pfield with carry
                elif (this_pfield == last_values[i]
                      and element.token_type(this_pfield) not in elements):
                    e = event.set(e, i, '.')

                # Add a carry if one does not exist
                elif this_pfield == None:
                    e = event.push(e, '.')

                else:
                    last_values[i] = this_pfield

            output.append(e)

        else:
            last_identifier = event.get(e, 1)
            last_values = event.get_pfield_list(e)
            output.append(e)

    return ''.join(output)
Exemplo n.º 2
0
def value_to_carry(score):
    '''Replaces subsequent repeated values with a carry (.)
    
    Identical expressions do no carry, as a carry only copies the first
    value output from an expression.  This breaks the form when multiple
    random evaluations are part of the score.
    
    Macros do no carry as they may contain expressions.
    
    No-carries are not carried.
    '''
    
    event_list = score.splitlines(True)    
    last_identifier = None
    last_values = []
    output = []

    # Explicitly state pfield 3 instead a magic number.  Carry
    # statements only substitute for pfields 3 or higher.
    PFIELD_3 = 3

    # Excluded element token types
    elements = [element.EXPRESSION, element.MACRO, element.NO_CARRY];
    
    for e in event_list:
        if event.match(e, {0: 'i', 1: last_identifier}):
            lolv = len(last_values)

            for i in range(PFIELD_3, max(event.number_of_pfields(e), lolv)):
                this_pfield = event.get(e, i)

                # Detect NO_CARRY
                if element.token_type(this_pfield) == element.NO_CARRY:
                    last_values[i] = this_pfield
                    break
                    
                elif element.token_type(last_values[i]) == element.NO_CARRY:
                    break
                    
                # Replace pfield with carry
                elif (this_pfield == last_values[i] and
                      element.token_type(this_pfield) not in elements):
                    e = event.set(e, i, '.')
                    
                # Add a carry if one does not exist
                elif this_pfield == None:
                    e = event.push(e, '.')
                    
                else:
                    last_values[i] = this_pfield

            output.append(e)
            
        else:
            last_identifier = event.get(e, 1)
            last_values = event.get_pfield_list(e)
            output.append(e)
        
    return ''.join(output)
Exemplo n.º 3
0
def test(n, event, fill, expect):
    result = s.push(event, fill)
    did_pass = result == expect

    return did_pass, n, 'push()', str(expect), str(result)
Exemplo n.º 4
0
def test(n, event, fill, expect):
    result = s.push(event, fill)
    did_pass = result == expect

    return did_pass, n, 'push()', str(expect), str(result)