aboutsummaryrefslogtreecommitdiff
path: root/src/lexer.h
blob: efd03df8671931f08a909354d67ed8b04c7e76c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef ORYX_LEXER_H
#define ORYX_LEXER_H

#include <stddef.h>
#include <stdint.h>

enum {
	LEXIDENT,

	LEXAMP = '&',
	LEXCOLON = ':',
	LEXEQ = '=',
	LEXLANGL = '<',
	LEXLBRACE = '{',
	LEXLPAR = '(',
	LEXMINUS = '-',
	LEXPIPE = '|',
	LEXPLUS = '+',
	LEXRANGL = '>',
	LEXRBRACE = '}',
	LEXRPAR = ')',
	LEXSEMI = ';',
	LEXSLASH = '/',
	LEXSTAR = '*',
	LEXTILDE = '~',

	/* We keep these exactly 2 away from each other, because ‘<’ and ‘>’ are 2
	   away from each other in ASCII.  This gives us a simple mapping from some
	   token T to the doubled equivalent by doing T += 193. */
	LEXLANGL_DBL = UINT8_MAX - 2, /* << */
	LEXRANGL_DBL = UINT8_MAX - 0, /* >> */
};

typedef uint8_t lexeme_kind;

struct lexeme {
	lexeme_kind kind;
	const char *p;
	size_t len;
};

struct lexeme *lexstring(const unsigned char *, size_t, size_t *);

#endif /* !ORYX_LEXER_H */