Пример #1
0
/**
 * compilerkit_alpha_numeric_character_class_new:
 * @fn compilerkit_alpha_numeric_character_class_new
 *
 * Constructs an alphanumeric character class object (internally the equivalent CompilerKitAlternation).
 * 
 * For example, `compilerkit_character_class_new('0','z')` produces the regex `[0-9A-Za-z]`.
 * Note that only alphanumeric characters will be included in the character class, and nothing else.
 *
 * @pre None.
 * @param gunichar `lo` The low end of the character class. If this is `'\0'`, `lo` is the next higher character.
 * @param gunichar `hi` The high end of the character class. If this is `'\0'`, return the empty string.
 * @return GObject* a pointer to the new character class regex, or NULL if `lo` or `hi` are non-alphanumeric.
 */
GObject* compilerkit_alpha_numeric_character_class_new(gunichar lo, gunichar hi)
{
    GObject *result;
    if (!compilerkit_character_is_alpha_numeric(lo)) return NULL;
    if (!compilerkit_character_is_alpha_numeric(hi)) return NULL;
    
    sort_chars (&lo, &hi);

    result = compilerkit_empty_set_get_instance ();
    if (lo <= '9' && hi >= 'A')
    {
        result = compilerkit_character_class_new (lo, '9');
        lo = 'A';
    }
    if ('A' <= lo && lo <= 'Z' && hi >= 'a')
    {
        result = compilerkit_alternation_new (result, compilerkit_character_class_new (lo, 'Z'));
        lo = 'a';
    }
    if ('a' <= lo)
    {
        result = compilerkit_alternation_new (result, compilerkit_character_class_new (lo, hi));
    }
    return result;
}
Пример #2
0
/**
 * test_visitor_null_visit:
 * @fn test_visitor_null_visit
 * Tests whether compilerkit_visitor_visit produces appropriate results in the CompilerKitVisitor struct.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_null_visit(void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor* visitor;

    g_test_message ("Testing visitor null visits");
    g_test_timer_start ();

    symbol = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor = check_symbol();

    // Assert that visitor produces the correct result
    g_assert(compilerkit_visitor_visit(visitor, symbol) == symbol);

    // NULL objects will produce NULL
    g_assert(compilerkit_visitor_visit(visitor, NULL) == NULL);

    // Nothing registered for empty set, so return NULL
    g_assert(compilerkit_visitor_visit(visitor, empty_set) == NULL);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Пример #3
0
/**
 * test_visitor_register_identity:
 * @fn test_visitor_register_identity
 * Tests whether compilerkit_visitor_register_identity function works as intended.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_register_identity (void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor *visitor;

    g_test_message ("Testing visitor register identity");
    g_test_timer_start ();

    symbol    = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor   = compilerkit_visitor_new();

    // Register the identity function (it returns whatever GObject* gets as a parameter during the visit)
    compilerkit_visitor_register_identity (visitor, COMPILERKIT_TYPE_EMPTY_SET);

    // Since we didn't register the symbol, the visitor should return NULL
    g_assert (compilerkit_visitor_visit (visitor, symbol) == NULL);

    // The visitor should produce symbol here, since we registered the identity function for the symbol class.
    g_assert (compilerkit_visitor_visit (visitor, empty_set) == empty_set);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Пример #4
0
/** @todo Describe what task main will accomplish. */
int main (int argc, char ** argv)
{
    CompilerKitEmptySet* empty_set;
    g_type_init();
    
    empty_set = compilerkit_empty_set_get_instance();
    
    g_object_unref (empty_set);
}
Пример #5
0
int main (int argc, char ** argv)
{
    GObject* complement;
	GObject* rejectingRegex;
    g_type_init();
    
    complement = compilerkit_complement_new(compilerkit_empty_set_get_instance());//creates a complement object that accepted anything but the given regex
																				  //in this case, it will accept anything except the empty set
    rejectingRegex = compilerkit_complement_get_node(complement);//returns the regex which should be rejected

    g_object_unref (complement);
}
Пример #6
0
/**
 * test_concatenation_constructor_empty_set:
 * @fn test_concatenation_constructor_empty_set
 * Tests compilerkit_concatenation_new in CompilerKitConcatenation struct when either side is an empty set.
 * @pre None
 * @param None
 * @return void
 */
