/** * test_alternation_vlist_new: * @fn test_alternation_vlist_new * Tests method compilerkit_alternation_vlist_new in CompilerKitAlternation struct. * @pre None * @param None * @return void */ void test_alternation_vlist_new (void) { GObject* alt; GObject* one; GObject* two; GObject* three; g_test_message ("Testing Alternation vlist new"); g_test_timer_start (); one = compilerkit_symbol_new('a'); two = compilerkit_symbol_new('b'); three = compilerkit_symbol_new('c'); alt = compilerkit_alternation_vlist_new(one, two, three, NULL); g_assert (COMPILERKIT_IS_ALTERNATION(alt)); g_assert (one != two); g_assert (two != three); g_assert (one != three); g_assert (one != alt); g_assert (two != alt); g_assert (three != alt); g_assert (three == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(alt))); g_assert (one == compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt))))); g_assert (two == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt))))); g_object_unref (alt); // This will unref one, two and three as well g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1); }
int main (int argc, char ** argv) { GObject *alternationOne; GObject *alternationTwo; GObject *left; GObject *right; GObject *left_left; GObject *left_right; GObject *subAlternation; g_type_init(); alternationOne = compilerkit_alternation_new(compilerkit_symbol_new('a'),compilerkit_symbol_new('b')); // creates an alternation ('a' | 'b') alternationTwo = compilerkit_alternation_vlist_new(compilerkit_symbol_new('c'), compilerkit_symbol_new('d'), compilerkit_symbol_new('e'), NULL); //NULL terminated list of at least 2 GObjects //creates an alternation (('c' | 'd') | 'e') left = compilerkit_alternation_get_left(alternationOne); //returns the symbol 'a' right = compilerkit_alternation_get_right(alternationOne); //returns the symbol 'b' subAlternation = compilerkit_alternation_get_left(alternationTwo); //returns the alternation ('c' | 'd') left_left = compilerkit_alternation_get_left(compilerkit_alternation_get_left(alternationTwo)); //returns the symbol 'c' left_right = compilerkit_alternation_get_right(compilerkit_alternation_get_left(alternationTwo)); //returns the symbol 'd' right = compilerkit_alternation_get_right(alternationTwo); //returns the symbol 'e' g_object_unref (alternationOne); //Also de-references the parts (left and right) g_object_unref (alternationTwo); //Also de-references the parts (subAlternation, left_left, left_right, and right) }
/** * compilerkit_regex_punct: * @fn compilerkit_regex_punct * * Return a character class corresponding to all punctuation. * * @pre None * @param None * @return GObject* regex that matches all punctuation. */ GObject *compilerkit_regex_punct(void) { return compilerkit_alternation_vlist_new( compilerkit_character_class_new('!', '/'), compilerkit_character_class_new('@',':'), compilerkit_character_class_new('[','`'), compilerkit_character_class_new('{','~'), NULL); }