From: Pierre Habouzit Date: Mon, 11 Dec 2006 09:05:23 +0000 (+0100) Subject: rc parser progress over the week-end. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=e00a897e094ccd0c1ecf8567240d16695dcdb7e5;p=apps%2Fmadmutt.git rc parser progress over the week-end. Signed-off-by: Pierre Habouzit --- diff --git a/init.c b/init.c index c86f23e..8f6070c 100644 --- a/init.c +++ b/init.c @@ -2521,7 +2521,8 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) #if 0 { - void *parser = ParseAlloc(malloc); + void *parser = rcparseAlloc(malloc); + struct rcstate state; segment s1 = {" ", 1}; segment s2 = {"toto", 4 }; segment s3 = {"titi", 4 }; @@ -2529,18 +2530,20 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) mutt_endwin(NULL); - ParseTrace(stderr, "> "); - Parse(parser, RCTK_ALT_ORDER, s1); - Parse(parser, RCTK_SPACE, s1); - Parse(parser, RCTK_ATOM, s2); - Parse(parser, RCTK_SPACE, s1); - Parse(parser, RCTK_DQUOTE, s4); - Parse(parser, RCTK_ATOM, s3); - Parse(parser, RCTK_SPACE, s1); - Parse(parser, RCTK_ATOM, s3); - Parse(parser, RCTK_DQUOTE, s4); - Parse(parser, RCTK_NL, s1); - Parse(parser, 0, s1); + p_clear(&state, 1); + + rcparseTrace(stderr, "> "); + rcparse(parser, RCTK_ALTERNATIVE_ORDER, s1, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_ATOM, s2, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_DQUOTE, s4, &state); + rcparse(parser, RCTK_ATOM, s3, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_ATOM, s3, &state); + rcparse(parser, RCTK_DQUOTE, s4, &state); + rcparse(parser, RCTK_NL, s1, &state); + rcparse(parser, 0, s1, &state); exit(0); } diff --git a/parse.h b/parse.h index 214fb60..f7e0f59 100644 --- a/parse.h +++ b/parse.h @@ -7,15 +7,19 @@ typedef struct segment { } segment; #ifdef NDEBUG -# define ParseTrace(a, b) +# define rcparseTrace(a, b) #else -void ParseTrace(FILE *, char *); +void rcparseTrace(FILE *, char *); #endif -const char *ParseTokenName(int); -void *ParseAlloc(void *(*)(size_t)); -void ParseFree(void*, void (*)(void*)); +const char *rcparseTokenName(int); +void *rcparseAlloc(void *(*)(size_t)); +void rcparseFree(void*, void (*)(void*)); -void Parse(void *, int, segment); +struct rcstate { + int linenum; +}; + +void rcparse(void *, int, segment, struct rcstate *state); #endif diff --git a/rcparser.y b/rcparser.y index b63ab9a..4f5c572 100644 --- a/rcparser.y +++ b/rcparser.y @@ -37,7 +37,7 @@ assert (len > 0); switch (*s) { - case 'c': case 'C': + case 'c': case 'Z': if (len < 2) break; buffer_addch(buf, to_control(s[1])); @@ -82,76 +82,95 @@ } } +%name rcparse %token_prefix RCTK_ %token_type { segment } %start_symbol rc +%extra_argument { struct rcstate *state } /****************************************************************************/ /* Often used */ /****************************************************************************/ -spaces ::= SPACE . -spaces ::= spaces SPACE . +escnl ::= BSLASH NL . { state->linenum++; } -non_nl ::= ATOM|SPACE|BANG|BQUOTE|BSLASH|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|PIPE|QUOTE|RBRACE|TILDE . +sp ::= SPACE . +sp ::= sp SPACE . +sp ::= sp escnl SPACE . + +non_nl ::= ATOM|SPACE|BQUOTE|BSLASH|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|QUOTE|RBRACE . non_nl_star ::= . non_nl_star ::= non_nl_star non_nl . -to_eol ::= NL . -to_eol ::= SHARP non_nl_star NL . -to_eol ::= spaces SHARP non_nl_star NL . - +to_eol_aux ::= NL . { state->linenum++; } +to_eol_aux ::= SHARP non_nl_star NL . { state->linenum++; } +to_eol ::= to_eol_aux . +to_eol ::= sp to_eol_aux . /****************************************************************************/ /* Our macro tokens */ /****************************************************************************/ +/* '-quoted tokens */ %type sqtok { buffer_t* } -sqtok(C) ::= . { C = buffer_new(); } -sqtok(C) ::= sqtok(A) BSLASH BSLASH|QUOTE(B) . { buffer_addch(C = A, *B.s); } -sqtok(C) ::= sqtok(A) BSLASH ATOM|SPACE|BANG|BQUOTE|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|PIPE|RBRACE|TILDE(B) . { - buffer_addch(C = A, '\\'); - buffer_add(C, B.s, B.len); +%destructor sqtok { buffer_delete(&$$); } +sqtok(Z) ::= . { Z = buffer_new(); } +sqtok(Z) ::= sqtok(A) escnl . { Z = A; } +sqtok(Z) ::= sqtok(A) BSLASH BSLASH|QUOTE(B) . { buffer_addch(Z = A, *B.s); } +sqtok(Z) ::= sqtok(A) BSLASH ATOM|SPACE|BQUOTE|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|RBRACE(B) . { + buffer_addch(Z = A, '\\'); + buffer_add(Z, B.s, B.len); } -sqtok(C) ::= sqtok(A) ATOM|SPACE|BANG|BQUOTE|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|PIPE|RBRACE|TILDE(B) . { - buffer_add(C = A, B.s, B.len); +sqtok(Z) ::= sqtok(A) ATOM|SPACE|BQUOTE|SHARP|DOLLAR|DQUOTE|EQUAL|LBRACE|RBRACE(B) . { + buffer_add(Z = A, B.s, B.len); } +/* "-quoted tokens */ %type dqtok { buffer_t* } -dqtok(C) ::= . { C = buffer_new(); } -dqtok(C) ::= dqtok(A) BSLASH non_nl(T) . { C = buffer_escape(A, T.s, T.len); } -dqtok(C) ::= dqtok(A) ATOM|SPACE|BANG|SHARP|EQUAL|LBRACE|PIPE|RBRACE|TILDE(T) . { - buffer_add(C = A, T.s, T.len); +%destructor dqtok { buffer_delete(&$$); } +dqtok(Z) ::= . { Z = buffer_new(); } +dqtok(Z) ::= dqtok(A) escnl . { Z = A; } +dqtok(Z) ::= dqtok(A) BSLASH non_nl(B) . { Z = buffer_escape(A, B.s, B.len); } +dqtok(Z) ::= dqtok(A) ATOM|SPACE|SHARP|EQUAL|LBRACE|RBRACE(B) . { + buffer_add(Z = A, B.s, B.len); } - -%type tok { buffer_t* } -tok(R) ::= ATOM|BANG|EQUAL|PIPE|TILDE(T) . { - R = buffer_new(); - buffer_add(R, T.s, T.len); +dqtok(Z) ::= dqtok(A) DOLLAR ATOM(B) . { + // FIXME + B = B; + Z = A; +} +dqtok(Z) ::= dqtok(A) DOLLAR LBRACE ATOM(B) RBRACE . { + // FIXME + B = B; + Z = A; } -tok(R) ::= BSLASH non_nl(T) . { R = buffer_new(); buffer_add(R, T.s, T.len); } -tok(R) ::= QUOTE sqtok(T) QUOTE . { R = T; } -tok(R) ::= DQUOTE dqtok(T) DQUOTE . { R = T; } -%type token_acc { buffer_t* } -token_acc(A) ::= tok(T) . { A = T; } -token_acc(C) ::= token_acc(A) tok(B) . { C = buffer_merge(A, &B); } +/* unquoted tokens */ +%type uqtok { buffer_t* } +%destructor uqtok { buffer_delete(&$$); } +uqtok(Z) ::= ATOM|EQUAL|LBRACE|RBRACE(A) . { buffer_add(Z = buffer_new(), A.s, A.len); } +uqtok(Z) ::= BSLASH non_nl(A) . { buffer_add(Z = buffer_new(), A.s, A.len); } +uqtok(Z) ::= QUOTE sqtok(A) QUOTE . { Z = A; } +uqtok(Z) ::= DQUOTE dqtok(A) DQUOTE . { Z = A; } +/* token accumulator */ %type token { buffer_t* } -token(R) ::= spaces token_acc(T) . { R = T; } - +%destructor token { buffer_delete(&$$); } +token(Z) ::= uqtok(A) . { Z = A; } +token(Z) ::= token(A) escnl . { Z = A; } +token(Z) ::= token(A) uqtok(B) . { Z = buffer_merge(A, &B); } /****************************************************************************/ /* list of tokens */ /****************************************************************************/ %type simple_list { string_list_t * } -simple_list ::= . -simple_list(L) ::= simple_list(A) token(B) . { - string_list_t **last = string_list_last(&A); - *last = string_item_new(); - (*last)->data = buffer_unwrap(&B); - L = A; +%destructor simple_list { string_list_wipe(&$$); } +simple_list ::= . +simple_list(L) ::= simple_list(A) sp token(B) . { + L = string_item_new(); + L->data = buffer_unwrap(&B); + L->next = A; } @@ -163,9 +182,17 @@ rc ::= rclines . rclines ::= . rclines ::= rclines rcline . -rcline ::= to_eol . -rcline ::= ALT_ORDER simple_list(L) to_eol . { - string_list_append(&AlternativeOrderList, L); +rcline ::= ALTERNATIVE_ORDER simple_list(L) to_eol . { + string_list_append(&AlternativeOrderList, string_list_rev(L)); +} +rcline ::= AUTO_VIEW simple_list(L) to_eol . { + string_list_append(&AutoViewList, string_list_rev(L)); +} +rcline ::= HDR_ORDER simple_list(L) to_eol . { + string_list_append(&HeaderOrderList, string_list_rev(L)); +} +rcline ::= MIME_LOOKUP simple_list(L) to_eol . { + string_list_append(&MimeLookupList, string_list_rev(L)); }