diff -r 385b9a10d096 -r 115067dfba55 src/lib/lexer.h --- a/src/lib/lexer.h Tue Oct 07 18:38:03 2008 +0300 +++ b/src/lib/lexer.h Tue Oct 07 20:31:35 2008 +0300 @@ -11,27 +11,46 @@ */ /* + * Transition flags + */ +enum lex_transition_flags { + LEX_TRANS_DEFAULT = 0x01, + LEX_TRANS_FINAL = 0x02, +}; + +/* * A transition from one state to another. */ struct lex_transition { // applies to chars [left, right] char left, right; + // flags from lex_transition_flags + char flags; + // next state to enter int next_state; }; /* + * State flags + */ +enum lex_state_flags { + LEX_STATE_END = 0x01; +}; + +/* * A state */ struct lex_state { // the state name (for debugging) const char *name; + // flags from lex_state_flags + char flags; + // list of transitions for this state, terminated by a transition with next_state=0 struct lex_transition *trans_list; - - }; /* @@ -54,43 +73,46 @@ * * Return zero to have lexing continue, nonzero to stop lexing. */ - int (*lex_token_fn) (int this_token, char *token_data, int next_token, int prev_token, void *arg); + int (*token_fn) (int this_token, char *token_data, int next_token, int prev_token, void *arg); /* * Called on every char handled by the lexer. `this_token` is the state of the token that the char belongs to. * * Return zero to have lexing continue, nonzero to stop lexing. */ - int (*lex_char_fn) (int this_token, char token_char, void *arg); + int (*char_fn) (int this_token, char token_char, void *arg); /* * Called when the end of input has been reached, `last_token` is the state that we terminated in. * * Return zero to indiciate that the input was valid, nonzero to indicate an error. */ - int (*lex_end_fn) (int last_token, void *arg); + int (*end_fn) (int last_token, void *arg); }; /* * Helper macros for building the state_list */ -#define LEX_STATE(enum_val) { #enum_val, { +#define LEX_STATE(enum_val) { #enum_val, 0, +#define LEX_STATE_END(enum_val) { #enum_val, LEX_STATE_END, - #define LEX_CHAR(c, to) { c, c, to }, - #define LEX_RANGE(l, r, to) { l, r, to }, + #define LEX_CHAR(c, to) { c, c, 0, to }, + #define LEX_RANGE(l, r, to) { l, r, 0, to }, #define LEX_ALPHA(to) LEX_RANGE('a', 'z', to), LEX_RANGE('A', 'Z', to) #define LEX_NUMBER(to) LEX_RANGE('0', '9', to) #define LEX_ALNUM(to) LEX_ALPHA(to), LEX_NUMBER(to), LEX_CHAR('-', to), LEX_CHAR('_', to) #define LEX_WHITESPACE(to) LEX_CHAR(' ', to), LEX_CHAR('\n', to), LEX_CHAR('\t', to) -#define LEX_STATE_END {0, 0, 0} \ - } } + #define LEX_DEFAULT(to) { 0, 0, LEX_TRANS_DEFAULT, to } \ + } + #define LEX_END { 0, 0, 0, 0 } \ + } /* * Lex it! * * Return zero to indiciate that the input was valid, nonzero otherwise. */ -int lexer (struct lex *lex, const char *input, void *arg); +int lexer (const struct lex *lex, const char *input, void *arg); #endif /* LIB_LEXER_H */