/** * 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; }
/** * 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); }
void test_convenience_alternation(void) { GObject* expression1 = compilerkit_character_class_new('0','h'); GObject* expression2 = compilerkit_character_class_new(33,'h'); GObject* expression3 = compilerkit_character_class_new('0',137); g_assert(expression1 != NULL); g_assert(expression2 == NULL); g_assert(expression3 == NULL); g_object_unref(expression1); g_object_unref(expression2); g_object_unref(expression3); }
/** @todo Describe what task main will accomplish. */ int main (int argc, char ** argv) { CompilerKitScanner* scanner; CompilerKitToken *token; g_type_init(); scanner = compilerkit_scanner_new(); // Specify lexical structure of the language. compilerkit_scanner_register(scanner, compilerkit_token_new("IDENTIFIER"), compilerkit_positive_closure_new(compilerkit_character_class_new('A','Z'))); // Attach it to a parser compilerkit_scanner_open_filename(scanner, "scanner-demo.c"); while (token = compilerkit_scanner_next_token(scanner)) { // do something with the token } compilerkit_scanner_close_file(scanner); g_object_unref (scanner); }
/** * compilerkit_regex_digits: * @fn compilerkit_regex_digits * * Return a character class corresponding to `[0-9]` * * @pre None * @param None * @return GObject* regex that matches the digits 0 through 9. */ GObject *compilerkit_regex_digits() { return compilerkit_character_class_new('0', '9'); }
/** * compilerkit_regex_whitespace: * @fn compilerkit_regex_whitespace * * Return a character class corresponding to all whitespace. * * @pre None * @param None * @return GObject* regex that matches all whitespace. */ GObject *compilerkit_regex_whitespace(void) { return compilerkit_character_class_new(' ', ' ');; }
/** * compilerkit_regex_upper: * @fn compilerkit_regex_upper * * Return a character class corresponding to `[A-Z]` * * @pre None * @param None * @return GObject* regex that matches the symbols A through Z. */ GObject *compilerkit_regex_upper(void) { return compilerkit_character_class_new('A', 'Z'); }
/** * compilerkit_regex_lower: * @fn compilerkit_regex_lower * * Return a character class corresponding to `[a-z]` * * @pre None * @param None * @return GObject* regex that matches the symbols a through z. */ GObject *compilerkit_regex_lower(void) { return compilerkit_character_class_new('a', 'z'); }