void AST_t::replace(AST_t ast)
    {
        if (ast._ast == NULL)
        {
            internal_error("Trying to replace a tree with an empty tree", 0);
        }

        if (this->_ast == NULL)
        {
            internal_error("Trying to replace an empty tree with another tree", 0);
        }

        if (ASTType(ast._ast) == AST_NODE_LIST)
        {
            // If the replacement is a list but the original is not, let's check two cases
            // maybe this list is a one-element list or not.
            if (ASTType(this->_ast) != AST_NODE_LIST)
            {
                // If it is a one element list
                if (ASTSon0(ast._ast) == NULL)
                {
                    // then replace the whole thing with the list information
                    AST_t repl_tree(ASTSon1(ast._ast));
                    replace_with(repl_tree);
                }
                // If this is not a one-element list then try to replace using
                // a typical replace_in_list but this may fail sometimes
                // because we'll look for the first enclosing list
                else 
                {
                    // Maybe we should yield a message here
                    // std::cerr << "Warning: Replacing a non-list tree at '" 
                    //     << this->get_locus() 
                    //     << "' with a list tree of more than one element" << std::endl;
                    replace_in_list(ast);
                }
            }
            // If both are lists is easy
            else
            {
                replace_in_list(ast);
            }
        }
        // If the thing being replaced is a list, but the replacement
        // is not, then convert the latter into a list
        else if (ASTType(_ast) == AST_NODE_LIST
                && ASTType(_ast) != AST_NODE_LIST)
        {
            // Create a single element list
            AST single(ASTListLeaf(ast._ast));
            replace_in_list(single);
        }
        // Otherwise replace directly. Neither the replaced nor the replacement
        // are lists in this case.
        else
        {
            replace_with(ast);
        }
    }
Example #2
0
File: lt.c Project: kdomen/test
void LTA(char *buf, char *word) {
    char tmp_buf[128];

    strcpy(buf, word);
    remove_punctuation(buf);
    
    replace_with(tmp_buf, buf, "ight", "ite");

    /* Don't process words 4 letters or under */
    if (strlen(buf) <= 5) return;

    buf[0] = word[0];
    remove_vowels(buf);
}
Example #3
0
*/	void Trim_String(REBSER *ser, REBCNT index, REBCNT len, REBCNT flags, REBVAL *with)
/*
***********************************************************************/
{
	REBCNT tail = index + len;

	// /all or /with
	if (flags & (AM_TRIM_ALL | AM_TRIM_WITH)) {
		replace_with(ser, index, tail, with);
	}
	// /auto option
	else if (flags & AM_TRIM_AUTO) {
		trim_auto(ser, index, tail);
	}
	// /lines option
	else if (flags & AM_TRIM_LINES) {
		trim_lines(ser, index, tail);
	}
	else {
		trim_head_tail(ser, index, tail, flags & AM_TRIM_HEAD, flags & AM_TRIM_TAIL);
	}
}