ident.h

Identifiers: [a-zA-Z0-9_]+.

An identifier is a sequence of characters. A character is one of:

  • digits (0123456789),

  • lowercase letters (abcdefghijklmnopqrstuvwxyz),

  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ),

  • the underscore character (_).

For example, here are identifiers: _ak39A, 192_iAjP_2, r9. But these are not identifiers: ~18nA, o78*, 3i#^hdd.

Defines

ML99_detectIdent(prefix, ident)

Tells whether ident belongs to a set of identifiers defined by prefix.

If ML99_cat(prefix, ident) exists, it must be an object-like macro which expands to (). If so, ML99_detectIdent(prefix, ident) will expand to truth, otherwise (ML99_cat(prefix, ident) does not exist), ML99_detectIdent(prefix, ident) will expand to falsehood.

Predefined detectors

  • ML99_UNDERSCORE_DETECTOR detects the underscore character (_).

Examples

#include <metalang99/ident.h>

#define FOO_x ()
#define FOO_y ()

// 1
ML99_detectIdent(v(FOO_), v(x))

// 1
ML99_detectIdent(v(FOO_), v(y))

// 0
ML99_detectIdent(v(FOO_), v(z))

// 1
ML99_detectIdent(v(ML99_UNDERSCORE_DETECTOR), v(_))
ML99_identEq(prefix, x, y)

Compares two identifiers x and y for equality.

This macro is a shortcut to ML99_detectIdent(ML99_cat3(prefix, x, v(_)), y).

Predefined detectors

  • ML99_C_KEYWORD_DETECTOR detects all the C11 keywords.

  • ML99_LOWERCASE_DETECTOR detects lowercase letters (abcdefghijklmnopqrstuvwxyz).

  • ML99_UPPERCASE_DETECTOR detects uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ).

  • ML99_DIGIT_DETECTOR detects digits (0123456789).

Examples

#include <metalang99/ident.h>

#define FOO_x_x ()
#define FOO_y_y ()

// 1
ML99_identEq(v(FOO_), v(x), v(x))

// 1
ML99_identEq(v(FOO_), v(y), v(y))

// 0
ML99_identEq(v(FOO_), v(x), v(y))

// 1
ML99_identEq(v(ML99_C_KEYWORD_DETECTOR), v(while), v(while))
ML99_identEq(v(ML99_LOWERCASE_DETECTOR), v(x), v(x))
ML99_identEq(v(ML99_UPPERCASE_DETECTOR), v(X), v(X))
ML99_identEq(v(ML99_DIGIT_DETECTOR), v(5), v(5))
ML99_charEq(x, y)

Compares two characters x and y for equality.

x and y can be any identifiers, though this function evaluates to true only for characters.

Examples

#include <metalang99/ident.h>

// 1
ML99_charEq(v(t), v(t))

// 0
ML99_charEq(v(9), v(A))

// 0
ML99_charEq(v(9), v(abcd))
ML99_isLowercase(x)

Tells whether the identifier x is a lowercase letter.

ML99_isUppercase(x)

Tells whether the identifier x is an uppercase letter.

ML99_isDigit(x)

Tells whether the identifier x is a digit.

ML99_isChar(x)

Tells whether the identifier x is a character.

ML99_charLit(x)

Converts the Metalang99 character x to a C character literal.

Examples

#include <metalang/ident.h>

// 't'
ML99_charLit(v(t))

// '9'
ML99_charLit(v(9))

// '_'
ML99_charLit(v(_))

Note

The inverse of this function is impossible, i.e., you cannot get q from 'q'.

ML99_LOWERCASE_CHARS(...)

Expands to all comma-separated lowercase letters.

This macro consumes all arguments.

Examples

#include <metalang99/ident.h>
#include <metalang99/variadics.h>

#define F_IMPL(x) v([x])
#define F_ARITY   1

// [a] [b] [c] ... [x] [y] [z]
ML99_variadicsForEach(v(F), v(ML99_LOWERCASE_CHARS()))
ML99_UPPERCASE_CHARS(...)

The same as ML99_LOWERCASE_CHARS but for uppercase characters.

ML99_DIGITS(...)

The same as ML99_LOWERCASE_CHARS but for digits.

ML99_DETECT_IDENT(prefix, ident)
ML99_IDENT_EQ(prefix, x, y)
ML99_CHAR_EQ(x, y)
ML99_IS_LOWERCASE(x)
ML99_IS_UPPERCASE(x)
ML99_IS_DIGIT(x)
ML99_IS_CHAR(x)
ML99_CHAR_LIT(x)