diff options
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -29,8 +29,6 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d { if(check_and_move_if_on_word("machine",sizeof("machine")-1,src,1)) return get_token(src->src+src->where_in_src-sizeof("machine")+1,sizeof("machine")-1,KW_MACHINE,src->current_row,src->current_column); - if(check_and_move_if_on_word("state",sizeof("state")-1,src,1)) - return get_token(src->src+src->where_in_src-sizeof("state")+1,sizeof("state")-1,KW_STATE,src->current_row,src->current_column); if(check_and_move_if_on_word("from",sizeof("from")-1,src,1)) return get_token(src->src+src->where_in_src-sizeof("from")+1,sizeof("from")-1,KW_FROM,src->current_row,src->current_column); if(check_and_move_if_on_word("to",sizeof("to")-1,src,1)) @@ -39,6 +37,8 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d return get_token(src->src+src->where_in_src-sizeof("on")+1,sizeof("on")-1,KW_ON,src->current_row,src->current_column); if(check_and_move_if_on_word("[",sizeof("[")-1,src,0)) return get_token(src->src+src->where_in_src-sizeof("[")+1,sizeof("[")-1,KW_OPEN_SQUARE,src->current_row,src->current_column); + if(check_and_move_if_on_word(",",sizeof(",")-1,src,0)) + return get_token(src->src+src->where_in_src-sizeof(",")+1,sizeof(",")-1,KW_COMMA,src->current_row,src->current_column); if(check_and_move_if_on_word("]",sizeof("]")-1,src,0)) return get_token(src->src+src->where_in_src-sizeof("]")+1,sizeof("]")-1,KW_CLOSE_SQUARE,src->current_row,src->current_column); if(check_and_move_if_on_word(";",sizeof(";")-1,src,0)) @@ -47,6 +47,16 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d return get_token(src->src+src->where_in_src-sizeof("|")+1,sizeof("|")-1,KW_PIPE,src->current_row,src->current_column); if(check_and_move_if_on_word("starting",sizeof("starting")-1,src,1)) return get_token(src->src+src->where_in_src-sizeof("starting")+1,sizeof("starting")-1,KW_STARTING,src->current_row,src->current_column); + if(check_and_move_if_on_word("states",sizeof("states")-1,src,1)) + return get_token(src->src+src->where_in_src-sizeof("states")+1,sizeof("states")-1,KW_STATES,src->current_row,src->current_column); + if(check_and_move_if_on_word("events",sizeof("events")-1,src,1)) + return get_token(src->src+src->where_in_src-sizeof("events")+1,sizeof("events")-1,KW_EVENTS,src->current_row,src->current_column); + if(check_and_move_if_on_word("execute",sizeof("execute")-1,src,1)) + return get_token(src->src+src->where_in_src-sizeof("execute")+1,sizeof("execute")-1,KW_EXECUTE,src->current_row,src->current_column); + if(check_and_move_if_on_word("event",sizeof("event")-1,src,1)) + return get_token(src->src+src->where_in_src-sizeof("event")+1,sizeof("event")-1,KW_EVENT,src->current_row,src->current_column); + if(check_and_move_if_on_word("transitions",sizeof("transitions")-1,src,1)) + return get_token(src->src+src->where_in_src-sizeof("transitions")+1,sizeof("transitions")-1,KW_TRANSITIONS,src->current_row,src->current_column); @@ -122,6 +132,7 @@ static char check_and_move_if_on_word(char *word,size_t word_size,struct Source else if( (needs_space_after && isspace(src->src[src->where_in_src+i])) || !needs_space_after ) { src->where_in_src+=i; + src->current_column+=i; return 1; } else @@ -132,6 +143,18 @@ static char check_and_move_if_on_word(char *word,size_t word_size,struct Source void skip_white_space(struct Source *src) { while(src->where_in_src<src->src_size && isspace(src->src[src->where_in_src])) + { + if(src->src[src->where_in_src]=='\n') + { + ++src->current_row; + src->current_column=0; + } ++src->where_in_src; + } +} + +void push_token_into_map(struct token *token,struct Map *map,void *thing) +{ + Map_Push(map,token->data,token->size,thing); } #endif |