Metalang99 1.13.3
Full-blown preprocessor metaprogramming
Loading...
Searching...
No Matches
ident.h File Reference

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

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ML99_detectIdent(prefix, ident)   ML99_call(ML99_detectIdent, prefix, ident)
 Tells whether ident belongs to a set of identifiers defined by prefix.
 
#define ML99_identEq(prefix, x, y)   ML99_call(ML99_identEq, prefix, x, y)
 Compares two identifiers x and y for equality.
 
#define ML99_charEq(x, y)   ML99_call(ML99_charEq, x, y)
 Compares two characters x and y for equality.
 
#define ML99_isLowercase(x)   ML99_call(ML99_isLowercase, x)
 Tells whether the identifier x is a lowercase letter.
 
#define ML99_isUppercase(x)   ML99_call(ML99_isUppercase, x)
 Tells whether the identifier x is an uppercase letter.
 
#define ML99_isDigit(x)   ML99_call(ML99_isDigit, x)
 Tells whether the identifier x is a digit.
 
#define ML99_isChar(x)   ML99_call(ML99_isChar, x)
 Tells whether the identifier x is a character.
 
#define ML99_charLit(x)   ML99_call(ML99_charLit, x)
 Converts the Metalang99 character x to a C character literal.
 
#define ML99_LOWERCASE_CHARS(...)    a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
 Expands to all comma-separated lowercase letters.
 
#define ML99_UPPERCASE_CHARS(...)    A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
 The same as ML99_LOWERCASE_CHARS but for uppercase characters.
 
#define ML99_DIGITS(...)   0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 The same as ML99_LOWERCASE_CHARS but for digits.
 
#define ML99_DETECT_IDENT(prefix, ident)   ML99_PRIV_IS_TUPLE_FAST(ML99_PRIV_CAT(prefix, ident))
 
#define ML99_IDENT_EQ(prefix, x, y)   ML99_DETECT_IDENT(ML99_PRIV_CAT3(prefix, x, _), y)
 
#define ML99_CHAR_EQ(x, y)
 
#define ML99_IS_LOWERCASE(x)   ML99_IDENT_EQ(ML99_LOWERCASE_DETECTOR, x, x)
 
#define ML99_IS_UPPERCASE(x)   ML99_IDENT_EQ(ML99_UPPERCASE_DETECTOR, x, x)
 
#define ML99_IS_DIGIT(x)   ML99_IDENT_EQ(ML99_DIGIT_DETECTOR, x, x)
 
#define ML99_IS_CHAR(x)
 
#define ML99_CHAR_LIT(x)   ML99_PRIV_CAT(ML99_PRIV_CHAR_LIT_, x)
 

Detailed Description

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.

Macro Definition Documentation

◆ ML99_CHAR_EQ

#define ML99_CHAR_EQ (   x,
 
)
Value:
ML99_PRIV_IF( \
ML99_DETECT_IDENT(ML99_UNDERSCORE_DETECTOR, x), \
ML99_DETECT_IDENT(ML99_UNDERSCORE_DETECTOR, y), \
ML99_PRIV_OR3( \
ML99_IDENT_EQ(ML99_LOWERCASE_DETECTOR, x, y), \
ML99_IDENT_EQ(ML99_UPPERCASE_DETECTOR, x, y), \
ML99_IDENT_EQ(ML99_DIGIT_DETECTOR, x, y)))

◆ ML99_charEq

#define ML99_charEq (   x,
 
)    ML99_call(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

// 1
ML99_charEq(v(t), v(t))
// 0
ML99_charEq(v(9), v(A))
// 0
ML99_charEq(v(9), v(abcd))
Identifiers: [a-zA-Z0-9_]+.
#define ML99_charEq(x, y)
Compares two characters x and y for equality.
Definition ident.h:118
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145

◆ ML99_charLit

#define ML99_charLit (   x)    ML99_call(ML99_charLit, x)

Converts the Metalang99 character x to a C character literal.

Examples

#include <metalang/ident.h>
// 't'
// '9'
// '_'
#define ML99_charLit(x)
Converts the Metalang99 character x to a C character literal.
Definition ident.h:160
Note
The inverse of this function is impossible, i.e., you cannot get q from ‘'q’`.

◆ ML99_detectIdent

#define ML99_detectIdent (   prefix,
  ident 
)    ML99_call(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

#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(_))
#define ML99_detectIdent(prefix, ident)
Tells whether ident belongs to a set of identifiers defined by prefix.
Definition ident.h:57

◆ ML99_identEq

#define ML99_identEq (   prefix,
  x,
 
)    ML99_call(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

#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))
#define ML99_identEq(prefix, x, y)
Compares two identifiers x and y for equality.
Definition ident.h:96

◆ ML99_IS_CHAR

#define ML99_IS_CHAR (   x)
Value:
ML99_PRIV_OR4( \
ML99_IS_LOWERCASE(x), \
ML99_IS_UPPERCASE(x), \
ML99_IS_DIGIT(x), \
ML99_DETECT_IDENT(ML99_UNDERSCORE_DETECTOR, x))

◆ ML99_LOWERCASE_CHARS

#define ML99_LOWERCASE_CHARS (   ...)     a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

Expands to all comma-separated lowercase letters.

This macro consumes all arguments.

Examples

#define F_IMPL(x) v([x])
#define F_ARITY 1
// [a] [b] [c] ... [x] [y] [z]
#define ML99_LOWERCASE_CHARS(...)
Expands to all comma-separated lowercase letters.
Definition ident.h:180
Variadic arguments: x, y, z.
#define ML99_variadicsForEach(f,...)
Applies f to each argument.
Definition variadics.h:103