void test_concatenation_constructor_empty_set (void)
{
	GObject* ckc;
	GObject* left;
	GObject* right;

    g_test_message ("Testing concatenation constructor when either side is an empty set");
    g_test_timer_start ();

	// Right parameter is EmptySet
    {
        left = compilerkit_symbol_new('a');
        right = compilerkit_empty_set_get_instance ();
        ckc = compilerkit_concatenation_new(left,right);

        // Assert that ckc is the empty set, and that emptyset is a singleton.
        g_assert (right == ckc);
        g_assert(COMPILERKIT_IS_EMPTY_SET(ckc));

        g_object_unref (left);
        g_object_unref (right);
    }

	// Left parameter is EmptySet
    {
        left = compilerkit_empty_set_get_instance();
        right = compilerkit_symbol_new('a');
        ckc = compilerkit_concatenation_new(left,right);

        // Assert that concatenation is returning the empty set here.
        g_assert (ckc == left);
        g_assert (COMPILERKIT_IS_EMPTY_SET(ckc));

        g_object_unref (left);
        g_object_unref (right);
    }

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_derivative_visitor:
 * @fn test_derivative_visitor
 * Tests compilerkit_derivative_visitor.
 * @pre None
 * @param None
 * @return void
 */
void test_derivative_visitor (void)
{
    CompilerKitVisitor *derivative;
    GObject *regex, *new_regex;
	//GObject *symbol, *cat, *star;	/** @todo these are currently unused */
    
    g_test_message ("Testing Derivative visitor");
    g_test_timer_start ();
    
    derivative = compilerkit_derivative_visitor();
    regex = compilerkit_symbol_new ('h');
    
    // When we match a single character, h, against the single character 'h', we should get the empty string, because they match.
    new_regex = compilerkit_derivative_apply_char (derivative, regex, 'h');
    g_assert (new_regex == compilerkit_empty_string_get_instance());
    
    // When we match a single character, h, against the single character 'e', we should get the empty set, because they don't match.
    new_regex = compilerkit_derivative_apply_char (derivative, regex, 'e');
    g_assert (new_regex == compilerkit_empty_set_get_instance());
    
    // When we match a single character, h, against a string, we should get the empty set, because they don't match.
    new_regex = compilerkit_derivative_apply_string (derivative, regex, "hello");
    g_assert (new_regex == compilerkit_empty_set_get_instance());
    
    // When we match "hi!" against the string "hi", we should get the symbol "!", because that's what remains.
    regex = compilerkit_concatenation_new (regex, compilerkit_concatenation_new (compilerkit_symbol_new ('i'), compilerkit_symbol_new ('!')));
    new_regex = compilerkit_derivative_apply_string (derivative, regex, "hi");
//    g_warn_if_fail (g_type_name(G_OBJECT_TYPE(new_regex)));
//    g_assert (COMPILERKIT_IS_SYMBOL (new_regex));
//    g_assert (compilerkit_symbol_get_symbol(COMPILERKIT_SYMBOL(new_regex)) == '!');
    
    g_object_unref (derivative);
    g_object_unref (regex);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Пример #8
0
/**
 * compilerkit_concatenation_new:
 * @fn compilerkit_concatenation_new
 * @memberof CompilerKitConcatenation
 * Construct a CompilerKitConcatenation instance.
 * @pre GObject* are all non NULL.
 * @param GObject* Left side of concatenation
 * @param GObject* Right side of concatenation
 * @return A new CompilerKitConcatenation struct if concatenation is necessary otherwise return the single element or EmptySet.
 */
GObject *compilerkit_concatenation_new (GObject *left, GObject *right)
{
	CompilerKitConcatenation* result;

	if (COMPILERKIT_IS_EMPTY_SET(left) || COMPILERKIT_IS_EMPTY_SET(right)) // If left or right is EmptySet
		return compilerkit_empty_set_get_instance();
	if (COMPILERKIT_IS_EMPTY_STRING(left)) // If left is EmptyString, return right
		return right;
	if (COMPILERKIT_IS_EMPTY_STRING(right)) // If right is EmpltyString, return left
		return left;

    result = COMPILERKIT_CONCATENATION (g_object_new (COMPILERKIT_TYPE_CONCATENATION, NULL));
    result->priv->left = left;
    result->priv->right = right;
    return G_OBJECT(result);
}
Пример #9
0
/**
 * test_kleene_star_constructor:
 * @fn test_kleene_star_constructor
 * Tests compilerkit_kleene_star_new in CompilerKitKleeneStar struct.
 * @pre None
 * @param None
 * @return void
 */
void test_kleene_star_constructor (void)
{
	GObject* e_set;
	GObject* e_string;
	GObject* a;
	GObject* result;
	
	
    g_test_message ("Testing KleeneStar method");
    g_test_timer_start ();
	
	
	//empty set
	{
	
		e_set = compilerkit_empty_set_get_instance();
		result = compilerkit_kleene_star_new(e_set);
		g_assert(COMPILERKIT_IS_EMPTY_SET (result));
        g_object_unref (result);
	}
	
	//empty string
	{
		e_string = compilerkit_empty_string_get_instance();
		result = compilerkit_kleene_star_new(e_string);
		g_assert(COMPILERKIT_IS_EMPTY_STRING (result));
        g_object_unref (result);
	}
	
	//symbol
	{
		a = compilerkit_symbol_new('a');
		result = compilerkit_kleene_star_new(a);
		g_assert(COMPILERKIT_IS_KLEENE_STAR (result));
        g_object_unref (result);
	}
    
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}