22 #ifndef LELY_UTIL_LEX_H_
23 #define LELY_UTIL_LEX_H_
31 #ifndef LELY_UTIL_LEX_INLINE
32 #define LELY_UTIL_LEX_INLINE static inline
43 LELY_UTIL_LEX_INLINE
int isbreak(
int c);
46 LELY_UTIL_LEX_INLINE
int isodigit(
int c);
49 LELY_UTIL_LEX_INLINE
int ctoo(
int c);
56 LELY_UTIL_LEX_INLINE
int ctox(
int c);
72 size_t lex_char(
int c,
const char *begin,
const char *end,
struct floc *at);
90 size_t lex_ctype(
int (*ctype)(
int),
const char *begin,
const char *end,
106 size_t lex_break(
const char *begin,
const char *end,
struct floc *at);
127 size_t lex_utf8(
const char *begin,
const char *end,
struct floc *at,
148 size_t lex_c99_id(
const char *begin,
const char *end,
struct floc *at,
char *s,
172 size_t lex_c99_esc(
const char *begin,
const char *end,
struct floc *at,
197 size_t lex_c99_str(
const char *begin,
const char *end,
struct floc *at,
char *s,
217 #define LELY_UTIL_DEFINE_LEX_SIGNED(type, suffix, strtov, pname) \
234 size_t lex_c99_##suffix(const char *begin, \
235 const char *end, struct floc *at, type *pname);
239 #define LELY_UTIL_DEFINE_LEX_UNSIGNED(type, suffix, strtov, pname) \
256 size_t lex_c99_##suffix(const char *begin, \
257 const char *end, struct floc *at, type *pname);
260 LELY_UTIL_DEFINE_LEX_SIGNED(
long,
long, strtol, pl)
261 LELY_UTIL_DEFINE_LEX_UNSIGNED(
unsigned long, ulong, strtoul, pul)
262 LELY_UTIL_DEFINE_LEX_SIGNED(
long long, llong, strtoll, pll)
263 LELY_UTIL_DEFINE_LEX_UNSIGNED(
unsigned long long, ullong, strtoull, pul)
264 LELY_UTIL_DEFINE_LEX_SIGNED(
float, flt, strtof, pf)
265 LELY_UTIL_DEFINE_LEX_SIGNED(
double, dbl, strtod, pd)
266 LELY_UTIL_DEFINE_LEX_SIGNED(
long double, ldbl, strtold, pld)
268 #undef LELY_UTIL_DEFINE_LEX_UNSIGNED
269 #undef LELY_UTIL_DEFINE_LEX_SIGNED
272 #define LELY_UTIL_DEFINE_LEX_SIGNED(type, suffix, pname) \
288 size_t lex_c99_##suffix(const char *begin, \
289 const char *end, struct floc *at, type *pname);
293 #define LELY_UTIL_DEFINE_LEX_UNSIGNED(type, suffix, pname) \
309 size_t lex_c99_##suffix(const char *begin, \
310 const char *end, struct floc *at, type *pname);
313 LELY_UTIL_DEFINE_LEX_SIGNED(int_least8_t, i8, pi8)
314 LELY_UTIL_DEFINE_LEX_SIGNED(int_least16_t, i16, pi16)
315 LELY_UTIL_DEFINE_LEX_SIGNED(int_least32_t, i32, pi32)
316 LELY_UTIL_DEFINE_LEX_SIGNED(int_least64_t, i64, pi64)
317 LELY_UTIL_DEFINE_LEX_UNSIGNED(uint_least8_t, u8, pu8)
318 LELY_UTIL_DEFINE_LEX_UNSIGNED(uint_least16_t, u16, pu16)
319 LELY_UTIL_DEFINE_LEX_UNSIGNED(uint_least32_t, u32, pu32)
320 LELY_UTIL_DEFINE_LEX_UNSIGNED(uint_least64_t, u64, pu64)
322 #undef LELY_UTIL_DEFINE_LEX_UNSIGNED
323 #undef LELY_UTIL_DEFINE_LEX_SIGNED
342 size_t lex_line_comment(
const char *delim,
const char *begin,
const char *end,
365 size_t lex_hex(
const char *begin,
const char *end,
struct floc *at,
void *ptr,
391 size_t lex_base64(
const char *begin,
const char *end,
struct floc *at,
392 void *ptr,
size_t *pn);
394 LELY_UTIL_LEX_INLINE
int
397 return c ==
'\n' || c ==
'\r';
400 LELY_UTIL_LEX_INLINE
int
403 return c >=
'0' && c <=
'7';
406 LELY_UTIL_LEX_INLINE
int
412 LELY_UTIL_LEX_INLINE
int
417 #if __STDC_ISO_10646__ && !__STDC_MB_MIGHT_NEQ_WC__
418 return 10 + (isupper(c) ? c -
'A' : c -
'a');
422 case 'a':
return 0xa;
424 case 'b':
return 0xb;
426 case 'c':
return 0xc;
428 case 'd':
return 0xd;
430 case 'e':
return 0xe;
432 case 'f':
return 0xf;
This is the public header file of the utilities library.
int isodigit(int c)
Returns 1 if c is an octal digit, and 0 otherwise.
size_t lex_char(int c, const char *begin, const char *end, struct floc *at)
Lexes the specified character from a memory buffer.
size_t lex_ctype(int(*ctype)(int), const char *begin, const char *end, struct floc *at)
Greedily lexes a sequence of characters of the specified class from a memory buffer.
size_t lex_utf8(const char *begin, const char *end, struct floc *at, char32_t *pc32)
Lexes a UTF-8 encoded Unicode character from a memory buffer.
size_t lex_c99_id(const char *begin, const char *end, struct floc *at, char *s, size_t *pn)
Lexes a C99 identifier from a memory buffer.
size_t lex_line_comment(const char *delim, const char *begin, const char *end, struct floc *at)
Lexes a single line-comment (excluding the line break) starting with the specified delimiter from a m...
size_t lex_c99_esc(const char *begin, const char *end, struct floc *at, char32_t *pc32)
Lexes a C99 character escape sequence from a memory buffer if the buffer begins with '\',...
size_t lex_hex(const char *begin, const char *end, struct floc *at, void *ptr, size_t *pn)
Lexes and decodes the hexadecimal representation of binary data from a memory buffer.
size_t lex_base64(const char *begin, const char *end, struct floc *at, void *ptr, size_t *pn)
Lexes and decodes the Base64 representation of binary data from a memory buffer.
int isbreak(int c)
Returns 1 if c is a line break character, and 0 otherwise.
int ctoo(int c)
Returns the octal digit corresponding to the character c.
size_t lex_c99_str(const char *begin, const char *end, struct floc *at, char *s, size_t *pn)
Lexes a UTF-8 encoded Unicode string from a memory buffer.
size_t lex_break(const char *begin, const char *end, struct floc *at)
Lexes a single line break from a memory buffer.
int ctox(int c)
Returns the hexadecimal digit corresponding to the character c.
size_t lex_c99_pp_num(const char *begin, const char *end, struct floc *at)
Lexes a C99 preprocessing number from a memory buffer.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
A location in a text file.
This header file is part of the C11 and POSIX compatibility library; it includes <uchar....