diff options
Diffstat (limited to 'libcmd/cmd_parse.ragel')
-rw-r--r-- | libcmd/cmd_parse.ragel | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/libcmd/cmd_parse.ragel b/libcmd/cmd_parse.ragel index dd5ff13..482ad8d 100644 --- a/libcmd/cmd_parse.ragel +++ b/libcmd/cmd_parse.ragel @@ -5,8 +5,8 @@ #define TADD(T,S,E,SZ) {cmd_tok_t *t=cmd_tok_create(S,E,SZ,T);cmd_tok_add(tl,t);tl=tl->next;} //#define TADD(T,S,E) -//#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n"); -#define PR_TK_DBG(S) ; +#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n"); +//#define PR_TK_DBG(S) ; char *new_string( const char *start, const char *end ) { @@ -30,40 +30,51 @@ int print_token( char *s, char *e, int tok) %%{ machine cmd; - - hex = '0x' [a-fA-F0-9]+; - decimal = [0-9]+; - binary = '0b' [0-1]+; - string = ('"' ([a-zA-Z0-9' '])+ '"'); - seperate = ';'; - word = [a-zA-Z] ([a-zA-Z0-9])*; - - sp = (' ' | '\t' | '\n')*; + hex = '0x' [a-fA-F0-9]+; + decimal = [0-9]+; + binary = '0b' [0-1]+; + float = [0-9]* '.' [0-9]+; + quoted_string = '"' + ( + ' ' + |(any-['\\' '"' ' '])+ + |'\\\\' + |'\\\"' + |'\\ ' + )* + '"'; + quote = '"' (any-'"')* '"'; + #seperate = ';'; + word = [a-zA-Z] ([a-zA-Z0-9])*; + sp = ([' ','\t','\n']); main := |* - hex {PR_TK_DBG("hex = ");TADD(CMDT_HEX, ts,te,te-ts);}; - sp {PR_TK_DBG("sp = ");}; - string {PR_TK_DBG("str = ");TADD(CMDT_STR, ts,te,te-ts);}; - decimal {PR_TK_DBG("dec = ");TADD(CMDT_INT, ts,te,te-ts);}; - binary {PR_TK_DBG("bin = ");TADD(CMDT_BIN, ts,te,te-ts);}; - seperate {PR_TK_DBG("sep = ");TADD(CMDT_SP, ts,te,te-ts);}; - word {PR_TK_DBG("wrd = ");TADD(CMDT_WORD,ts,te,te-ts);}; + hex {PR_TK_DBG("hex = ");TADD(CMDT_HEX, ts,te,te-ts);}; + decimal {PR_TK_DBG("dec = ");TADD(CMDT_INT, ts,te,te-ts);}; + binary {PR_TK_DBG("bin = ");TADD(CMDT_BIN, ts,te,te-ts);}; + quoted_string {PR_TK_DBG("qstr = ");TADD(CMDT_QSTR, ts,te,te-ts);}; + word {PR_TK_DBG("word = ");TADD(CMDT_WORD, ts,te,te-ts);}; + sp {PR_TK_DBG("sp = ");TADD(CMDT_SP, ts,te,te-ts);}; + float {PR_TK_DBG("float= ");TADD(CMDT_FLOAT, ts,te,te-ts);}; *|; - #main := lang; - write data; }%% -int parse_cmd( cmd_tok_t *tl, const char *str ) +int parse_cmd( cmd_tok_t *tl, const char *str, size_t str_size ) { static uint8_t cs; const int stacksize = 10; - int res=0, *stack=NULL, act=0; + int res=0, *stack=NULL, act=0,top=0; stack = malloc( sizeof(stack)*stacksize ); - char *p=(char *)str, *pe = (char *)str + strlen( str ), *eof=NULL; + char *p=(char *)str, *pe = (char *)str + str_size, *eof=pe; char *ts, *te = 0; + /*save for cmd_begin state*/ + //char *ts_cb=0, *te_cb=0; + + printf("PE:%s %02x\n",pe,(unsigned char)*pe); + /* variables used in state machine */ @@ -73,7 +84,7 @@ int parse_cmd( cmd_tok_t *tl, const char *str ) if ( cs == cmd_error ) { - printf("CLIPARSE ERR state [%d] pos[%d]:[%s]\n", res, p-str, p); + printf("CLIPARSE ERR state [%d] pos[%ld]:[%s]\n", res, p-str, p); res = -1; } |