#if 0
{
- void *parser = ParseAlloc(malloc);
+ void *parser = rcparseAlloc(malloc);
+ struct rcstate state;
segment s1 = {" ", 1};
segment s2 = {"toto", 4 };
segment s3 = {"titi", 4 };
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);
}
assert (len > 0);
switch (*s) {
- case 'c': case 'C':
+ case 'c': case 'Z':
if (len < 2)
break;
buffer_addch(buf, to_control(s[1]));
}
}
+%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;
}
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));
}